Skip to content

Expose static members of public types in ESM2017 build #3259

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 23, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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