Skip to content

Commit

Permalink
Expose static members of public types in ESM2017 build (#3259)
Browse files Browse the repository at this point in the history
* Expose static members of public types in ESM2017 build

* Update api.ts

* Update api.ts
  • Loading branch information
schmidt-sebastian authored Jun 23, 2020
1 parent 868a786 commit 50494ec
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions packages/firestore/src/util/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

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

/** List of JavaScript builtins that cannot be reassigned. */
const RESERVED_READONLY_PROPS = ['length', 'name'];

/**
* Helper function to prevent instantiation through the constructor.
*
Expand All @@ -41,12 +44,13 @@ export function makeConstructorPrivate<T extends Function>(
throw new FirestoreError(Code.INVALID_ARGUMENT, error);
}

// Make sure instanceof checks work and all methods are exposed on the public
// constructor
PublicConstructor.prototype = cls.prototype;

// Copy any static methods/members
Object.assign(PublicConstructor, cls);
// Copy static members and prototype
for (const staticProp of Object.getOwnPropertyNames(cls)) {
if (RESERVED_READONLY_PROPS.indexOf(staticProp) === -1) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(PublicConstructor as any)[staticProp] = (cls as any)[staticProp];
}
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return PublicConstructor as any;
Expand Down

0 comments on commit 50494ec

Please sign in to comment.