Skip to content

Commit

Permalink
fix: polyfill instancing bug (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
guybedford authored Nov 5, 2021
1 parent 1fc26eb commit 77020fd
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/es-module-shims.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticL
if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
return module;
}
const module = await dynamicImport((shimMode || load.n) ? load.b : load.u, { errUrl: load.u });
const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
// if the top-level load is a shell, run its update function
if (load.s)
(await dynamicImport(load.s)).u$_(module);
Expand Down
3 changes: 3 additions & 0 deletions test/fixtures/instance-case-a.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { common } from "./instance-case-common.js";

window.common_a = common;
3 changes: 3 additions & 0 deletions test/fixtures/instance-case-b.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { common } from "./instance-case-common.js";

window.common_b = common;
1 change: 1 addition & 0 deletions test/fixtures/instance-case-common.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const common = {};
8 changes: 8 additions & 0 deletions test/fixtures/instance-case.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import 'a';

const bPromise = import('b');

export async function check () {
await bPromise;
return window.common_a === window.common_b;
}
6 changes: 6 additions & 0 deletions test/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ suite('Polyfill tests', () => {
test('import maps passthrough polyfill mode', async function () {
await importShim('test');
});

test('Shared instances', async function () {
const { check } = await importShim('./fixtures/instance-case.js');
const result = await check();
assert.equal(result, true);
});
});
4 changes: 3 additions & 1 deletion test/test-csp.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
"test/": "/test/fixtures/",
"global1": "/test/fixtures/es-modules/global1.js",
"/test/fixtures/es-modules/dynamic.js": "/test/fixtures/es-modules/dynamic-url-map.js",
"data": "data:text/javascript,"
"data": "data:text/javascript,",
"a": "/test/fixtures/instance-case-a.js",
"b": "/test/fixtures/instance-case-b.js"
}
}
</script>
Expand Down
4 changes: 3 additions & 1 deletion test/test-polyfill-wasm.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"test": "/test/fixtures/es-modules/es6-file.js",
"test/": "/test/fixtures/",
"global1": "/test/fixtures/es-modules/global1.js",
"/test/fixtures/es-modules/dynamic.js": "/test/fixtures/es-modules/dynamic-url-map.js"
"/test/fixtures/es-modules/dynamic.js": "/test/fixtures/es-modules/dynamic-url-map.js",
"a": "/test/fixtures/instance-case-a.js",
"b": "/test/fixtures/instance-case-b.js"
}
}
</script>
Expand Down
4 changes: 3 additions & 1 deletion test/test-polyfill.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
"test": "/test/fixtures/es-modules/es6-file.js",
"test/": "/test/fixtures/",
"global1": "/test/fixtures/es-modules/global1.js",
"/test/fixtures/es-modules/dynamic.js": "/test/fixtures/es-modules/dynamic-url-map.js"
"/test/fixtures/es-modules/dynamic.js": "/test/fixtures/es-modules/dynamic-url-map.js",
"a": "/test/fixtures/instance-case-a.js",
"b": "/test/fixtures/instance-case-b.js"
}
}
</script>
Expand Down

0 comments on commit 77020fd

Please sign in to comment.