Skip to content

Commit 50494ec

Browse files
Expose static members of public types in ESM2017 build (#3259)
* Expose static members of public types in ESM2017 build * Update api.ts * Update api.ts
1 parent 868a786 commit 50494ec

File tree

1 file changed

+10
-6
lines changed
  • packages/firestore/src/util

1 file changed

+10
-6
lines changed

packages/firestore/src/util/api.ts

Lines changed: 10 additions & 6 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 builtins that cannot be reassigned. */
21+
const RESERVED_READONLY_PROPS = ['length', 'name'];
22+
2023
/**
2124
* Helper function to prevent instantiation through the constructor.
2225
*
@@ -41,12 +44,13 @@ 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-
48-
// Copy any static methods/members
49-
Object.assign(PublicConstructor, cls);
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+
}
5054

5155
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5256
return PublicConstructor as any;

0 commit comments

Comments
 (0)