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 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.12/dist/es-module-shims.js"></script>
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 | Chrome (61+) | Firefox (60+) | Safari (10.1+) | Edge (17+) |
192
- | ---------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ | ------------------------------------ |
193
- | Executes Modules in Correct Order | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark:<sup>1</sup> |
194
- | [Dynamic Import](#dynamic-import) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
195
- | [import.meta.url](#importmetaurl) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
196
- | [Module Workers](#module-workers) | :heavy_check_mark: ~68+ | :x:<sup>2</sup> | :x:<sup>2</sup> | :x:<sup>2</sup> |
197
- | [modulepreload](#modulepreload) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
198
- | [Import Maps](#import-maps) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
199
- | [JSON Modules](#json-modules) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
200
- | [CSS Modules](#css-modules) | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> | :heavy_check_mark:<sup>3</sup> |
201
- | [import.meta.resolve](#resolve) | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: |
202
- | [Top-Level Await](#tla) | :heavy_check_mark: 89+ | :heavy_check_mark: 89+ | :x:<sup>4</sup> | :x:<sup>4</sup> |
203
-
204
- * 1: _The Edge parallel execution ordering bug is corrected by ES Module Shims with an execution chain inlining approach._
205
- * 2: _Module worker support cannot be implemented without dynamic import support in web workers._
206
- * 3: _CSS module support requires a separate [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme)._
207
- * 4: _Top-level await support is possible for ES Module Shims to implement, with the feature request tracking in https://github.com/guybedford/es-module-shims/issues/5._
208
-
209
- Browser compatibility **without ES module shims**:
210
-
211
- | ES Modules Features | Chrome (61+) | Firefox (60+) | Safari (10.1+) | Edge (17+) |
212
- | ---------------------------------- | ------------------------------------ | ------------------------------------ | ------------------------------------ | ------------------------------------ |
213
- | Executes Modules in Correct Order | :heavy_check_mark: | :heavy_check_mark: | :heavy_check_mark: | :x:<sup>1</sup> |
214
- | [Dynamic Import](#dynamic-import) | :heavy_check_mark: 63+ | :heavy_check_mark: 67+ | :heavy_check_mark: 11.1+ | :x: |
215
- | [import.meta.url](#importmetaurl) | :heavy_check_mark: ~76+ | :heavy_check_mark: ~67+ | :heavy_check_mark: ~12+ ❕<sup>1</sup>| :x: |
216
- | [Module Workers](#module-workers) | :heavy_check_mark: ~68+ | :x: | :x: | :x: |
217
- | [modulepreload](#modulepreload) | :heavy_check_mark: 66+ | :x: | :x: | :x: |
218
- | [Import Maps](#import-maps) | :heavy_check_mark: 89+ | :x: | :x: | :x: |
219
- | [JSON Modules](#json-modules) | :heavy_check_mark: 91+ | :x: | :x: | :x: |
220
- | [CSS Modules](#css-modules) | :heavy_check_mark: 95+ | :x: | :x: | :x: |
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
- An example of ES Module Shims usage in web workers is provided below:
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
- > For now, in web workers must be used the non-CSP build of ES Module Shims, namely the `es-module-shim.wasm.js` output: es-module-shims/dist/es-module-shims.wasm.js.
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 "shim" the circular reference into an acyclic graph. As a result, live bindings for the circular parent A are not supported, and instead the bindings are captured immediately after the execution of A.
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
 
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 1.5.12 */
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
- const iframe = document.createElement('iframe');
324
- iframe.style.display = 'none';
325
- iframe.setAttribute('nonce', nonce);
326
- // setting src to a blob URL results in a navigation event in webviews
327
- // setting srcdoc is not supported in React native webviews on iOS
328
- // therefore, we need to first feature detect srcdoc support
329
- iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
330
- document.head.appendChild(iframe);
331
- iframe.onload = () => {
332
- self._$s = (a, b, c, d) => {
333
- document.head.removeChild(iframe);
334
- supportsImportMaps = a;
335
- supportsImportMeta = b;
336
- supportsCssAssertions = c;
337
- supportsJsonAssertions = d;
338
- delete self._$s;
339
- resolve();
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
- const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
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$1 = resolveHook ? async (id, parentUrl) => {
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
- processImportMaps();
389
+ processScriptsAndPreloads(true);
388
390
  if (!shimMode)
389
391
  acceptingImportMaps = false;
390
392
  }
391
393
  await importMapPromise;
392
- return topLevelLoad((await resolve$1(id, parentUrl)).r, { credentials: 'same-origin' });
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
- processImportMaps();
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$1(n, load.r || load.u);
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
- for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
781
- processScript(script);
782
- for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
783
- processPreload(link);
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
- domContentLoadedCheck();
818
- if (shimMode || !baselinePassthrough) {
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) // ep marker = processed
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.12 */
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
- const iframe = document.createElement('iframe');
332
- iframe.style.display = 'none';
333
- iframe.setAttribute('nonce', nonce);
334
- // setting src to a blob URL results in a navigation event in webviews
335
- // setting srcdoc is not supported in React native webviews on iOS
336
- // therefore, we need to first feature detect srcdoc support
337
- iframe.srcdoc = `<!doctype html><script nonce="${nonce}"><${''}/script>`;
338
- document.head.appendChild(iframe);
339
- iframe.onload = () => {
340
- self._$s = (a, b, c, d) => {
341
- document.head.removeChild(iframe);
342
- supportsImportMaps = a;
343
- supportsImportMeta = b;
344
- supportsCssAssertions = c;
345
- supportsJsonAssertions = d;
346
- delete self._$s;
347
- resolve();
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
- const supportsSrcDoc = iframe.contentDocument.head.childNodes.length > 0;
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$1 = resolveHook ? async (id, parentUrl) => {
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
- processImportMaps();
397
+ processScriptsAndPreloads(true);
396
398
  if (!shimMode)
397
399
  acceptingImportMaps = false;
398
400
  }
399
401
  await importMapPromise;
400
- return topLevelLoad((await resolve$1(id, parentUrl)).r, { credentials: 'same-origin' });
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
- processImportMaps();
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$1(n, load.r || load.u);
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
- for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]'))
789
- processScript(script);
790
- for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]'))
791
- processPreload(link);
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
- domContentLoadedCheck();
826
- if (shimMode || !baselinePassthrough) {
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) // ep marker = processed
888
- return;
881
+ if (link.ep) return;
889
882
  link.ep = true;
890
883
  if (fetchCache[link.href])
891
884
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.5.12",
3
+ "version": "1.5.13",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {