Skip to content

Commit 6f10d65

Browse files
committed
perf(shared): futher improve makeEsShim
1 parent 6ba791b commit 6f10d65

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed
Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,3 @@
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-
131
export interface EsShimProp<I> {
142
implementation: I,
153
getPolyfill(): I,
@@ -18,7 +6,28 @@ export interface EsShimProp<I> {
186

197
export function makeEsShim<T extends object, I>(shim: T, implementation: I): asserts shim is T & EsShimProp<I> {
208
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+
}
2433
}

0 commit comments

Comments
 (0)