es-module-shims 1.4.2 → 1.4.6

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,22 @@
1
+ ES Module Shims 1.4.6 (2022/02/15)
2
+ * Feat: Improve fetch content type error failure context (https://github.com/guybedford/es-module-shims/pull/263)
3
+ * Feat: Refactor error handling paths, use `reportError` when possible (https://github.com/guybedford/es-module-shims/pull/264)
4
+
5
+ ES Module Shims 1.4.5 (2022/02/12)
6
+ * Feat: Allow import map overrides with option (https://github.com/guybedford/es-module-shims/pull/257, @lewisl@9029)
7
+ * Feat: Additional fetch error context (https://github.com/guybedford/es-module-shims/pull/256)
8
+ * Fix: dynamic import context with import assertions (https://github.com/guybedford/es-module-shims/pull/260, @ICodeMyOwnLife)
9
+ * Docs: Clarify modulepreload-shim (https://github.com/guybedford/es-module-shims/pull/261, @LarsDenBakker)
10
+
11
+ ES Module Shims 1.4.4 (2022/02/03)
12
+ * Fix: import.meta.resolve support for inline scripts (https://github.com/guybedford/es-module-shims/pull/251)
13
+ * Fix: CSS imports unquoted URL normalization (https://github.com/guybedford/es-module-shims/pull/252)
14
+ * Fix: Reword polyfill info message (https://github.com/guybedford/es-module-shims/pull/253)
15
+
16
+ ES Module Shims 1.4.3 (2022/01/25)
17
+ * Feature: Support import map overrides when existing resolution matches new resolution (https://github.com/guybedford/es-module-shims/pull/249, @vovacodes)
18
+ * Fix: Import assertions support with dynamic imports (https://github.com/guybedford/es-module-shims/pull/248)
19
+
1
20
  ES Module Shims 1.4.2 (2022/01/24)
2
21
  * Fix: optional catch binding in `isUrl` function (@thepassle, https://github.com/guybedford/es-module-shims/pull/246)
3
22
 
package/README.md CHANGED
@@ -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.4.2/dist/es-module-shims.js"></script>
30
+ <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.6/dist/es-module-shims.js"></script>
31
31
 
32
32
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
33
33
  <script type="importmap">
@@ -227,6 +227,10 @@ This tag just initiates a fetch request in the browser and thus works equally as
227
227
  Unlike the browser specification, the modulepreload polyfill does not request dependency modules by default, in order to avoid unnecessary
228
228
  code analysis in the polyfill scenarios. **It is recommended to preload deep imports anyway so that this feature shouldn't be necessary.**
229
229
 
230
+ #### Preload shim
231
+
232
+ When in shim mode, `<link rel="modulepreload-shim" href="/module.js" />` must be used to properly cache the preloaded modules.
233
+
230
234
  ### CSP Support
231
235
 
232
236
  By default ES Module Shims provides full support for CSP by using the asm.js ES Module Lexer build. This is absolutely identical in performance to the Wasm version in Firefox and Chrome, while in Safari the asm.js version is actually faster than Wasm making this build preferable.
@@ -287,7 +291,7 @@ import sheet from 'https://site.com/sheet.css' assert { type: 'css' };
287
291
  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
292
 
289
293
  ```html
290
- <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.0.0/dist/adoptedStyleSheets.js"></script>
294
+ <script async src="https://unpkg.com/construct-style-sheets-polyfill@3.1.0/dist/adoptedStyleSheets.js"></script>
291
295
  ```
292
296
 
293
297
  For more information see the [web.dev article](https://web.dev/css-module-scripts/).
@@ -417,6 +421,7 @@ Provide a `esmsInitOptions` on the global scope before `es-module-shims` is load
417
421
  * [resolve](#resolve-hook)
418
422
  * [fetch](#fetch-hook)
419
423
  * [revokeBlobURLs](#revoke-blob-urls)
424
+ * [mapOverrides](#overriding-import-map-entries)
420
425
 
421
426
  ```html
422
427
  <script>
@@ -432,6 +437,7 @@ window.esmsInitOptions = {
432
437
  fetch: (url, options) => fetch(url, options), // default is native
433
438
  revokeBlobURLs: true, // default false
434
439
  enforceIntegrity: true, // default false
440
+ mapOverrides: true, // default false
435
441
  }
436
442
  </script>
437
443
  <script async src="es-module-shims.js"></script>
@@ -687,6 +693,37 @@ You can do that by enabling the `revokeBlobURLs` init option:
687
693
  NOTE: revoking object URLs is not entirely free, while we are trying to be smart about it and make sure it doesn't
688
694
  cause janks, we recommend enabling this option only if you have done the measurements and identified that you really need it.
689
695
 
696
+ ### Overriding import map entries
697
+
698
+ When [dynamically injecting import maps](#dynamic-import-maps), an error will be thrown in both polyfill and shim modes if the new import map would override existing entries with a different value.
699
+
700
+ It is possible to disable this behavior in shim mode by setting the `mapOverrides` option:
701
+
702
+ ```js
703
+ <script type="esms-options">
704
+ {
705
+ "shimMode": true,
706
+ "mapOverrides": true
707
+ }
708
+ </script>
709
+ <script type="importmap-shim">
710
+ {
711
+ "imports": {
712
+ "x": "/x.js"
713
+ }
714
+ }
715
+ </script>
716
+ <script>
717
+ // No error will be thrown here
718
+ document.body.appendChild(Object.assign(document.createElement('script'), {
719
+ type: 'importmap',
720
+ innerHTML: JSON.stringify({ imports: { x: './y.js' } }),
721
+ }));
722
+ </script>
723
+ ```
724
+
725
+ This can be useful for HMR workflows.
726
+
690
727
  ## Implementation Details
691
728
 
692
729
  ### Import Rewriting
@@ -1,40 +1,81 @@
1
- /* ES Module Shims 1.4.2 */
1
+ /* ES Module Shims 1.4.6 */
2
2
  (function () {
3
3
 
4
- const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
5
- const edge = uaMatch && uaMatch[1] === 'Edge';
6
- const safari = uaMatch && uaMatch[1] === 'Safari';
4
+ const noop = () => {};
7
5
 
8
- let baseUrl;
6
+ const optionsScript = document.querySelector('script[type=esms-options]');
9
7
 
10
- function createBlob (source, type = 'text/javascript') {
11
- return URL.createObjectURL(new Blob([source], { type }));
8
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
9
+
10
+ let shimMode = !!esmsInitOptions.shimMode;
11
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
12
+
13
+ const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
14
+
15
+ let nonce = esmsInitOptions.nonce;
16
+
17
+ const mapOverrides = esmsInitOptions.mapOverrides;
18
+
19
+ if (!nonce) {
20
+ const nonceElement = document.querySelector('script[nonce]');
21
+ if (nonceElement)
22
+ nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
12
23
  }
13
24
 
14
- const noop = () => {};
25
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
26
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
27
+
28
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
29
+
30
+ const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
31
+
32
+ function globalHook (name) {
33
+ return typeof name === 'string' ? self[name] : name;
34
+ }
35
+
36
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
37
+ const cssModulesEnabled = enable.includes('css-modules');
38
+ const jsonModulesEnabled = enable.includes('json-modules');
39
+
40
+ function setShimMode () {
41
+ shimMode = true;
42
+ }
43
+
44
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
15
45
 
16
- const baseEl = document.querySelector('base[href]');
17
- if (baseEl)
18
- baseUrl = baseEl.href;
46
+ const baseUrl = document.baseURI;
19
47
 
20
- if (!baseUrl && typeof location !== 'undefined') {
21
- baseUrl = location.href.split('#')[0].split('?')[0];
22
- const lastSepIndex = baseUrl.lastIndexOf('/');
23
- if (lastSepIndex !== -1)
24
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
48
+ function createBlob (source, type = 'text/javascript') {
49
+ return URL.createObjectURL(new Blob([source], { type }));
25
50
  }
26
51
 
52
+ const eoop = err => setTimeout(() => { throw err });
53
+
54
+ const throwError = err => { (window.reportError || window.safari && console.error || eoop)(err), void onerror(err); };
55
+
27
56
  function isURL (url) {
28
57
  try {
29
58
  new URL(url);
30
59
  return true;
31
60
  }
32
- catch(_) {
61
+ catch (_) {
33
62
  return false;
34
63
  }
64
+ }
65
+
66
+ const backslashRegEx = /\\/g;
67
+
68
+ /*
69
+ * Import maps implementation
70
+ *
71
+ * To make lookups fast we pre-resolve the entire import map
72
+ * and then match based on backtracked hash lookups
73
+ *
74
+ */
75
+ function resolveUrl (relUrl, parentUrl) {
76
+ return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
35
77
  }
36
78
 
37
- const backslashRegEx = /\\/g;
38
79
  function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
39
80
  // strip off any trailing query params or hashes
40
81
  parentUrl = parentUrl && parentUrl.split('#')[0].split('?')[0];
@@ -87,28 +128,25 @@
87
128
  output.push(segmented.slice(segmentIndex, i + 1));
88
129
  segmentIndex = -1;
89
130
  }
131
+ continue;
90
132
  }
91
-
92
133
  // new segment - check if it is relative
93
134
  else if (segmented[i] === '.') {
94
135
  // ../ segment
95
136
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
96
137
  output.pop();
97
138
  i += 2;
139
+ continue;
98
140
  }
99
141
  // ./ segment
100
142
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
101
143
  i += 1;
102
- }
103
- else {
104
- // the start of a new segment as below
105
- segmentIndex = i;
144
+ continue;
106
145
  }
107
146
  }
108
147
  // it is the start of a new segment
109
- else {
110
- segmentIndex = i;
111
- }
148
+ while (segmented[i] === '/') i++;
149
+ segmentIndex = i;
112
150
  }
113
151
  // finish reading out the last segment
114
152
  if (segmentIndex !== -1)
@@ -117,35 +155,6 @@
117
155
  }
118
156
  }
119
157
 
120
- /*
121
- * Import maps implementation
122
- *
123
- * To make lookups fast we pre-resolve the entire import map
124
- * and then match based on backtracked hash lookups
125
- *
126
- */
127
- function resolveUrl (relUrl, parentUrl) {
128
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
129
- }
130
-
131
- function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
132
- for (let p in packages) {
133
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
134
- if (outPackages[resolvedLhs]) {
135
- throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
136
- }
137
- let target = packages[p];
138
- if (typeof target !== 'string')
139
- continue;
140
- const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
141
- if (mapped) {
142
- outPackages[resolvedLhs] = mapped;
143
- continue;
144
- }
145
- console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
146
- }
147
- }
148
-
149
158
  function resolveAndComposeImportMap (json, baseUrl, parentMap) {
150
159
  const outMap = { imports: Object.assign({}, parentMap.imports), scopes: Object.assign({}, parentMap.scopes) };
151
160
 
@@ -181,6 +190,7 @@
181
190
  }
182
191
  }
183
192
 
193
+
184
194
  function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
185
195
  let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
186
196
  while (scopeUrl) {
@@ -190,42 +200,24 @@
190
200
  scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
191
201
  }
192
202
  return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
193
- }
194
-
195
- const optionsScript = document.querySelector('script[type=esms-options]');
196
-
197
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
198
-
199
- let shimMode = !!esmsInitOptions.shimMode;
200
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
201
-
202
- const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
203
-
204
- let nonce = esmsInitOptions.nonce;
205
-
206
- if (!nonce) {
207
- const nonceElement = document.querySelector('script[nonce]');
208
- if (nonceElement)
209
- nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
210
203
  }
211
204
 
212
- const onerror = globalHook(esmsInitOptions.onerror || noop);
213
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
214
-
215
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
216
-
217
- const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
218
-
219
- function globalHook (name) {
220
- return typeof name === 'string' ? self[name] : name;
221
- }
222
-
223
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
224
- const cssModulesEnabled = enable.includes('css-modules');
225
- const jsonModulesEnabled = enable.includes('json-modules');
226
-
227
- function setShimMode () {
228
- shimMode = true;
205
+ function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
206
+ for (let p in packages) {
207
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
208
+ if ((!shimMode || !mapOverrides) && outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
209
+ throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
210
+ }
211
+ let target = packages[p];
212
+ if (typeof target !== 'string')
213
+ continue;
214
+ const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
215
+ if (mapped) {
216
+ outPackages[resolvedLhs] = mapped;
217
+ continue;
218
+ }
219
+ console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
220
+ }
229
221
  }
230
222
 
231
223
  let err;
@@ -315,7 +307,6 @@
315
307
 
316
308
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
317
309
 
318
- let id = 0;
319
310
  const registry = {};
320
311
 
321
312
  async function loadAll (load, seen) {
@@ -390,7 +381,7 @@
390
381
  await lastStaticLoadPromise;
391
382
  return dynamicImport(source ? createBlob(source) : url, { errUrl: url || source });
392
383
  }
393
- const load = getOrCreateLoad(url, fetchOpts, source);
384
+ const load = getOrCreateLoad(url, fetchOpts, null, source);
394
385
  const seen = {};
395
386
  await loadAll(load, seen);
396
387
  lastLoad = undefined;
@@ -432,7 +423,12 @@
432
423
  }
433
424
  }
434
425
 
435
- async function importShim (id, parentUrl = baseUrl, _assertion) {
426
+ async function importShim (id, ...args) {
427
+ // parentUrl if present will be the last argument
428
+ let parentUrl = args[args.length - 1];
429
+ if (typeof parentUrl !== 'string') {
430
+ parentUrl = baseUrl;
431
+ }
436
432
  // needed for shim check
437
433
  await initPromise;
438
434
  if (acceptingImportMaps || shimMode || !baselinePassthrough) {
@@ -486,7 +482,7 @@
486
482
  // once all deps have loaded we can inline the dependency resolution blobs
487
483
  // and define this blob
488
484
  let lastIndex = 0, depIndex = 0;
489
- for (const { s: start, se: end, d: dynamicImportIndex } of imports) {
485
+ for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
490
486
  // dependency source replacements
491
487
  if (dynamicImportIndex === -1) {
492
488
  const depLoad = load.d[depIndex++];
@@ -507,24 +503,24 @@
507
503
  }
508
504
  // circular shell execution
509
505
  else if (depLoad.s) {
510
- 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})`;
511
- lastIndex = end;
506
+ 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})`;
507
+ lastIndex = statementEnd;
512
508
  depLoad.s = undefined;
513
509
  continue;
514
510
  }
515
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)}`;
516
- lastIndex = end;
511
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
512
+ lastIndex = statementEnd;
517
513
  }
518
514
  // import.meta
519
515
  else if (dynamicImportIndex === -2) {
520
516
  meta[load.r] = { url: load.r, resolve: importMetaResolve };
521
517
  resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
522
- lastIndex = end;
518
+ lastIndex = statementEnd;
523
519
  }
524
520
  // dynamic import
525
521
  else {
526
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
527
- lastIndex = end;
522
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, statementEnd)}, ${urlJsString(load.r)}`;
523
+ lastIndex = statementEnd;
528
524
  }
529
525
  }
530
526
 
@@ -563,42 +559,56 @@
563
559
  p.shift()();
564
560
  }
565
561
 
566
- async function doFetch (url, fetchOpts) {
562
+ function fromParent (parent) {
563
+ return parent ? ` imported from ${parent}` : '';
564
+ }
565
+
566
+ async function doFetch (url, fetchOpts, parent) {
567
567
  if (enforceIntegrity && !fetchOpts.integrity)
568
- throw Error(`No integrity for ${url}`);
568
+ throw Error(`No integrity for ${url}${fromParent(parent)}.`);
569
569
  const poolQueue = pushFetchPool();
570
570
  if (poolQueue) await poolQueue;
571
571
  try {
572
572
  var res = await fetchHook(url, fetchOpts);
573
573
  }
574
+ catch (e) {
575
+ e.message = `Unable to fetch ${url}${fromParent(parent)} - see network log for details.\n` + e.message;
576
+ throw e;
577
+ }
574
578
  finally {
575
579
  popFetchPool();
576
580
  }
577
581
  if (!res.ok)
578
- throw Error(`${res.status} ${res.statusText} ${res.url}`);
582
+ throw Error(`${res.status} ${res.statusText} ${res.url}${fromParent(parent)}`);
583
+ return res;
584
+ }
585
+
586
+ async function fetchModule (url, fetchOpts, parent) {
587
+ const res = await doFetch(url, fetchOpts, parent);
579
588
  const contentType = res.headers.get('content-type');
580
589
  if (jsContentType.test(contentType))
581
590
  return { r: res.url, s: await res.text(), t: 'js' };
582
591
  else if (jsonContentType.test(contentType))
583
592
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
584
- else if (cssContentType.test(contentType))
593
+ else if (cssContentType.test(contentType)) {
585
594
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
586
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
595
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
587
596
  });export default s;`, t: 'css' };
597
+ }
588
598
  else
589
- throw Error(`Unsupported Content-Type "${contentType}"`);
599
+ throw Error(`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`);
590
600
  }
591
601
 
592
- function getOrCreateLoad (url, fetchOpts, source) {
602
+ function getOrCreateLoad (url, fetchOpts, parent, source) {
593
603
  let load = registry[url];
594
- if (load)
604
+ if (load && !source)
595
605
  return load;
596
606
 
597
- load = registry[url] = {
607
+ load = {
598
608
  // url
599
609
  u: url,
600
610
  // response url
601
- r: undefined,
611
+ r: source ? url : undefined,
602
612
  // fetchPromise
603
613
  f: undefined,
604
614
  // source
@@ -618,12 +628,18 @@
618
628
  // type
619
629
  t: null
620
630
  };
631
+ if (registry[url]) {
632
+ let i = 0;
633
+ while (registry[load.u + ++i]);
634
+ load.u += i;
635
+ }
636
+ registry[load.u] = load;
621
637
 
622
638
  load.f = (async () => {
623
639
  if (!source) {
624
640
  // preload fetch options override fetch options (race)
625
641
  let t;
626
- ({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
642
+ ({ r: load.r, s: source, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
627
643
  if (t && !shimMode) {
628
644
  if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
629
645
  throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
@@ -657,7 +673,7 @@
657
673
  if (skip && skip.test(r)) return { b: r };
658
674
  if (childFetchOpts.integrity)
659
675
  childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
660
- return getOrCreateLoad(r, childFetchOpts).f;
676
+ return getOrCreateLoad(r, childFetchOpts, load.r).f;
661
677
  }))).filter(l => l);
662
678
  });
663
679
 
@@ -740,9 +756,9 @@
740
756
  if (acceptingImportMaps) {
741
757
  importMapPromise = importMapPromise
742
758
  .then(async () => {
743
- importMap = resolveAndComposeImportMap(script.src ? await (await fetchHook(script.src)).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
759
+ importMap = resolveAndComposeImportMap(script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
744
760
  })
745
- .catch(error => setTimeout(() => { throw error }));
761
+ .catch(throwError);
746
762
  if (!shimMode)
747
763
  acceptingImportMaps = false;
748
764
  }
@@ -764,15 +780,7 @@
764
780
  if (isReadyScript) readyStateCompleteCnt++;
765
781
  if (isDomContentLoadedScript) domContentLoadedCnt++;
766
782
  const blocks = script.getAttribute('async') === null && isReadyScript;
767
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
768
- // Safari only gives error via console.error
769
- if (safari)
770
- console.error(e);
771
- // Firefox only gives error stack via setTimeout
772
- else
773
- setTimeout(() => { throw e});
774
- onerror(e);
775
- });
783
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(throwError);
776
784
  if (blocks)
777
785
  lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
778
786
  if (isDomContentLoadedScript)
@@ -786,11 +794,11 @@
786
794
  link.ep = true;
787
795
  if (fetchCache[link.href])
788
796
  return;
789
- fetchCache[link.href] = doFetch(link.href, getFetchOpts(link));
797
+ fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
790
798
  }
791
799
 
792
800
  function throwUnresolved (id, parentUrl) {
793
- throw Error("Unable to resolve specifier '" + id + (parentUrl ? "' from " + parentUrl : "'"));
801
+ throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
794
802
  }
795
803
 
796
804
  })();
@@ -1,40 +1,81 @@
1
- /* ES Module Shims Wasm 1.4.2 */
1
+ /* ES Module Shims Wasm 1.4.6 */
2
2
  (function () {
3
3
 
4
- const uaMatch = navigator.userAgent.match(/(Edge|Safari)\/\d+\.\d+/);
5
- const edge = uaMatch && uaMatch[1] === 'Edge';
6
- const safari = uaMatch && uaMatch[1] === 'Safari';
4
+ const noop = () => {};
7
5
 
8
- let baseUrl;
6
+ const optionsScript = document.querySelector('script[type=esms-options]');
9
7
 
10
- function createBlob (source, type = 'text/javascript') {
11
- return URL.createObjectURL(new Blob([source], { type }));
8
+ const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
9
+
10
+ let shimMode = !!esmsInitOptions.shimMode;
11
+ const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
12
+
13
+ const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
14
+
15
+ let nonce = esmsInitOptions.nonce;
16
+
17
+ const mapOverrides = esmsInitOptions.mapOverrides;
18
+
19
+ if (!nonce) {
20
+ const nonceElement = document.querySelector('script[nonce]');
21
+ if (nonceElement)
22
+ nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
12
23
  }
13
24
 
14
- const noop = () => {};
25
+ const onerror = globalHook(esmsInitOptions.onerror || noop);
26
+ const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: ^ TypeError module failure has been polyfilled`);
27
+
28
+ const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
29
+
30
+ const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
31
+
32
+ function globalHook (name) {
33
+ return typeof name === 'string' ? self[name] : name;
34
+ }
35
+
36
+ const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
37
+ const cssModulesEnabled = enable.includes('css-modules');
38
+ const jsonModulesEnabled = enable.includes('json-modules');
39
+
40
+ function setShimMode () {
41
+ shimMode = true;
42
+ }
43
+
44
+ const edge = !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
15
45
 
16
- const baseEl = document.querySelector('base[href]');
17
- if (baseEl)
18
- baseUrl = baseEl.href;
46
+ const baseUrl = document.baseURI;
19
47
 
20
- if (!baseUrl && typeof location !== 'undefined') {
21
- baseUrl = location.href.split('#')[0].split('?')[0];
22
- const lastSepIndex = baseUrl.lastIndexOf('/');
23
- if (lastSepIndex !== -1)
24
- baseUrl = baseUrl.slice(0, lastSepIndex + 1);
48
+ function createBlob (source, type = 'text/javascript') {
49
+ return URL.createObjectURL(new Blob([source], { type }));
25
50
  }
26
51
 
52
+ const eoop = err => setTimeout(() => { throw err });
53
+
54
+ const throwError = err => { (window.reportError || window.safari && console.error || eoop)(err), void onerror(err); };
55
+
27
56
  function isURL (url) {
28
57
  try {
29
58
  new URL(url);
30
59
  return true;
31
60
  }
32
- catch(_) {
61
+ catch (_) {
33
62
  return false;
34
63
  }
64
+ }
65
+
66
+ const backslashRegEx = /\\/g;
67
+
68
+ /*
69
+ * Import maps implementation
70
+ *
71
+ * To make lookups fast we pre-resolve the entire import map
72
+ * and then match based on backtracked hash lookups
73
+ *
74
+ */
75
+ function resolveUrl (relUrl, parentUrl) {
76
+ return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
35
77
  }
36
78
 
37
- const backslashRegEx = /\\/g;
38
79
  function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
39
80
  // strip off any trailing query params or hashes
40
81
  parentUrl = parentUrl && parentUrl.split('#')[0].split('?')[0];
@@ -87,28 +128,25 @@
87
128
  output.push(segmented.slice(segmentIndex, i + 1));
88
129
  segmentIndex = -1;
89
130
  }
131
+ continue;
90
132
  }
91
-
92
133
  // new segment - check if it is relative
93
134
  else if (segmented[i] === '.') {
94
135
  // ../ segment
95
136
  if (segmented[i + 1] === '.' && (segmented[i + 2] === '/' || i + 2 === segmented.length)) {
96
137
  output.pop();
97
138
  i += 2;
139
+ continue;
98
140
  }
99
141
  // ./ segment
100
142
  else if (segmented[i + 1] === '/' || i + 1 === segmented.length) {
101
143
  i += 1;
102
- }
103
- else {
104
- // the start of a new segment as below
105
- segmentIndex = i;
144
+ continue;
106
145
  }
107
146
  }
108
147
  // it is the start of a new segment
109
- else {
110
- segmentIndex = i;
111
- }
148
+ while (segmented[i] === '/') i++;
149
+ segmentIndex = i;
112
150
  }
113
151
  // finish reading out the last segment
114
152
  if (segmentIndex !== -1)
@@ -117,35 +155,6 @@
117
155
  }
118
156
  }
119
157
 
120
- /*
121
- * Import maps implementation
122
- *
123
- * To make lookups fast we pre-resolve the entire import map
124
- * and then match based on backtracked hash lookups
125
- *
126
- */
127
- function resolveUrl (relUrl, parentUrl) {
128
- return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (relUrl.indexOf(':') !== -1 ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
129
- }
130
-
131
- function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
132
- for (let p in packages) {
133
- const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
134
- if (outPackages[resolvedLhs]) {
135
- throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
136
- }
137
- let target = packages[p];
138
- if (typeof target !== 'string')
139
- continue;
140
- const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
141
- if (mapped) {
142
- outPackages[resolvedLhs] = mapped;
143
- continue;
144
- }
145
- console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
146
- }
147
- }
148
-
149
158
  function resolveAndComposeImportMap (json, baseUrl, parentMap) {
150
159
  const outMap = { imports: Object.assign({}, parentMap.imports), scopes: Object.assign({}, parentMap.scopes) };
151
160
 
@@ -181,6 +190,7 @@
181
190
  }
182
191
  }
183
192
 
193
+
184
194
  function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
185
195
  let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
186
196
  while (scopeUrl) {
@@ -190,42 +200,24 @@
190
200
  scopeUrl = getMatch(scopeUrl.slice(0, scopeUrl.lastIndexOf('/')), importMap.scopes);
191
201
  }
192
202
  return applyPackages(resolvedOrPlain, importMap.imports) || resolvedOrPlain.indexOf(':') !== -1 && resolvedOrPlain;
193
- }
194
-
195
- const optionsScript = document.querySelector('script[type=esms-options]');
196
-
197
- const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : self.esmsInitOptions ? self.esmsInitOptions : {};
198
-
199
- let shimMode = !!esmsInitOptions.shimMode;
200
- const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
201
-
202
- const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
203
-
204
- let nonce = esmsInitOptions.nonce;
205
-
206
- if (!nonce) {
207
- const nonceElement = document.querySelector('script[nonce]');
208
- if (nonceElement)
209
- nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
210
- }
211
-
212
- const onerror = globalHook(esmsInitOptions.onerror || noop);
213
- const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`);
214
-
215
- const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions;
216
-
217
- const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
218
-
219
- function globalHook (name) {
220
- return typeof name === 'string' ? self[name] : name;
221
203
  }
222
204
 
223
- const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
224
- const cssModulesEnabled = enable.includes('css-modules');
225
- const jsonModulesEnabled = enable.includes('json-modules');
226
-
227
- function setShimMode () {
228
- shimMode = true;
205
+ function resolveAndComposePackages (packages, outPackages, baseUrl, parentMap) {
206
+ for (let p in packages) {
207
+ const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
208
+ if ((!shimMode || !mapOverrides) && outPackages[resolvedLhs] && (outPackages[resolvedLhs] !== packages[resolvedLhs])) {
209
+ throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`);
210
+ }
211
+ let target = packages[p];
212
+ if (typeof target !== 'string')
213
+ continue;
214
+ const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
215
+ if (mapped) {
216
+ outPackages[resolvedLhs] = mapped;
217
+ continue;
218
+ }
219
+ console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`);
220
+ }
229
221
  }
230
222
 
231
223
  let supportsDynamicImportCheck = false;
@@ -313,7 +305,6 @@
313
305
 
314
306
  const resolve = resolveHook ? async (id, parentUrl) => ({ r: await resolveHook(id, parentUrl, defaultResolve), b: false }) : _resolve;
315
307
 
316
- let id = 0;
317
308
  const registry = {};
318
309
 
319
310
  async function loadAll (load, seen) {
@@ -388,7 +379,7 @@
388
379
  await lastStaticLoadPromise;
389
380
  return dynamicImport(source ? createBlob(source) : url, { errUrl: url || source });
390
381
  }
391
- const load = getOrCreateLoad(url, fetchOpts, source);
382
+ const load = getOrCreateLoad(url, fetchOpts, null, source);
392
383
  const seen = {};
393
384
  await loadAll(load, seen);
394
385
  lastLoad = undefined;
@@ -430,7 +421,12 @@
430
421
  }
431
422
  }
432
423
 
433
- async function importShim (id, parentUrl = baseUrl, _assertion) {
424
+ async function importShim (id, ...args) {
425
+ // parentUrl if present will be the last argument
426
+ let parentUrl = args[args.length - 1];
427
+ if (typeof parentUrl !== 'string') {
428
+ parentUrl = baseUrl;
429
+ }
434
430
  // needed for shim check
435
431
  await initPromise;
436
432
  if (acceptingImportMaps || shimMode || !baselinePassthrough) {
@@ -484,7 +480,7 @@
484
480
  // once all deps have loaded we can inline the dependency resolution blobs
485
481
  // and define this blob
486
482
  let lastIndex = 0, depIndex = 0;
487
- for (const { s: start, se: end, d: dynamicImportIndex } of imports) {
483
+ for (const { s: start, e: end, se: statementEnd, d: dynamicImportIndex } of imports) {
488
484
  // dependency source replacements
489
485
  if (dynamicImportIndex === -1) {
490
486
  const depLoad = load.d[depIndex++];
@@ -505,24 +501,24 @@
505
501
  }
506
502
  // circular shell execution
507
503
  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;
504
+ 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})`;
505
+ lastIndex = statementEnd;
510
506
  depLoad.s = undefined;
511
507
  continue;
512
508
  }
513
- resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, end)}*/${urlJsString(blobUrl)}`;
514
- lastIndex = end;
509
+ resolvedSource += `${source.slice(lastIndex, start - 1)}/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
510
+ lastIndex = statementEnd;
515
511
  }
516
512
  // import.meta
517
513
  else if (dynamicImportIndex === -2) {
518
514
  meta[load.r] = { url: load.r, resolve: importMetaResolve };
519
515
  resolvedSource += `${source.slice(lastIndex, start)}self._esmsm[${urlJsString(load.r)}]`;
520
- lastIndex = end;
516
+ lastIndex = statementEnd;
521
517
  }
522
518
  // dynamic import
523
519
  else {
524
- resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, end)}, ${load.r && urlJsString(load.r)}`;
525
- lastIndex = end;
520
+ resolvedSource += `${source.slice(lastIndex, dynamicImportIndex + 6)}Shim(${source.slice(start, statementEnd)}, ${urlJsString(load.r)}`;
521
+ lastIndex = statementEnd;
526
522
  }
527
523
  }
528
524
 
@@ -561,42 +557,56 @@
561
557
  p.shift()();
562
558
  }
563
559
 
564
- async function doFetch (url, fetchOpts) {
560
+ function fromParent (parent) {
561
+ return parent ? ` imported from ${parent}` : '';
562
+ }
563
+
564
+ async function doFetch (url, fetchOpts, parent) {
565
565
  if (enforceIntegrity && !fetchOpts.integrity)
566
- throw Error(`No integrity for ${url}`);
566
+ throw Error(`No integrity for ${url}${fromParent(parent)}.`);
567
567
  const poolQueue = pushFetchPool();
568
568
  if (poolQueue) await poolQueue;
569
569
  try {
570
570
  var res = await fetchHook(url, fetchOpts);
571
571
  }
572
+ catch (e) {
573
+ e.message = `Unable to fetch ${url}${fromParent(parent)} - see network log for details.\n` + e.message;
574
+ throw e;
575
+ }
572
576
  finally {
573
577
  popFetchPool();
574
578
  }
575
579
  if (!res.ok)
576
- throw Error(`${res.status} ${res.statusText} ${res.url}`);
580
+ throw Error(`${res.status} ${res.statusText} ${res.url}${fromParent(parent)}`);
581
+ return res;
582
+ }
583
+
584
+ async function fetchModule (url, fetchOpts, parent) {
585
+ const res = await doFetch(url, fetchOpts, parent);
577
586
  const contentType = res.headers.get('content-type');
578
587
  if (jsContentType.test(contentType))
579
588
  return { r: res.url, s: await res.text(), t: 'js' };
580
589
  else if (jsonContentType.test(contentType))
581
590
  return { r: res.url, s: `export default ${await res.text()}`, t: 'json' };
582
- else if (cssContentType.test(contentType))
591
+ else if (cssContentType.test(contentType)) {
583
592
  return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
584
- JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
593
+ JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes = '', relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
585
594
  });export default s;`, t: 'css' };
595
+ }
586
596
  else
587
- throw Error(`Unsupported Content-Type "${contentType}"`);
597
+ throw Error(`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`);
588
598
  }
589
599
 
590
- function getOrCreateLoad (url, fetchOpts, source) {
600
+ function getOrCreateLoad (url, fetchOpts, parent, source) {
591
601
  let load = registry[url];
592
- if (load)
602
+ if (load && !source)
593
603
  return load;
594
604
 
595
- load = registry[url] = {
605
+ load = {
596
606
  // url
597
607
  u: url,
598
608
  // response url
599
- r: undefined,
609
+ r: source ? url : undefined,
600
610
  // fetchPromise
601
611
  f: undefined,
602
612
  // source
@@ -616,12 +626,18 @@
616
626
  // type
617
627
  t: null
618
628
  };
629
+ if (registry[url]) {
630
+ let i = 0;
631
+ while (registry[load.u + ++i]);
632
+ load.u += i;
633
+ }
634
+ registry[load.u] = load;
619
635
 
620
636
  load.f = (async () => {
621
637
  if (!source) {
622
638
  // preload fetch options override fetch options (race)
623
639
  let t;
624
- ({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
640
+ ({ r: load.r, s: source, t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
625
641
  if (t && !shimMode) {
626
642
  if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
627
643
  throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`);
@@ -655,7 +671,7 @@
655
671
  if (skip && skip.test(r)) return { b: r };
656
672
  if (childFetchOpts.integrity)
657
673
  childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
658
- return getOrCreateLoad(r, childFetchOpts).f;
674
+ return getOrCreateLoad(r, childFetchOpts, load.r).f;
659
675
  }))).filter(l => l);
660
676
  });
661
677
 
@@ -738,9 +754,9 @@
738
754
  if (acceptingImportMaps) {
739
755
  importMapPromise = importMapPromise
740
756
  .then(async () => {
741
- importMap = resolveAndComposeImportMap(script.src ? await (await fetchHook(script.src)).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
757
+ importMap = resolveAndComposeImportMap(script.src ? await (await doFetch(script.src, getFetchOpts(script))).json() : JSON.parse(script.innerHTML), script.src || baseUrl, importMap);
742
758
  })
743
- .catch(error => setTimeout(() => { throw error }));
759
+ .catch(throwError);
744
760
  if (!shimMode)
745
761
  acceptingImportMaps = false;
746
762
  }
@@ -762,15 +778,7 @@
762
778
  if (isReadyScript) readyStateCompleteCnt++;
763
779
  if (isDomContentLoadedScript) domContentLoadedCnt++;
764
780
  const blocks = script.getAttribute('async') === null && isReadyScript;
765
- const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
766
- // Safari only gives error via console.error
767
- if (safari)
768
- console.error(e);
769
- // Firefox only gives error stack via setTimeout
770
- else
771
- setTimeout(() => { throw e});
772
- onerror(e);
773
- });
781
+ const loadPromise = topLevelLoad(script.src || baseUrl, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(throwError);
774
782
  if (blocks)
775
783
  lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
776
784
  if (isDomContentLoadedScript)
@@ -784,11 +792,11 @@
784
792
  link.ep = true;
785
793
  if (fetchCache[link.href])
786
794
  return;
787
- fetchCache[link.href] = doFetch(link.href, getFetchOpts(link));
795
+ fetchCache[link.href] = fetchModule(link.href, getFetchOpts(link));
788
796
  }
789
797
 
790
798
  function throwUnresolved (id, parentUrl) {
791
- throw Error("Unable to resolve specifier '" + id + (parentUrl ? "' from " + parentUrl : "'"));
799
+ throw Error(`Unable to resolve specifier '${id}'${fromParent(parentUrl)}`);
792
800
  }
793
801
 
794
802
  })();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "1.4.2",
3
+ "version": "1.4.6",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {
@@ -14,7 +14,7 @@
14
14
  "footprint": "npm run build ; cat dist/es-module-shims.js | terser -mc | brotli | wc -c",
15
15
  "footprint:wasm": "npm run build ; cat dist/es-module-shims.wasm.js | terser -mc | brotli | wc -c",
16
16
  "prepublishOnly": "npm run build",
17
- "test": "npm run test:test-base-href ; npm run test:test-csp ; npm run test:test-dom-order ; npm run test:test-early-module-load ; npm run test:test-polyfill ; npm run test:test-polyfill-wasm ; npm run test:test-preload-case ; npm run test:test-revoke-blob-urls ; npm run test:test-shim",
17
+ "test": "npm run test:test-base-href ; npm run test:test-csp ; npm run test:test-dom-order ; npm run test:test-early-module-load ; npm run test:test-polyfill ; npm run test:test-polyfill-wasm ; npm run test:test-preload-case ; npm run test:test-revoke-blob-urls ; npm run test:test-shim ; npm run test:test-shim-map-overrides",
18
18
  "test:test-base-href": "cross-env TEST_NAME=test-base-href node test/server.mjs",
19
19
  "test:test-csp": "cross-env TEST_NAME=test-csp node test/server.mjs",
20
20
  "test:test-dom-order": "cross-env TEST_NAME=test-dom-order node test/server.mjs",
@@ -23,7 +23,8 @@
23
23
  "test:test-polyfill-wasm": "cross-env TEST_NAME=test-polyfill-wasm node test/server.mjs",
24
24
  "test:test-preload-case": "cross-env TEST_NAME=test-preload-case node test/server.mjs",
25
25
  "test:test-revoke-blob-urls": "cross-env TEST_NAME=test-revoke-blob-urls node test/server.mjs",
26
- "test:test-shim": "cross-env TEST_NAME=test-shim node test/server.mjs"
26
+ "test:test-shim": "cross-env TEST_NAME=test-shim node test/server.mjs",
27
+ "test:test-shim-map-overrides": "cross-env TEST_NAME=test-shim-map-overrides node test/server.mjs"
27
28
  },
28
29
  "types": "index.d.ts",
29
30
  "type": "module",
@@ -49,7 +50,8 @@
49
50
  "rimraf": "^3.0.2",
50
51
  "rollup": "^2.58.0",
51
52
  "speed-limiter": "^1.0.2",
52
- "tachometer": "^0.5.10"
53
+ "tachometer": "^0.5.10",
54
+ "terser": "^5.10.0"
53
55
  },
54
56
  "directories": {
55
57
  "test": "test"