8000 fix: syntheticDefaultExportPolyfill Check if frozen before attempting… · fuse-box/fuse-box@2c971e7 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Jun 20, 2023. It is now read-only.

Commit 2c971e7

Browse files
troyntnchanged
authored andcommitted
fix: syntheticDefaultExportPolyfill Check if frozen before attempting to defineProperty. (#1235)
* fix: syntheticDefaultExportPolyfill Check if frozen before attempting to defineProperty. * fix: LoaderAPI syntheticDefaultExportPolyfill should match fuse-box-responsive-api/index.js
1 parent 26e7ebe commit 2c971e7

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

modules/fuse-box-responsive-api/index.js

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,27 @@
88
/* @end */
99

1010
/* @if allowSyntheticDefaultImports */
11-
function syntheticDefaultExportPolyfill(input){
12-
return input !== null && ['function', 'object', 'array']
13-
.indexOf(typeof input) > -1 && input.default === undefined ?
14-
Object.isFrozen(input) ? input.default = input : Object.defineProperty(input, "default", {value : input, writable : true, enumerable : false}) : void 0;
11+
// NOTE: Should match syntheticDefaultExportPolyfill in LoaderAPI.ts
12+
function syntheticDefaultExportPolyfill(input) {
13+
if( input === null ||
14+
['function', 'object', 'array'].indexOf(typeof input) === -1 ||
15+
input.hasOwnProperty("default") // use hasOwnProperty to avoid triggering usage warnings from libraries like mobx
16+
) {
17+
return
18+
}
19+
20+
// to get around frozen input
21+
if (Object.isFrozen(input) ) {
22+
input.default = input;
23+
return;
24+
}
25+
26+
// free to define properties
27+
Object.defineProperty(input, "default", {
28+
value: input,
29+
writable: true,
30+
enumerable: false
31+
});
1532
}
1633
/* @end */
1734

@@ -256,7 +273,7 @@
256273
/* @if server */
257274
var path = bMapping.c.s;
258275
/* @end */
259-
276+
260277
/* @if browser */
261278
var path = bMapping.c.b;
262279
/* @end */
@@ -385,4 +402,4 @@
385402

386403
/* @if !isContained */
387404
})();
388-
/* @end */
405+
/* @end */

src/loader/LoaderAPI.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,27 @@ function $trigger(name: string, args: any) {
395395
}
396396
};
397397

398+
// NOTE: Should match syntheticDefaultExportPolyfill in fuse-box-responsive-api/index.js
398399
function syntheticDefaultExportPolyfill(input){
399-
return input !== null && ['function', 'object', 'array']
400-
.indexOf(typeof input) > -1 && input.default === undefined ?
401-
Object.isFrozen(input) ? input.default = input : Object.defineProperty(input, "default", {value : input, writable : true, enumerable : false}) : void 0;
400+
if( input === null ||
401+
['function', 'object', 'array'].indexOf(typeof input) === -1 ||
402+
input.hasOwnProperty("default") // use hasOwnProperty to avoid triggering usage warnings from libraries like mobx
403+
) {
404+
return
405+
}
406+
407+
// to get around frozen input
408+
if (Object.isFrozen(input) ) {
409+
input.default = input;
410+
return;
411+
}
412+
413+
// free to define properties
414+
Object.defineProperty(input, "default", {
415+
value: input,
416+
writable: true,
417+
enumerable: false
418+
});
402419
}
403420

404421
/**

0 commit comments

Comments
 (0)
0