es-module-shims 1.5.12 → 1.5.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -42
- package/dist/es-module-shims.js +51 -58
- package/dist/es-module-shims.wasm.js +51 -58
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -29,7 +29,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
29
29
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.
|
|
32
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.13/dist/es-module-shims.js"></script>
|
|
33
33
|
|
|
34
34
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
35
35
|
<script type="importmap">
|
|
@@ -186,43 +186,38 @@ Benchmark summary:
|
|
|
186
186
|
|
|
187
187
|
Works in all browsers with [baseline ES module support](https://caniuse.com/#feat=es6-module).
|
|
188
188
|
|
|
189
|
-
Browser Compatibility **with ES Module Shims
|
|
190
|
-
|
|
191
|
-
| ES Modules Features
|
|
192
|
-
|
|
|
193
|
-
|
|
|
194
|
-
| [Dynamic Import](#dynamic-import)
|
|
195
|
-
| [import.meta.url](#importmetaurl)
|
|
196
|
-
| [
|
|
197
|
-
| [
|
|
198
|
-
| [
|
|
199
|
-
| [
|
|
200
|
-
| [
|
|
201
|
-
|
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
|
212
|
-
|
|
|
213
|
-
|
|
|
214
|
-
| [
|
|
215
|
-
| [
|
|
216
|
-
| [
|
|
217
|
-
| [
|
|
218
|
-
| [
|
|
219
|
-
|
|
|
220
|
-
|
|
221
|
-
| [import.meta.resolve](#resolve) | :x: | :x: | :x: | :x: |
|
|
222
|
-
| [Top-Level Await](#tla) | :heavy_check_mark: 89+ | :heavy_check_mark: 89+ | :x: | :x: |
|
|
223
|
-
|
|
224
|
-
* 1: _Edge executes parallel dependencies in non-deterministic order. ([ChakraCore bug](https://github.com/microsoft/ChakraCore/issues/6261))._
|
|
225
|
-
* ~: _Indicates the exact first version support has not yet been determined (PR's welcome!)._
|
|
189
|
+
Browser Compatibility on baseline ES modules support **with** ES Module Shims:
|
|
190
|
+
|
|
191
|
+
| ES Modules Features | Chrome (61+) | Firefox (60+) | Safari (10.1+) |
|
|
192
|
+
| ----------------------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ |
|
|
193
|
+
| [modulepreload](#modulepreload) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
194
|
+
| [Dynamic Import](#dynamic-import) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
195
|
+
| [import.meta.url](#importmetaurl) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
196
|
+
| [Import Maps](#import-maps) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
197
|
+
| [JSON Modules](#json-modules) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
198
|
+
| [CSS Modules](#css-modules) | :heavy_check_mark:<sup>1</sup> | :heavy_check_mark:<sup>1</sup> | :heavy_check_mark:<sup>1</sup> |
|
|
199
|
+
| [import.meta.resolve](#resolve) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
|
|
200
|
+
| [Module Workers](#module-workers) (via wrapper) | 63+ | :x:<sup>2</sup> | 15+ |
|
|
201
|
+
| Top-Level Await (unpolyfilled<sup>3</sup>) | 89+ | 89+ | 15+ |
|
|
202
|
+
|
|
203
|
+
* 1: _CSS module support requires a separate [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme)._
|
|
204
|
+
* 2: _Module worker support cannot yet be implemented in Firefox due to no dynamic import support in web workers._
|
|
205
|
+
* 3: _Top-level await support is not currently polyfilled but is possible for ES Module Shims to implement for intermediate browser versions, with the feature request tracking in https://github.com/guybedford/es-module-shims/issues/5. The compatibility gap with native modules is currently < 5% of users so it may not even be necessary._
|
|
206
|
+
|
|
207
|
+
Browser compatibility **without** ES Module Shims:
|
|
208
|
+
|
|
209
|
+
| ES Modules Features | Chrome | Firefox | Safari |
|
|
210
|
+
| ---------------------------------- | ------------------ | ------------------ | ------------------ |
|
|
211
|
+
| [modulepreload](#modulepreload) | 66+ | :x: | :x: |
|
|
212
|
+
| [Dynamic Import](#dynamic-import) | 63+ | 67+ | 11.1+ |
|
|
213
|
+
| [import.meta.url](#importmetaurl) | ~76+ | ~67+ | ~12+ ❕<sup>1</sup> |
|
|
214
|
+
| [Import Maps](#import-maps) | 89+ | :x: | :x: |
|
|
215
|
+
| [JSON Modules](#json-modules) | 91+ | :x: | :x: |
|
|
216
|
+
| [CSS Modules](#css-modules) | 95+ | :x: | :x: |
|
|
217
|
+
| [import.meta.resolve](#resolve) | :x: | :x: | :x: |
|
|
218
|
+
| [Module Workers](#module-workers) | ~68+ | :x: | :x: |
|
|
219
|
+
| Top-Level Await | 89+ | 89+ | 15+ |
|
|
220
|
+
|
|
226
221
|
* ❕<sup>1</sup>: On module redirects, Safari returns the request URL in `import.meta.url` instead of the response URL as per the spec.
|
|
227
222
|
|
|
228
223
|
### Import Maps
|
|
@@ -435,9 +430,11 @@ var resolvedUrl = import.meta.resolve('dep', 'https://site.com/another/scope');
|
|
|
435
430
|
Node.js also implements a similar API, although it's in the process of shifting to a synchronous resolver.
|
|
436
431
|
|
|
437
432
|
### Module Workers
|
|
438
|
-
ES Module Shims can be used in module workers in browsers that provide dynamic import in worker environments, which at the moment are Chrome(80+), Edge(80+), Safari(15+).
|
|
439
433
|
|
|
440
|
-
|
|
434
|
+
ES Module Shims can be used in module workers in browsers that provide dynamic import in worker environments, which at the moment are Chrome(80+), Edge(80+) and Safari(15+).
|
|
435
|
+
|
|
436
|
+
By default, when there is no DOM present, ES Module Shims will switch into shim mode. An example of ES Module Shims usage through shim mode in web workers is provided below:
|
|
437
|
+
|
|
441
438
|
```js
|
|
442
439
|
/**
|
|
443
440
|
*
|
|
@@ -460,7 +457,8 @@ function getWorkerScriptURL(aURL) {
|
|
|
460
457
|
|
|
461
458
|
const worker = new Worker(getWorkerScriptURL('myEsModule.js'));
|
|
462
459
|
```
|
|
463
|
-
|
|
460
|
+
|
|
461
|
+
> Web workers must use the non-CSP build of ES Module Shims via `es-module-shim.wasm.js` from the `dist/` folder, since the CSP build currently assumes a DOM.
|
|
464
462
|
|
|
465
463
|
## Init Options
|
|
466
464
|
|
|
@@ -862,7 +860,7 @@ window.esmsInitOptions = {
|
|
|
862
860
|
|
|
863
861
|
* Sources are fetched, import specifiers are rewritten to reference exact URLs, and then executed as BlobURLs through the whole module graph.
|
|
864
862
|
* The [lexer](https://github.com/guybedford/es-module-lexer) handles the full language grammar including nested template strings, comments, regexes and division operator ambiguity based on backtracking.
|
|
865
|
-
* When executing a circular reference A -> B -> A, a shell module technique is used to
|
|
863
|
+
* When executing a circular reference A -> B -> A, a shell module technique is used to acyclify into the graph A -> B -> A Shell, with A -> A Shell. The shell module exports an update function which is called by the original once after the last import statement, and again after the last statement of the source file.
|
|
866
864
|
|
|
867
865
|
## Inspiration
|
|
868
866
|
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims 1.5.
|
|
1
|
+
/* ES Module Shims 1.5.13 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -320,33 +320,35 @@
|
|
|
320
320
|
jsonModulesEnabled && dynamicImport(jsonModulescheck).then(() => supportsJsonAssertions = true, noop),
|
|
321
321
|
]);
|
|
322
322
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
323
|
+
return new Promise(resolve => {
|
|
324
|
+
const iframe = document.createElement('iframe');
|
|
325
|
+
iframe.style.display = 'none';
|
|
326
|
+
iframe.setAttribute('nonce', nonce);
|
|
327
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
328
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
329
|
+
// therefore, we need to first feature detect srcdoc support
|
|
330
|
+
iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
|
|
331
|
+
document.head.appendChild(iframe);
|
|
332
|
+
iframe.onload = () => {
|
|
333
|
+
self._$s = (a, b, c, d) => {
|
|
334
|
+
document.head.removeChild(iframe);
|
|
335
|
+
supportsImportMaps = a;
|
|
336
|
+
supportsImportMeta = b;
|
|
337
|
+
supportsCssAssertions = c;
|
|
338
|
+
supportsJsonAssertions = d;
|
|
339
|
+
delete self._$s;
|
|
340
|
+
resolve();
|
|
341
|
+
};
|
|
342
|
+
const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
|
|
343
|
+
const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">Promise.all([${
|
|
344
|
+
supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
|
|
345
|
+
}].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
|
|
346
|
+
if (supportsSrcDoc)
|
|
347
|
+
iframe.srcdoc = importMapTest;
|
|
348
|
+
else
|
|
349
|
+
iframe.contentDocument.write(importMapTest);
|
|
340
350
|
};
|
|
341
|
-
|
|
342
|
-
const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">Promise.all([${
|
|
343
|
-
supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
|
|
344
|
-
}].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
|
|
345
|
-
if (supportsSrcDoc)
|
|
346
|
-
iframe.srcdoc = importMapTest;
|
|
347
|
-
else
|
|
348
|
-
iframe.contentDocument.write(importMapTest);
|
|
349
|
-
};
|
|
351
|
+
});
|
|
350
352
|
}
|
|
351
353
|
});
|
|
352
354
|
|
|
@@ -362,7 +364,7 @@
|
|
|
362
364
|
};
|
|
363
365
|
}
|
|
364
366
|
|
|
365
|
-
const resolve
|
|
367
|
+
const resolve = resolveHook ? async (id, parentUrl) => {
|
|
366
368
|
let result = resolveHook(id, parentUrl, defaultResolve);
|
|
367
369
|
// will be deprecated in next major
|
|
368
370
|
if (result && result.then)
|
|
@@ -384,12 +386,12 @@
|
|
|
384
386
|
if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
|
|
385
387
|
if (acceptingImportMaps || shimMode || !baselinePassthrough) {
|
|
386
388
|
if (hasDocument)
|
|
387
|
-
|
|
389
|
+
processScriptsAndPreloads(true);
|
|
388
390
|
if (!shimMode)
|
|
389
391
|
acceptingImportMaps = false;
|
|
390
392
|
}
|
|
391
393
|
await importMapPromise;
|
|
392
|
-
return topLevelLoad((await resolve
|
|
394
|
+
return topLevelLoad((await resolve(id, parentUrl)).r, { credentials: 'same-origin' });
|
|
393
395
|
}
|
|
394
396
|
|
|
395
397
|
self.importShim = importShim;
|
|
@@ -452,12 +454,12 @@
|
|
|
452
454
|
if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
|
|
453
455
|
processImportMap(node);
|
|
454
456
|
}
|
|
455
|
-
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
|
|
457
|
+
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) {
|
|
456
458
|
processPreload(node);
|
|
459
|
+
}
|
|
457
460
|
}
|
|
458
461
|
}
|
|
459
462
|
}).observe(document, {childList: true, subtree: true});
|
|
460
|
-
processImportMaps();
|
|
461
463
|
processScriptsAndPreloads();
|
|
462
464
|
if (document.readyState === 'complete') {
|
|
463
465
|
readyStateCompleteCheck();
|
|
@@ -465,7 +467,7 @@
|
|
|
465
467
|
else {
|
|
466
468
|
async function readyListener() {
|
|
467
469
|
await initPromise;
|
|
468
|
-
|
|
470
|
+
processScriptsAndPreloads();
|
|
469
471
|
if (document.readyState === 'complete') {
|
|
470
472
|
readyStateCompleteCheck();
|
|
471
473
|
document.removeEventListener('readystatechange', readyListener);
|
|
@@ -763,7 +765,7 @@
|
|
|
763
765
|
if (d >= 0 && !supportsDynamicImport || d === -2 && !supportsImportMeta)
|
|
764
766
|
load.n = true;
|
|
765
767
|
if (d !== -1 || !n) return;
|
|
766
|
-
const { r, b } = await resolve
|
|
768
|
+
const { r, b } = await resolve(n, load.r || load.u);
|
|
767
769
|
if (b && (!supportsImportMaps || importMapSrcOrLazy))
|
|
768
770
|
load.n = true;
|
|
769
771
|
if (skip && skip.test(r)) return { b: r };
|
|
@@ -776,16 +778,15 @@
|
|
|
776
778
|
return load;
|
|
777
779
|
}
|
|
778
780
|
|
|
779
|
-
function processScriptsAndPreloads () {
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
function processImportMaps () {
|
|
787
|
-
for (const script of document.querySelectorAll(shimMode ? 'script[type="importmap-shim"]' : 'script[type="importmap"]'))
|
|
781
|
+
function processScriptsAndPreloads (mapsOnly = false) {
|
|
782
|
+
if (!mapsOnly)
|
|
783
|
+
for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
|
|
784
|
+
processPreload(link);
|
|
785
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=importmap-shim]' : 'script[type=importmap]'))
|
|
788
786
|
processImportMap(script);
|
|
787
|
+
if (!mapsOnly)
|
|
788
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
|
|
789
|
+
processScript(script);
|
|
789
790
|
}
|
|
790
791
|
|
|
791
792
|
function getFetchOpts (script) {
|
|
@@ -814,11 +815,8 @@
|
|
|
814
815
|
if (hasDocument) {
|
|
815
816
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
816
817
|
await initPromise;
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
processImportMaps();
|
|
820
|
-
processScriptsAndPreloads();
|
|
821
|
-
}
|
|
818
|
+
if (shimMode || !baselinePassthrough)
|
|
819
|
+
domContentLoadedCheck();
|
|
822
820
|
});
|
|
823
821
|
}
|
|
824
822
|
|
|
@@ -829,10 +827,8 @@
|
|
|
829
827
|
}
|
|
830
828
|
|
|
831
829
|
function processImportMap (script) {
|
|
832
|
-
if (script.ep) // ep marker = script processed
|
|
833
|
-
return;
|
|
834
830
|
// empty inline scripts sometimes show before domready
|
|
835
|
-
if (!script.src && !script.innerHTML)
|
|
831
|
+
if (script.ep || !script.src && !script.innerHTML)
|
|
836
832
|
return;
|
|
837
833
|
script.ep = true;
|
|
838
834
|
// we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
|
|
@@ -853,14 +849,12 @@
|
|
|
853
849
|
}
|
|
854
850
|
|
|
855
851
|
function processScript (script) {
|
|
856
|
-
if (script.ep) // ep marker = script processed
|
|
857
|
-
return;
|
|
858
|
-
if (script.getAttribute('noshim') !== null)
|
|
859
|
-
return;
|
|
860
852
|
// empty inline scripts sometimes show before domready
|
|
861
|
-
if (!script.src && !script.innerHTML)
|
|
853
|
+
if (script.ep || !script.src && !script.innerHTML)
|
|
862
854
|
return;
|
|
863
855
|
script.ep = true;
|
|
856
|
+
if (script.getAttribute('noshim') !== null)
|
|
857
|
+
return;
|
|
864
858
|
// does this load block readystate complete
|
|
865
859
|
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
866
860
|
// does this load block DOMContentLoaded
|
|
@@ -876,8 +870,7 @@
|
|
|
876
870
|
|
|
877
871
|
const fetchCache = {};
|
|
878
872
|
function processPreload (link) {
|
|
879
|
-
if (link.ep)
|
|
880
|
-
return;
|
|
873
|
+
if (link.ep) return;
|
|
881
874
|
link.ep = true;
|
|
882
875
|
if (fetchCache[link.href])
|
|
883
876
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 1.5.
|
|
1
|
+
/* ES Module Shims Wasm 1.5.13 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -328,33 +328,35 @@
|
|
|
328
328
|
jsonModulesEnabled && dynamicImport(jsonModulescheck).then(() => supportsJsonAssertions = true, noop),
|
|
329
329
|
]);
|
|
330
330
|
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
331
|
+
return new Promise(resolve => {
|
|
332
|
+
const iframe = document.createElement('iframe');
|
|
333
|
+
iframe.style.display = 'none';
|
|
334
|
+
iframe.setAttribute('nonce', nonce);
|
|
335
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
336
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
337
|
+
// therefore, we need to first feature detect srcdoc support
|
|
338
|
+
iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
|
|
339
|
+
document.head.appendChild(iframe);
|
|
340
|
+
iframe.onload = () => {
|
|
341
|
+
self._$s = (a, b, c, d) => {
|
|
342
|
+
document.head.removeChild(iframe);
|
|
343
|
+
supportsImportMaps = a;
|
|
344
|
+
supportsImportMeta = b;
|
|
345
|
+
supportsCssAssertions = c;
|
|
346
|
+
supportsJsonAssertions = d;
|
|
347
|
+
delete self._$s;
|
|
348
|
+
resolve();
|
|
349
|
+
};
|
|
350
|
+
const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
|
|
351
|
+
const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">Promise.all([${
|
|
352
|
+
supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
|
|
353
|
+
}].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
|
|
354
|
+
if (supportsSrcDoc)
|
|
355
|
+
iframe.srcdoc = importMapTest;
|
|
356
|
+
else
|
|
357
|
+
iframe.contentDocument.write(importMapTest);
|
|
348
358
|
};
|
|
349
|
-
|
|
350
|
-
const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}<${''}/script><script nonce="${nonce}">Promise.all([${
|
|
351
|
-
supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
|
|
352
|
-
}].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
|
|
353
|
-
if (supportsSrcDoc)
|
|
354
|
-
iframe.srcdoc = importMapTest;
|
|
355
|
-
else
|
|
356
|
-
iframe.contentDocument.write(importMapTest);
|
|
357
|
-
};
|
|
359
|
+
});
|
|
358
360
|
}
|
|
359
361
|
});
|
|
360
362
|
|
|
@@ -370,7 +372,7 @@
|
|
|
370
372
|
};
|
|
371
373
|
}
|
|
372
374
|
|
|
373
|
-
const resolve
|
|
375
|
+
const resolve = resolveHook ? async (id, parentUrl) => {
|
|
374
376
|
let result = resolveHook(id, parentUrl, defaultResolve);
|
|
375
377
|
// will be deprecated in next major
|
|
376
378
|
if (result && result.then)
|
|
@@ -392,12 +394,12 @@
|
|
|
392
394
|
if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl);
|
|
393
395
|
if (acceptingImportMaps || shimMode || !baselinePassthrough) {
|
|
394
396
|
if (hasDocument)
|
|
395
|
-
|
|
397
|
+
processScriptsAndPreloads(true);
|
|
396
398
|
if (!shimMode)
|
|
397
399
|
acceptingImportMaps = false;
|
|
398
400
|
}
|
|
399
401
|
await importMapPromise;
|
|
400
|
-
return topLevelLoad((await resolve
|
|
402
|
+
return topLevelLoad((await resolve(id, parentUrl)).r, { credentials: 'same-origin' });
|
|
401
403
|
}
|
|
402
404
|
|
|
403
405
|
self.importShim = importShim;
|
|
@@ -460,12 +462,12 @@
|
|
|
460
462
|
if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
|
|
461
463
|
processImportMap(node);
|
|
462
464
|
}
|
|
463
|
-
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload'))
|
|
465
|
+
else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) {
|
|
464
466
|
processPreload(node);
|
|
467
|
+
}
|
|
465
468
|
}
|
|
466
469
|
}
|
|
467
470
|
}).observe(document, {childList: true, subtree: true});
|
|
468
|
-
processImportMaps();
|
|
469
471
|
processScriptsAndPreloads();
|
|
470
472
|
if (document.readyState === 'complete') {
|
|
471
473
|
readyStateCompleteCheck();
|
|
@@ -473,7 +475,7 @@
|
|
|
473
475
|
else {
|
|
474
476
|
async function readyListener() {
|
|
475
477
|
await initPromise;
|
|
476
|
-
|
|
478
|
+
processScriptsAndPreloads();
|
|
477
479
|
if (document.readyState === 'complete') {
|
|
478
480
|
readyStateCompleteCheck();
|
|
479
481
|
document.removeEventListener('readystatechange', readyListener);
|
|
@@ -771,7 +773,7 @@
|
|
|
771
773
|
if (d >= 0 && !supportsDynamicImport || d === -2 && !supportsImportMeta)
|
|
772
774
|
load.n = true;
|
|
773
775
|
if (d !== -1 || !n) return;
|
|
774
|
-
const { r, b } = await resolve
|
|
776
|
+
const { r, b } = await resolve(n, load.r || load.u);
|
|
775
777
|
if (b && (!supportsImportMaps || importMapSrcOrLazy))
|
|
776
778
|
load.n = true;
|
|
777
779
|
if (skip && skip.test(r)) return { b: r };
|
|
@@ -784,16 +786,15 @@
|
|
|
784
786
|
return load;
|
|
785
787
|
}
|
|
786
788
|
|
|
787
|
-
function processScriptsAndPreloads () {
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
function processImportMaps () {
|
|
795
|
-
for (const script of document.querySelectorAll(shimMode ? 'script[type="importmap-shim"]' : 'script[type="importmap"]'))
|
|
789
|
+
function processScriptsAndPreloads (mapsOnly = false) {
|
|
790
|
+
if (!mapsOnly)
|
|
791
|
+
for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
|
|
792
|
+
processPreload(link);
|
|
793
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=importmap-shim]' : 'script[type=importmap]'))
|
|
796
794
|
processImportMap(script);
|
|
795
|
+
if (!mapsOnly)
|
|
796
|
+
for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
|
|
797
|
+
processScript(script);
|
|
797
798
|
}
|
|
798
799
|
|
|
799
800
|
function getFetchOpts (script) {
|
|
@@ -822,11 +823,8 @@
|
|
|
822
823
|
if (hasDocument) {
|
|
823
824
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
824
825
|
await initPromise;
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
processImportMaps();
|
|
828
|
-
processScriptsAndPreloads();
|
|
829
|
-
}
|
|
826
|
+
if (shimMode || !baselinePassthrough)
|
|
827
|
+
domContentLoadedCheck();
|
|
830
828
|
});
|
|
831
829
|
}
|
|
832
830
|
|
|
@@ -837,10 +835,8 @@
|
|
|
837
835
|
}
|
|
838
836
|
|
|
839
837
|
function processImportMap (script) {
|
|
840
|
-
if (script.ep) // ep marker = script processed
|
|
841
|
-
return;
|
|
842
838
|
// empty inline scripts sometimes show before domready
|
|
843
|
-
if (!script.src && !script.innerHTML)
|
|
839
|
+
if (script.ep || !script.src && !script.innerHTML)
|
|
844
840
|
return;
|
|
845
841
|
script.ep = true;
|
|
846
842
|
// we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
|
|
@@ -861,14 +857,12 @@
|
|
|
861
857
|
}
|
|
862
858
|
|
|
863
859
|
function processScript (script) {
|
|
864
|
-
if (script.ep) // ep marker = script processed
|
|
865
|
-
return;
|
|
866
|
-
if (script.getAttribute('noshim') !== null)
|
|
867
|
-
return;
|
|
868
860
|
// empty inline scripts sometimes show before domready
|
|
869
|
-
if (!script.src && !script.innerHTML)
|
|
861
|
+
if (script.ep || !script.src && !script.innerHTML)
|
|
870
862
|
return;
|
|
871
863
|
script.ep = true;
|
|
864
|
+
if (script.getAttribute('noshim') !== null)
|
|
865
|
+
return;
|
|
872
866
|
// does this load block readystate complete
|
|
873
867
|
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
874
868
|
// does this load block DOMContentLoaded
|
|
@@ -884,8 +878,7 @@
|
|
|
884
878
|
|
|
885
879
|
const fetchCache = {};
|
|
886
880
|
function processPreload (link) {
|
|
887
|
-
if (link.ep)
|
|
888
|
-
return;
|
|
881
|
+
if (link.ep) return;
|
|
889
882
|
link.ep = true;
|
|
890
883
|
if (fetchCache[link.href])
|
|
891
884
|
return;
|