es-module-shims 1.4.0 → 1.4.4

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/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ES Module Shims 1.4.4
2
+ * Fix: import.meta.resolve support for inline scripts (https://github.com/guybedford/es-module-shims/pull/251)
3
+ * Fix: CSS imports unquoted URL normalization (https://github.com/guybedford/es-module-shims/pull/252)
4
+ * Fix: Reword polyfill info message (https://github.com/guybedford/es-module-shims/pull/253)
5
+
6
+ ES Module Shims 1.4.3 (2022/01/25)
7
+ * Feature: Support import map overrides when existing resolution matches new resolution (https://github.com/guybedford/es-module-shims/pull/249, @vovacodes)
8
+ * Fix: Import assertions support with dynamic imports (https://github.com/guybedford/es-module-shims/pull/248)
9
+
10
+ ES Module Shims 1.4.2 (2022/01/24)
11
+ * Fix: optional catch binding in `isUrl` function (@thepassle, https://github.com/guybedford/es-module-shims/pull/246)
12
+
13
+ ES Module Shims 1.4.1 (2021/12/15)
14
+ * Fix: Firefox parse error stacks (https://github.com/guybedford/es-module-shims/pull/239)
15
+
1
16
  ES Module Shims 1.4.0 (2021/12/14)
2
17
  * Feature: "enforceIntegrity" option and "modulepreload-shim" support for secure shim mode with integrity (https://github.com/guybedford/es-module-shims/pull/236)
3
18
  * Fix: Safari parse error stacks (https://github.com/guybedford/es-module-shims/pull/238)
package/README.md CHANGED
@@ -4,7 +4,7 @@ Shims modern ES Modules features like import maps on top of the baseline modules
4
4
 
5
5
  When running in polyfill mode, [the 67% of users](https://caniuse.com/import-maps) with import maps entirely bypass the shim code entirely.
6
6
 
7
- In for the remaining 30% of users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
7
+ For the remaining 30% of users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
8
8
 
9
9
  The following modules features are polyfilled:
10
10
 
@@ -27,7 +27,7 @@ Because we are still using the native module loader the edge cases work out comp
27
27
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
28
28
 
29
29
  ```html
30
- <script async src="https://ga.jspm.io/npm:es-module-shims@1.3.6/dist/es-module-shims.js"></script>
30
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.4/dist/es-module-shims.js"></script>
31
31
 
32
32
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
33
33
  <script type="importmap">
@@ -287,7 +287,7 @@ import sheet from 'https://site.com/sheet.css' assert { type: 'css' };
287
287
  To support the polyfill or shim of this feature, the [Constructable Stylesheets polyfill](https://github.com/calebdwilliams/construct-style-sheets#readme) must be separately included in browsers not supporting [Constructable Stylesheets](https://developer.mozilla.org/en-US/docs/Web/API/CSSStyleSheet/CSSStyleSheet) eg via:
288
288
 
289
289
  ```html
290
- <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.0.0/dist/adoptedStyleSheets.js"></script>
290
+ <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.1.0/dist/adoptedStyleSheets.js"></script>
291
291
  ```
292
292
 
293
293
  For more information see the [web.dev article](https://web.dev/css-module-scripts/).
@@ -431,7 +431,7 @@ window.esmsInitOptions = {
431
431
  resolve: (id, parentUrl, resolve) => resolve(id, parentUrl), // default is spec resolution
432
432
  fetch: (url, options) => fetch(url, options), // default is native
433
433
  revokeBlobURLs: true, // default false
434
- enforceIntegrity: true, // default true
434
+ enforceIntegrity: true, // default false
435
435
  }
436
436
  </script>
437
437
  <script async src="es-module-shims.js"></script>
@@ -1,9 +1,10 @@
1
- /* ES Module Shims 1.4.0 */
1
+ /* ES Module Shims 1.4.4 */
2
2
  (function () {
3
3
 
4
- const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
4
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
5
+ const safari = !!window.safari;
5
6
 
6
- let baseUrl;
7
+ const baseUrl = document.baseURI;
7
8
 
8
9
  function createBlob (source, type = 'text/javascript') {
9
10
  return URL.createObjectURL(new Blob([source], { type }));
@@ -11,23 +12,12 @@
11
12
 
12
13
  const noop = () => {};
13
14
 
14
- const baseEl = document.querySelector('base[href]');
15
- if (baseEl)
16
- baseUrl = baseEl.href;
17
-
18
- if (!baseUrl && typeof location !== 'undefined') {
19
- baseUrl = location.href.split('#')[0].split('?')[0];
20
- const lastSepIndex = baseUrl.lastIndexOf('/');
21
- if (lastSepIndex !== -1)
22
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
23
- }
24
-
25
15
  function isURL (url) {
26
16
  try {
27
17
  new URL(url);
28
18
  return true;
29
19
  }
30
- catch {
20
+ catch(_) {
31
21
  return false;
32
22
  }
33
23
  }
@@ -85,28 +75,25 @@
85
75
  output.push(segmented.slice(segmentIndex, i + 1));
86
76
  segmentIndex = -1;
87
77
  }
78
+ continue;
88
79
  }
89
-
90
80
  // new segment - check if it is relative
91
81
  else if (segmented[i] === '.') {
92
82
  // ../ segment
93
83
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
94
84
  output.pop();
95
85
  i += 2;
86
+ continue;
96
87
  }
97
88
  // ./ segment
98
89
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
99
90
  i += 1;
100
- }
101
- else {
102
- // the start of a new segment as below
103
- segmentIndex = i;
91
+ continue;
104
92
  }
105
93
  }
106
94
  // it is the start of a new segment
107
- else {
108
- segmentIndex = i;
109
- }
95
+ while (segmented[i] === '/') i++;
96
+ segmentIndex = i;
110
97
  }
111
98
  // finish reading out the last segment
112
99
  if (segmentIndex !== -1)
@@ -129,7 +116,7 @@
129
116
  function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
130
117
  for (let p in packages) {
131
118
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
132
- if (outPackages[resolvedLhs]) {
119
+ if (outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
133
120
  throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
134
121
  }
135
122
  let target = packages[p];
@@ -208,7 +195,7 @@
208
195
  }
209
196
 
210
197
  const onerror = globalHook(esmsInitOptions.onerror || noop);
211
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
198
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
212
199
 
213
200
  const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
214
201
 
@@ -313,7 +300,6 @@
313
300
 
314
301
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
315
302
 
316
- let id = 0;
317
303
  const registry = {};
318
304
 
319
305
  async function loadAll (load, seen) {
@@ -484,7 +470,7 @@
484
470
  // once all deps have loaded we can inline the dependency resolution blobs
485
471
  // and define this blob
486
472
  let lastIndex = 0, depIndex = 0;
487
- for (const { s: start, se: end, d: dynamicImportIndex } of imports) {
473
+ for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
488
474
  // dependency source replacements
489
475
  if (dynamicImportIndex === -1) {
490
476
  const depLoad = load.d[depIndex++];
@@ -505,31 +491,30 @@
505
491
  }
506
492
  // circular shell execution
507
493
  else if (depLoad.s) {
508
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
509
- lastIndex = end;
494
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
495
+ lastIndex = statementEnd;
510
496
  depLoad.s = undefined;
511
497
  continue;
512
498
  }
513
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)}`;
514
- lastIndex = end;
499
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
500
+ lastIndex = statementEnd;
515
501
  }
516
502
  // import.meta
517
503
  else if (dynamicImportIndex === -2) {
518
504
  meta[load.r] = { url: load.r, resolve: importMetaResolve };
519
505
  resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
520
- lastIndex = end;
506
+ lastIndex = statementEnd;
521
507
  }
522
508
  // dynamic import
523
509
  else {
524
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
525
- lastIndex = end;
510
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${urlJsString(load.r)}${source.slice(end, statementEnd)}`;
511
+ lastIndex = statementEnd;
526
512
  }
527
513
  }
528
514
 
529
515
  resolvedSource += source.slice(lastIndex);
530
516
  }
531
517
 
532
- // ; and // trailer support added for Ruby 7 source maps compatibility
533
518
  let hasSourceURL = false;
534
519
  resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
535
520
  if (!hasSourceURL)
@@ -539,6 +524,8 @@
539
524
  load.S = undefined;
540
525
  }
541
526
 
527
+ // ; and // trailer support added for Ruby on Rails 7 source maps compatibility
528
+ // https://github.com/guybedford/es-module-shims/issues/228
542
529
  const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
543
530
 
544
531
  const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
@@ -578,24 +565,25 @@
578
565
  return { r: res.url, s: await res.text(), t: 'js' };
579
566
  else if (jsonContentType.test(contentType))
580
567
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
581
- else if (cssContentType.test(contentType))
568
+ else if (cssContentType.test(contentType)) {
582
569
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
583
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
570
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
584
571
  });export default s;`, t: 'css' };
572
+ }
585
573
  else
586
574
  throw Error(`Unsupported Content-Type "${contentType}"`);
587
575
  }
588
576
 
589
577
  function getOrCreateLoad (url, fetchOpts, source) {
590
578
  let load = registry[url];
591
- if (load)
579
+ if (load && !source)
592
580
  return load;
593
581
 
594
- load = registry[url] = {
582
+ load = {
595
583
  // url
596
584
  u: url,
597
585
  // response url
598
- r: undefined,
586
+ r: source ? url : undefined,
599
587
  // fetchPromise
600
588
  f: undefined,
601
589
  // source
@@ -615,6 +603,12 @@
615
603
  // type
616
604
  t: null
617
605
  };
606
+ if (registry[url]) {
607
+ let i = 0;
608
+ while (registry[load.u + ++i]);
609
+ load.u += i;
610
+ }
611
+ registry[load.u] = load;
618
612
 
619
613
  load.f = (async () => {
620
614
  if (!source) {
@@ -761,9 +755,13 @@
761
755
  if (isReadyScript) readyStateCompleteCnt++;
762
756
  if (isDomContentLoadedScript) domContentLoadedCnt++;
763
757
  const blocks = script.getAttribute('async') === null && isReadyScript;
764
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
765
- // This used to be a setTimeout(() => { throw e }) but this breaks Safari stacks
766
- console.error(e);
758
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
759
+ // Safari only gives error via console.error
760
+ if (safari)
761
+ console.error(e);
762
+ // Firefox only gives error stack via setTimeout
763
+ else
764
+ setTimeout(() => { throw e});
767
765
  onerror(e);
768
766
  });
769
767
  if (blocks)
@@ -1,9 +1,10 @@
1
- /* ES Module Shims Wasm 1.4.0 */
1
+ /* ES Module Shims Wasm 1.4.4 */
2
2
  (function () {
3
3
 
4
- const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
4
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
5
+ const safari = !!window.safari;
5
6
 
6
- let baseUrl;
7
+ const baseUrl = document.baseURI;
7
8
 
8
9
  function createBlob (source, type = 'text/javascript') {
9
10
  return URL.createObjectURL(new Blob([source], { type }));
@@ -11,23 +12,12 @@
11
12
 
12
13
  const noop = () => {};
13
14
 
14
- const baseEl = document.querySelector('base[href]');
15
- if (baseEl)
16
- baseUrl = baseEl.href;
17
-
18
- if (!baseUrl && typeof location !== 'undefined') {
19
- baseUrl = location.href.split('#')[0].split('?')[0];
20
- const lastSepIndex = baseUrl.lastIndexOf('/');
21
- if (lastSepIndex !== -1)
22
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
23
- }
24
-
25
15
  function isURL (url) {
26
16
  try {
27
17
  new URL(url);
28
18
  return true;
29
19
  }
30
- catch {
20
+ catch(_) {
31
21
  return false;
32
22
  }
33
23
  }
@@ -85,28 +75,25 @@
85
75
  output.push(segmented.slice(segmentIndex, i + 1));
86
76
  segmentIndex = -1;
87
77
  }
78
+ continue;
88
79
  }
89
-
90
80
  // new segment - check if it is relative
91
81
  else if (segmented[i] === '.') {
92
82
  // ../ segment
93
83
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
94
84
  output.pop();
95
85
  i += 2;
86
+ continue;
96
87
  }
97
88
  // ./ segment
98
89
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
99
90
  i += 1;
100
- }
101
- else {
102
- // the start of a new segment as below
103
- segmentIndex = i;
91
+ continue;
104
92
  }
105
93
  }
106
94
  // it is the start of a new segment
107
- else {
108
- segmentIndex = i;
109
- }
95
+ while (segmented[i] === '/') i++;
96
+ segmentIndex = i;
110
97
  }
111
98
  // finish reading out the last segment
112
99
  if (segmentIndex !== -1)
@@ -129,7 +116,7 @@
129
116
  function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
130
117
  for (let p in packages) {
131
118
  const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
132
- if (outPackages[resolvedLhs]) {
119
+ if (outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
133
120
  throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
134
121
  }
135
122
  let target = packages[p];
@@ -208,7 +195,7 @@
208
195
  }
209
196
 
210
197
  const onerror = globalHook(esmsInitOptions.onerror || noop);
211
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
198
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
212
199
 
213
200
  const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
214
201
 
@@ -311,7 +298,6 @@
311
298
 
312
299
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
313
300
 
314
- let id = 0;
315
301
  const registry = {};
316
302
 
317
303
  async function loadAll (load, seen) {
@@ -482,7 +468,7 @@
482
468
  // once all deps have loaded we can inline the dependency resolution blobs
483
469
  // and define this blob
484
470
  let lastIndex = 0, depIndex = 0;
485
- for (const { s: start, se: end, d: dynamicImportIndex } of imports) {
471
+ for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
486
472
  // dependency source replacements
487
473
  if (dynamicImportIndex === -1) {
488
474
  const depLoad = load.d[depIndex++];
@@ -503,31 +489,30 @@
503
489
  }
504
490
  // circular shell execution
505
491
  else if (depLoad.s) {
506
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
507
- lastIndex = end;
492
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)};import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
493
+ lastIndex = statementEnd;
508
494
  depLoad.s = undefined;
509
495
  continue;
510
496
  }
511
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)}`;
512
- lastIndex = end;
497
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
498
+ lastIndex = statementEnd;
513
499
  }
514
500
  // import.meta
515
501
  else if (dynamicImportIndex === -2) {
516
502
  meta[load.r] = { url: load.r, resolve: importMetaResolve };
517
503
  resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
518
- lastIndex = end;
504
+ lastIndex = statementEnd;
519
505
  }
520
506
  // dynamic import
521
507
  else {
522
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
523
- lastIndex = end;
508
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${urlJsString(load.r)}${source.slice(end, statementEnd)}`;
509
+ lastIndex = statementEnd;
524
510
  }
525
511
  }
526
512
 
527
513
  resolvedSource += source.slice(lastIndex);
528
514
  }
529
515
 
530
- // ; and // trailer support added for Ruby 7 source maps compatibility
531
516
  let hasSourceURL = false;
532
517
  resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
533
518
  if (!hasSourceURL)
@@ -537,6 +522,8 @@
537
522
  load.S = undefined;
538
523
  }
539
524
 
525
+ // ; and // trailer support added for Ruby on Rails 7 source maps compatibility
526
+ // https://github.com/guybedford/es-module-shims/issues/228
540
527
  const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
541
528
 
542
529
  const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
@@ -576,24 +563,25 @@
576
563
  return { r: res.url, s: await res.text(), t: 'js' };
577
564
  else if (jsonContentType.test(contentType))
578
565
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
579
- else if (cssContentType.test(contentType))
566
+ else if (cssContentType.test(contentType)) {
580
567
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
581
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
568
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
582
569
  });export default s;`, t: 'css' };
570
+ }
583
571
  else
584
572
  throw Error(`Unsupported Content-Type "${contentType}"`);
585
573
  }
586
574
 
587
575
  function getOrCreateLoad (url, fetchOpts, source) {
588
576
  let load = registry[url];
589
- if (load)
577
+ if (load && !source)
590
578
  return load;
591
579
 
592
- load = registry[url] = {
580
+ load = {
593
581
  // url
594
582
  u: url,
595
583
  // response url
596
- r: undefined,
584
+ r: source ? url : undefined,
597
585
  // fetchPromise
598
586
  f: undefined,
599
587
  // source
@@ -613,6 +601,12 @@
613
601
  // type
614
602
  t: null
615
603
  };
604
+ if (registry[url]) {
605
+ let i = 0;
606
+ while (registry[load.u + ++i]);
607
+ load.u += i;
608
+ }
609
+ registry[load.u] = load;
616
610
 
617
611
  load.f = (async () => {
618
612
  if (!source) {
@@ -759,9 +753,13 @@
759
753
  if (isReadyScript) readyStateCompleteCnt++;
760
754
  if (isDomContentLoadedScript) domContentLoadedCnt++;
761
755
  const blocks = script.getAttribute('async') === null && isReadyScript;
762
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
763
- // This used to be a setTimeout(() => { throw e }) but this breaks Safari stacks
764
- console.error(e);
756
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
757
+ // Safari only gives error via console.error
758
+ if (safari)
759
+ console.error(e);
760
+ // Firefox only gives error stack via setTimeout
761
+ else
762
+ setTimeout(() => { throw e});
765
763
  onerror(e);
766
764
  });
767
765
  if (blocks)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.4.0",
3
+ "version": "1.4.4",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {