es-module-shims 1.5.13 → 1.5.14

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.13/dist/es-module-shims.js"></script>
32
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.5.14/dist/es-module-shims.js"></script>
33
33
 
34
34
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
35
35
  <script type="importmap">
@@ -1,4 +1,4 @@
1
- /* ES Module Shims 1.5.13 */
1
+ /* ES Module Shims 1.5.14 */
2
2
  (function () {
3
3
 
4
4
  const hasWindow = typeof window !== 'undefined';
@@ -340,7 +340,7 @@
340
340
  resolve();
341
341
  };
342
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([${
343
+ const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}}<${''}/script><script nonce="${nonce}">Promise.all([${
344
344
  supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
345
345
  }].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
346
346
  if (supportsSrcDoc)
@@ -450,9 +450,9 @@
450
450
  for (const node of mutation.addedNodes) {
451
451
  if (node.tagName === 'SCRIPT') {
452
452
  if (node.type === (shimMode ? 'module-shim' : 'module'))
453
- processScript(node);
453
+ processScript(node, true);
454
454
  if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
455
- processImportMap(node);
455
+ processImportMap(node, true);
456
456
  }
457
457
  else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) {
458
458
  processPreload(node);
@@ -826,11 +826,11 @@
826
826
  document.dispatchEvent(new Event('readystatechange'));
827
827
  }
828
828
 
829
- function processImportMap (script) {
830
- // empty inline scripts sometimes show before domready
831
- if (script.ep || !script.src && !script.innerHTML)
832
- return;
833
- script.ep = true;
829
+ const hasNext = script => script.nextSibling || script.parentNode && hasNext(script.parentNode);
830
+ const epCheck = (script, ready) => script.ep || !ready && (!script.src && !script.innerHTML || !hasNext(script)) || script.getAttribute('noshim') !== null || !(script.ep = true);
831
+
832
+ function processImportMap (script, ready = readyStateCompleteCnt > 0) {
833
+ if (epCheck(script, ready)) return;
834
834
  // we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
835
835
  if (script.src) {
836
836
  if (!shimMode)
@@ -842,19 +842,19 @@
842
842
  .then(async () => {
843
843
  importMap = resolveAndComposeImportMap(script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
844
844
  })
845
- .catch(throwError);
845
+ .catch(e => {
846
+ console.log(e);
847
+ if (e instanceof SyntaxError)
848
+ e = new Error(`Unable to parse import map ${e.message} in: ${script.src || script.innerHTML}`);
849
+ throwError(e);
850
+ });
846
851
  if (!shimMode)
847
852
  acceptingImportMaps = false;
848
853
  }
849
854
  }
850
855
 
851
- function processScript (script) {
852
- // empty inline scripts sometimes show before domready
853
- if (script.ep || !script.src && !script.innerHTML)
854
- return;
855
- script.ep = true;
856
- if (script.getAttribute('noshim') !== null)
857
- return;
856
+ function processScript (script, ready = readyStateCompleteCnt > 0) {
857
+ if (epCheck(script, ready)) return;
858
858
  // does this load block readystate complete
859
859
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
860
860
  // does this load block DOMContentLoaded
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 1.5.13 */
1
+ /* ES Module Shims Wasm 1.5.14 */
2
2
  (function () {
3
3
 
4
4
  const hasWindow = typeof window !== 'undefined';
@@ -348,7 +348,7 @@
348
348
  resolve();
349
349
  };
350
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([${
351
+ const importMapTest = `<!doctype html><script type=importmap nonce="${nonce}">{"imports":{"x":"${createBlob('')}"}}<${''}/script><script nonce="${nonce}">Promise.all([${
352
352
  supportsImportMaps ? 'true, true' : `'x', '${importMetaCheck}'`}, ${cssModulesEnabled ? `'${cssModulesCheck}'` : 'false'}, ${jsonModulesEnabled ? `'${jsonModulesCheck}'` : 'false'
353
353
  }].map(x => typeof x === 'string' ? import(x).then(x => !!x, () => false) : x)).then(a=>parent._$s.apply(null, a))<${''}/script>`;
354
354
  if (supportsSrcDoc)
@@ -458,9 +458,9 @@
458
458
  for (const node of mutation.addedNodes) {
459
459
  if (node.tagName === 'SCRIPT') {
460
460
  if (node.type === (shimMode ? 'module-shim' : 'module'))
461
- processScript(node);
461
+ processScript(node, true);
462
462
  if (node.type === (shimMode ? 'importmap-shim' : 'importmap'))
463
- processImportMap(node);
463
+ processImportMap(node, true);
464
464
  }
465
465
  else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) {
466
466
  processPreload(node);
@@ -834,11 +834,11 @@
834
834
  document.dispatchEvent(new Event('readystatechange'));
835
835
  }
836
836
 
837
- function processImportMap (script) {
838
- // empty inline scripts sometimes show before domready
839
- if (script.ep || !script.src && !script.innerHTML)
840
- return;
841
- script.ep = true;
837
+ const hasNext = script => script.nextSibling || script.parentNode && hasNext(script.parentNode);
838
+ const epCheck = (script, ready) => script.ep || !ready && (!script.src && !script.innerHTML || !hasNext(script)) || script.getAttribute('noshim') !== null || !(script.ep = true);
839
+
840
+ function processImportMap (script, ready = readyStateCompleteCnt > 0) {
841
+ if (epCheck(script, ready)) return;
842
842
  // we dont currently support multiple, external or dynamic imports maps in polyfill mode to match native
843
843
  if (script.src) {
844
844
  if (!shimMode)
@@ -850,19 +850,19 @@
850
850
  .then(async () => {
851
851
  importMap = resolveAndComposeImportMap(script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
852
852
  })
853
- .catch(throwError);
853
+ .catch(e => {
854
+ console.log(e);
855
+ if (e instanceof SyntaxError)
856
+ e = new Error(`Unable to parse import map ${e.message} in: ${script.src || script.innerHTML}`);
857
+ throwError(e);
858
+ });
854
859
  if (!shimMode)
855
860
  acceptingImportMaps = false;
856
861
  }
857
862
  }
858
863
 
859
- function processScript (script) {
860
- // empty inline scripts sometimes show before domready
861
- if (script.ep || !script.src && !script.innerHTML)
862
- return;
863
- script.ep = true;
864
- if (script.getAttribute('noshim') !== null)
865
- return;
864
+ function processScript (script, ready = readyStateCompleteCnt > 0) {
865
+ if (epCheck(script, ready)) return;
866
866
  // does this load block readystate complete
867
867
  const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
868
868
  // does this load block DOMContentLoaded
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.5.13",
3
+ "version": "1.5.14",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {