File tree Expand file tree Collapse file tree 1 file changed +24
-15
lines changed
packages/tools/shared/src Expand file tree Collapse file tree 1 file changed +24
-15
lines changed Original file line number Diff line number Diff line change 1
- const defineProperty = ( object : any , name : string | number | symbol , value : any ) => {
2
- if ( name in object ) {
3
- return ;
4
- }
5
- Object . defineProperty ( object , name , {
6
- configurable : true ,
7
- enumerable : false ,
8
- value,
9
- writable : true
10
- } ) ;
11
- } ;
12
-
13
1
export interface EsShimProp < I > {
14
2
implementation : I ,
15
3
getPolyfill ( ) : I ,
@@ -18,7 +6,28 @@ export interface EsShimProp<I> {
18
6
19
7
export function makeEsShim < T extends object , I > ( shim : T , implementation : I ) : asserts shim is T & EsShimProp < I > {
20
8
const getPolyfill = ( ) => implementation ;
21
- defineProperty ( shim , 'implementation' , implementation ) ;
22
- defineProperty ( shim , 'getPolyfill' , getPolyfill ) ;
23
- defineProperty ( shim , 'shim' , getPolyfill ) ;
9
+ if ( ! ( 'implementation' in shim ) ) {
10
+ Object . defineProperty ( shim , 'implementation' , {
11
+ configurable : true ,
12
+ enumerable : false ,
13
+ value : implementation ,
14
+ writable : true
15
+ } ) ;
16
+ }
17
+ if ( ! ( 'getPolyfill' in shim ) ) {
18
+ Object . defineProperty ( shim , 'getPolyfill' , {
19
+ configurable : true ,
20
+ enumerable : false ,
21
+ value : getPolyfill ,
22
+ writable : true
23
+ } ) ;
24
+ }
25
+ if ( ! ( 'shim' in shim ) ) {
26
+ Object . defineProperty ( shim , 'shim' , {
27
+ configurable : true ,
28
+ enumerable : false ,
29
+ value : getPolyfill ,
30
+ writable : true
31
+ } ) ;
32
+ }
24
33
}
You can’t perform that action at this time.
0 commit comments