File tree 1 file changed +10
-6
lines changed
packages/firestore/src/util
1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change 17
17
18
18
import { Code , FirestoreError } from './error' ;
19
19
20
+ /** List of JavaScript builtins that cannot be reassigned. */
21
+ const RESERVED_READONLY_PROPS = [ 'length' , 'name' ] ;
22
+
20
23
/**
21
24
* Helper function to prevent instantiation through the constructor.
22
25
*
@@ -41,12 +44,13 @@ export function makeConstructorPrivate<T extends Function>(
41
44
throw new FirestoreError ( Code . INVALID_ARGUMENT , error ) ;
42
45
}
43
46
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
+ }
50
54
51
55
// eslint-disable-next-line @typescript-eslint/no-explicit-any
52
56
return PublicConstructor as any ;
You can’t perform that action at this time.
0 commit comments