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 2 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
15 changes: 11 additions & 4 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,11 +44,15 @@ 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 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];
}
}

// Copy any static methods/members
// Copy instance methods/members
Object.assign(PublicConstructor, cls);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it anymore since instance methods/members are copied in prototype.


// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down