Skip to content

Commit 61ccd2f

Browse files
Expose static members of public types in ESM2017 build
1 parent 0ae2f63 commit 61ccd2f

File tree

1 file changed

+11
-4
lines changed
  • packages/firestore/src/util

1 file changed

+11
-4
lines changed

packages/firestore/src/util/api.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
import { Code, FirestoreError } from './error';
1919

20+
/** List of JavaScript built-in members that cannot be reassigned. */
21+
const RESERVED_READONLY_PROPS = ['length', 'name'];
22+
2023
/**
2124
* Helper function to prevent instantiation through the constructor.
2225
*
@@ -41,11 +44,15 @@ export function makeConstructorPrivate<T extends Function>(
4144
throw new FirestoreError(Code.INVALID_ARGUMENT, error);
4245
}
4346

44-
// Make sure instanceof checks work and all methods are exposed on the public
45-
// constructor
46-
PublicConstructor.prototype = cls.prototype;
47+
// Copy static members and prototype
48+
for (const staticProp of Object.getOwnPropertyNames(cls)) {
49+
if (RESERVED_READONLY_PROPS.indexOf(staticProp) === -1) {
50+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
51+
(PublicConstructor as any)[staticProp] = (cls as any)[staticProp];
52+
}
53+
}
4754

48-
// Copy any static methods/members
55+
// Copy instance methods/members
4956
Object.assign(PublicConstructor, cls);
5057

5158
// eslint-disable-next-line @typescript-eslint/no-explicit-any

0 commit comments

Comments
 (0)