es-module-shims 2.6.0 → 2.6.2

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
@@ -14,6 +14,7 @@ The following modules features are polyfilled:
14
14
  * [Import defer](#import-defer) via syntax stripping to allow usage in modern browsers with a polyfill fallback, when enabled.
15
15
  * [TypeScript](#typescript-type-stripping) type stripping.
16
16
  * [Hot Reloading](#hot-reloading) with a Vite-style `import.meta.hot` API.
17
+ * [Loader Hooks](#hooks) custom loader hooks for customizing module resolution and sources, including support for [virtual module sources](#source-hook).
17
18
 
18
19
  When running in shim mode, module rewriting is applied for all users and custom [resolve](#resolve-hook) and [fetch](#fetch-hook) hooks can be implemented allowing for custom resolution and streaming in-browser transform workflows.
19
20
 
@@ -30,7 +31,7 @@ Because we are still using the native module loader the edge cases work out comp
30
31
  Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
31
32
 
32
33
  ```html
33
- <script async src="https://ga.jspm.io/npm:es-module-shims@2.6.0/dist/es-module-shims.js"></script>
34
+ <script async src="https://ga.jspm.io/npm:es-module-shims@2.6.2/dist/es-module-shims.js"></script>
34
35
 
35
36
  <!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
36
37
  <script type="importmap">
@@ -215,7 +216,7 @@ Shim mode is an alternative to polyfill mode and doesn't rely on native modules
215
216
 
216
217
  In shim mode, only the above `importmap-shim` and `module-shim` tags will be parsed and executed by ES Module Shims.
217
218
 
218
- Shim mode also provides some additional features that aren't yet natively supported such as supporting multiple import maps, [external import maps](#external-import-maps) with a `"src"` attribute, [dynamically injecting import maps](#dynamic-import-maps), and [reading current import map state](#reading-current-import-map-state), which can be useful in certain applications.
219
+ Shim mode also provides some additional features that aren't yet natively supported such as [external import maps](#external-import-maps) with a `"src"` attribute and [reading current import map state](#reading-current-import-map-state), which can be useful in certain applications.
219
220
 
220
221
  ## Benchmarks
221
222
 
@@ -231,7 +232,7 @@ Benchmark summary:
231
232
 
232
233
  ### Browser Support
233
234
 
234
- Works in all browsers with [baseline ES module support](https://caniuse.com/#feat=es6-module).
235
+ Works in all browsers with [ES module dynamic import support](https://caniuse.com/es6-module-dynamic-import).
235
236
 
236
237
  Browser Compatibility on baseline ES modules support **with** ES Module Shims:
237
238
 
@@ -252,8 +253,8 @@ Browser compatibility **without** ES Module Shims:
252
253
  | --------------------------------------------- | ------------------ | ------------------ | ------------------ |
253
254
  | [modulepreload](#modulepreload) | 66+ | 115+ | 17.5+ |
254
255
  | [Import Maps](#import-maps) | 89+ | 108+ | 16.4+ |
255
- | [Import Map Integrity](#import-map-integrity) | 127+ | :x: | :x: |
256
- | [Multiple Import Maps](#multiple-import-maps) | 135+ | :x: | :x: |
256
+ | [Import Map Integrity](#import-map-integrity) | 127+ | 138+ | 18+ |
257
+ | [Multiple Import Maps](#multiple-import-maps) | 135+ | :x: | 18.4+ |
257
258
  | [JSON Modules](#json-modules) | 123+ | :x: | 17.2+ |
258
259
  | [CSS Modules](#css-modules) | 123+ | :x: | :x: |
259
260
  | [Wasm Modules](#wasm-modules) | Pending | :x: | :x: |
@@ -1,169 +1,177 @@
1
- /** ES Module Shims @version 2.6.0 */
1
+ /** ES Module Shims @version 2.6.2 */
2
2
  (function () {
3
3
 
4
- let invalidate;
5
- const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
6
- const initHotReload = () => {
7
- let _importHook = importHook,
8
- _resolveHook = resolveHook,
9
- _metaHook = metaHook;
10
-
11
- let defaultResolve;
12
- let hotResolveHook = (id, parent, _defaultResolve) => {
13
- if (!defaultResolve) defaultResolve = _defaultResolve;
14
- const originalParent = stripVersion(parent);
15
- const url = stripVersion(defaultResolve(id, originalParent));
16
- const hotState = getHotState(url);
17
- const parents = hotState.p;
18
- if (!parents.includes(originalParent)) parents.push(originalParent);
19
- return toVersioned(url, hotState);
20
- };
21
- const hotImportHook = (url, _, __, source, sourceType) => {
22
- const hotState = getHotState(url);
23
- hotState.e = typeof source === 'string' ? source : true;
24
- hotState.t = sourceType;
25
- };
26
- const hotMetaHook = (metaObj, url) => (metaObj.hot = new Hot(url));
27
-
28
- const Hot = class Hot {
29
- constructor(url) {
30
- this.data = getHotState((this.url = stripVersion(url))).d;
31
- }
32
- accept(deps, cb) {
33
- if (typeof deps === 'function') {
34
- cb = deps;
35
- deps = null;
36
- }
37
- const hotState = getHotState(this.url);
38
- if (!hotState.A) return;
39
- (hotState.a = hotState.a || []).push([
40
- typeof deps === 'string' ? defaultResolve(deps, this.url)
41
- : deps ? deps.map(d => defaultResolve(d, this.url))
42
- : null,
43
- cb
44
- ]);
45
- }
46
- dispose(cb) {
47
- getHotState(this.url).u = cb;
48
- }
49
- invalidate() {
50
- const hotState = getHotState(this.url);
51
- hotState.a = hotState.A = null;
52
- const seen = [this.url];
53
- hotState.p.forEach(p => invalidate(p, this.url, seen));
54
- }
55
- };
56
-
57
- const versionedRegEx = /\?v=\d+$/;
58
- const stripVersion = url => {
59
- const versionMatch = url.match(versionedRegEx);
60
- return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
61
- };
62
-
63
- const toVersioned = (url, hotState) => {
64
- const { v } = hotState;
65
- return url + (v ? '?v=' + v : '');
66
- };
67
-
68
- let hotRegistry = {},
69
- curInvalidationRoots = new Set(),
70
- curInvalidationInterval;
71
- const getHotState = url =>
72
- hotRegistry[url] ||
73
- (hotRegistry[url] = {
74
- // version
75
- v: 0,
76
- // accept list ([deps, cb] pairs)
77
- a: null,
78
- // accepting acceptors
79
- A: true,
80
- // unload callback
81
- u: null,
82
- // entry point or inline script source
83
- e: false,
84
- // hot data
85
- d: {},
86
- // parents
87
- p: [],
88
- // source type
89
- t: undefined
90
- });
91
-
92
- invalidate = (url, fromUrl, seen = []) => {
93
- const hotState = hotRegistry[url];
94
- if (!hotState || seen.includes(url)) return false;
95
- seen.push(url);
96
- console.info(`es-module-shims: hot reload ${url}`);
97
- hotState.A = false;
98
- if (
99
- fromUrl &&
100
- hotState.a &&
101
- hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
102
- ) {
103
- curInvalidationRoots.add(fromUrl);
104
- } else {
105
- if (hotState.e || hotState.a) curInvalidationRoots.add(url);
106
- hotState.v++;
107
- if (!hotState.a) hotState.p.forEach(p => invalidate(p, url, seen));
108
- }
109
- if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
110
- return true;
111
- };
112
-
113
- const handleInvalidations = () => {
114
- curInvalidationInterval = null;
115
- const earlyRoots = new Set();
116
- for (const root of curInvalidationRoots) {
117
- const hotState = hotRegistry[root];
118
- topLevelLoad(
119
- toVersioned(root, hotState),
120
- baseUrl,
121
- defaultFetchOpts,
122
- typeof hotState.e === 'string' ? hotState.e : undefined,
123
- false,
124
- undefined,
125
- hotState.t
126
- ).then(m => {
127
- if (hotState.a) {
128
- hotState.a.forEach(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
129
- // unload should be the latest unload handler from the just loaded module
130
- if (hotState.u) {
131
- hotState.u(hotState.d);
132
- hotState.u = null;
133
- }
134
- }
135
- hotState.p.forEach(p => {
136
- const hotState = hotRegistry[p];
137
- if (hotState && hotState.a)
138
- hotState.a.forEach(
139
- async ([d, c]) =>
140
- d &&
141
- !earlyRoots.has(c) &&
142
- (typeof d === 'string' ?
143
- d === root && c(m)
144
- : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
145
- );
146
- });
147
- }, throwError);
148
- }
149
- curInvalidationRoots = new Set();
150
- };
151
-
152
- return [
153
- _importHook ? chain(_importHook, hotImportHook) : hotImportHook,
154
- _resolveHook ?
155
- (id, parent, defaultResolve) =>
156
- hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
157
- : hotResolveHook,
158
- _metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
159
- ];
4
+ const self_ = typeof globalThis !== 'undefined' ? globalThis : self;
5
+
6
+ let invalidate;
7
+ const hotReload$1 = url => invalidate(new URL(url, baseUrl).href);
8
+ const initHotReload = (topLevelLoad, importShim) => {
9
+ let _importHook = importHook,
10
+ _resolveHook = resolveHook,
11
+ _metaHook = metaHook;
12
+
13
+ let defaultResolve;
14
+ let hotResolveHook = (id, parent, _defaultResolve) => {
15
+ if (!defaultResolve) defaultResolve = _defaultResolve;
16
+ const originalParent = stripVersion(parent);
17
+ const url = stripVersion(defaultResolve(id, originalParent));
18
+ const hotState = getHotState(url);
19
+ const parents = hotState.p;
20
+ if (!parents.includes(originalParent)) parents.push(originalParent);
21
+ return toVersioned(url, hotState);
22
+ };
23
+ const hotImportHook = (url, _, __, source, sourceType) => {
24
+ const hotState = getHotState(url);
25
+ hotState.e = typeof source === 'string' ? source : true;
26
+ hotState.t = sourceType;
27
+ };
28
+ const hotMetaHook = (metaObj, url) => (metaObj.hot = new Hot(url));
29
+
30
+ const Hot = class Hot {
31
+ constructor(url) {
32
+ this.data = getHotState((this.url = stripVersion(url))).d;
33
+ }
34
+ accept(deps, cb) {
35
+ if (typeof deps === 'function') {
36
+ cb = deps;
37
+ deps = null;
38
+ }
39
+ const hotState = getHotState(this.url);
40
+ if (!hotState.A) return;
41
+ (hotState.a = hotState.a || []).push([
42
+ typeof deps === 'string' ? defaultResolve(deps, this.url)
43
+ : deps ? deps.map(d => defaultResolve(d, this.url))
44
+ : null,
45
+ cb
46
+ ]);
47
+ }
48
+ dispose(cb) {
49
+ getHotState(this.url).u = cb;
50
+ }
51
+ invalidate() {
52
+ const hotState = getHotState(this.url);
53
+ hotState.a = hotState.A = null;
54
+ const seen = [this.url];
55
+ hotState.p.forEach(p => invalidate(p, this.url, seen));
56
+ }
57
+ };
58
+
59
+ const versionedRegEx = /\?v=\d+$/;
60
+ const stripVersion = url => {
61
+ const versionMatch = url.match(versionedRegEx);
62
+ return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
63
+ };
64
+
65
+ const toVersioned = (url, hotState) => {
66
+ const { v } = hotState;
67
+ return url + (v ? '?v=' + v : '');
68
+ };
69
+
70
+ let hotRegistry = {},
71
+ curInvalidationRoots = new Set(),
72
+ curInvalidationInterval;
73
+ const getHotState = url =>
74
+ hotRegistry[url] ||
75
+ (hotRegistry[url] = {
76
+ // version
77
+ v: 0,
78
+ // accept list ([deps, cb] pairs)
79
+ a: null,
80
+ // accepting acceptors
81
+ A: true,
82
+ // unload callback
83
+ u: null,
84
+ // entry point or inline script source
85
+ e: false,
86
+ // hot data
87
+ d: {},
88
+ // parents
89
+ p: [],
90
+ // source type
91
+ t: undefined
92
+ });
93
+
94
+ invalidate = (url, fromUrl, seen = []) => {
95
+ const hotState = hotRegistry[url];
96
+ if (!hotState || seen.includes(url)) return false;
97
+ seen.push(url);
98
+ console.info(`es-module-shims: hot reload ${url}`);
99
+ hotState.A = false;
100
+ if (
101
+ fromUrl &&
102
+ hotState.a &&
103
+ hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
104
+ ) {
105
+ curInvalidationRoots.add(fromUrl);
106
+ } else {
107
+ if (hotState.e || hotState.a) curInvalidationRoots.add(url);
108
+ hotState.v++;
109
+ if (!hotState.a) hotState.p.forEach(p => invalidate(p, url, seen));
110
+ }
111
+ if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
112
+ return true;
113
+ };
114
+
115
+ const handleInvalidations = () => {
116
+ curInvalidationInterval = null;
117
+ const earlyRoots = new Set();
118
+ for (const root of curInvalidationRoots) {
119
+ const hotState = hotRegistry[root];
120
+ topLevelLoad(
121
+ toVersioned(root, hotState),
122
+ baseUrl,
123
+ defaultFetchOpts,
124
+ typeof hotState.e === 'string' ? hotState.e : undefined,
125
+ false,
126
+ undefined,
127
+ hotState.t
128
+ ).then(m => {
129
+ if (hotState.a) {
130
+ hotState.a.forEach(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
131
+ // unload should be the latest unload handler from the just loaded module
132
+ if (hotState.u) {
133
+ hotState.u(hotState.d);
134
+ hotState.u = null;
135
+ }
136
+ }
137
+ hotState.p.forEach(p => {
138
+ const hotState = hotRegistry[p];
139
+ if (hotState && hotState.a)
140
+ hotState.a.forEach(
141
+ async ([d, c]) =>
142
+ d &&
143
+ !earlyRoots.has(c) &&
144
+ (typeof d === 'string' ?
145
+ d === root && c(m)
146
+ : c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
147
+ );
148
+ });
149
+ }, throwError);
150
+ }
151
+ curInvalidationRoots = new Set();
152
+ };
153
+
154
+ setHooks(
155
+ _importHook ? chain(_importHook, hotImportHook) : hotImportHook,
156
+ _resolveHook ?
157
+ (id, parent, defaultResolve) =>
158
+ hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
159
+ : hotResolveHook,
160
+ _metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
161
+ );
160
162
  };
161
163
 
162
164
  const hasDocument = typeof document !== 'undefined';
163
165
 
164
166
  const noop = () => {};
165
167
 
166
- const dynamicImport = (u, errUrl) => import(u);
168
+ const chain = (a, b) =>
169
+ function () {
170
+ a.apply(this, arguments);
171
+ b.apply(this, arguments);
172
+ };
173
+
174
+ const dynamicImport = (u, _errUrl) => import(u);
167
175
 
168
176
  const defineValue = (obj, prop, value) =>
169
177
  Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
@@ -171,12 +179,12 @@
171
179
  const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
172
180
 
173
181
  const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
174
- Object.assign(esmsInitOptions, self.esmsInitOptions || {});
182
+ Object.assign(esmsInitOptions, self_.esmsInitOptions || {});
175
183
 
176
- const version = "2.6.0";
184
+ const version = "2.6.2";
177
185
 
178
186
  const r$1 = esmsInitOptions.version;
179
- if (self.importShim || (r$1 && r$1 !== version)) {
187
+ if (self_.importShim || (r$1 && r$1 !== version)) {
180
188
  console.info(
181
189
  `es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
182
190
  );
@@ -186,9 +194,11 @@
186
194
  // shim mode is determined on initialization, no late shim mode
187
195
  const shimMode =
188
196
  esmsInitOptions.shimMode ||
189
- (hasDocument &&
197
+ (hasDocument ?
190
198
  document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
191
- .length > 0);
199
+ .length > 0
200
+ // Without a document, shim mode is always true as we cannot polyfill
201
+ : true);
192
202
 
193
203
  let importHook,
194
204
  resolveHook,
@@ -202,7 +212,7 @@
202
212
 
203
213
  const defaultFetchOpts = { credentials: 'same-origin' };
204
214
 
205
- const globalHook = name => (typeof name === 'string' ? self[name] : name);
215
+ const globalHook = name => (typeof name === 'string' ? self_[name] : name);
206
216
 
207
217
  if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
208
218
  if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
@@ -220,7 +230,11 @@
220
230
  nativePassthrough = !hasCustomizationHooks && !hotReload
221
231
  } = esmsInitOptions;
222
232
 
223
- if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
233
+ const setHooks = (importHook_, resolveHook_, metaHook_) => (
234
+ (importHook = importHook_),
235
+ (resolveHook = resolveHook_),
236
+ (metaHook = metaHook_)
237
+ );
224
238
 
225
239
  const mapOverrides = esmsInitOptions.mapOverrides;
226
240
 
@@ -252,13 +266,14 @@
252
266
  };
253
267
 
254
268
  const baseUrl =
255
- hasDocument ?
256
- document.baseURI
257
- : `${location.protocol}//${location.host}${
269
+ hasDocument ? document.baseURI
270
+ : typeof location !== 'undefined' ?
271
+ `${location.protocol}//${location.host}${
258
272
  location.pathname.includes('/') ?
259
273
  location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
260
274
  : location.pathname
261
- }`;
275
+ }`
276
+ : 'about:blank';
262
277
 
263
278
  const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
264
279
  let { skip } = esmsInitOptions;
@@ -272,10 +287,11 @@
272
287
  skip = s => skip.test(s);
273
288
  }
274
289
 
275
- const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
290
+ const dispatchError = error => self_.dispatchEvent(Object.assign(new Event('error'), { error }));
276
291
 
277
292
  const throwError = err => {
278
- (self.reportError || dispatchError)(err), void onerror(err);
293
+ (self_.reportError || dispatchError)(err);
294
+ onerror(err);
279
295
  };
280
296
 
281
297
  const fromParent = parent => (parent ? ` imported from ${parent}` : '');
@@ -629,7 +645,7 @@
629
645
  };
630
646
 
631
647
  // import()
632
- async function importShim$1(id, opts, parentUrl) {
648
+ async function importShim(id, opts, parentUrl) {
633
649
  if (typeof opts === 'string') {
634
650
  parentUrl = opts;
635
651
  opts = undefined;
@@ -653,7 +669,7 @@
653
669
  // import.source()
654
670
  // (opts not currently supported as no use cases yet)
655
671
  if (shimMode || wasmSourcePhaseEnabled)
656
- importShim$1.source = async (id, opts, parentUrl) => {
672
+ importShim.source = async (id, opts, parentUrl) => {
657
673
  if (typeof opts === 'string') {
658
674
  parentUrl = opts;
659
675
  opts = undefined;
@@ -667,18 +683,17 @@
667
683
  await importMapPromise;
668
684
  const url = resolve(id, parentUrl || baseUrl).r;
669
685
  const load = getOrCreateLoad(url, defaultFetchOpts, undefined, undefined);
670
- if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
671
- onpolyfill();
672
- firstPolyfillLoad = false;
673
- }
674
686
  await load.f;
675
- return importShim$1._s[load.r];
687
+ return importShim._s[load.r];
676
688
  };
677
689
 
678
690
  // import.defer() is just a proxy for import(), since we can't actually defer
679
- if (shimMode || deferPhaseEnabled) importShim$1.defer = importShim$1;
691
+ if (shimMode || deferPhaseEnabled) importShim.defer = importShim;
680
692
 
681
- if (hotReload) importShim$1.hotReload = hotReload$1;
693
+ if (hotReload) {
694
+ initHotReload(topLevelLoad, importShim);
695
+ importShim.hotReload = hotReload$1;
696
+ }
682
697
 
683
698
  const defaultResolve = (id, parentUrl) => {
684
699
  return (
@@ -695,24 +710,24 @@
695
710
  return resolve(id, `${parentUrl}`).r;
696
711
  };
697
712
 
698
- importShim$1.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
699
- importShim$1.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
700
- importShim$1.addImportMap = importMapIn => {
713
+ importShim.resolve = (id, parentUrl) => resolve(id, parentUrl).r;
714
+ importShim.getImportMap = () => JSON.parse(JSON.stringify(composedImportMap));
715
+ importShim.addImportMap = importMapIn => {
701
716
  if (!shimMode) throw new Error('Unsupported in polyfill mode.');
702
717
  composedImportMap = resolveAndComposeImportMap(importMapIn, baseUrl, composedImportMap);
703
718
  };
704
- importShim$1.version = version;
719
+ importShim.version = version;
705
720
 
706
- const registry = (importShim$1._r = {});
721
+ const registry = (importShim._r = {});
707
722
  // Wasm caches
708
- const sourceCache = (importShim$1._s = {});
709
- (importShim$1._i = new WeakMap());
723
+ const sourceCache = (importShim._s = {});
724
+ /* const instanceCache = */ importShim._i = new WeakMap();
710
725
 
711
726
  // Ensure this version is the only version
712
- defineValue(self, 'importShim', Object.freeze(importShim$1));
727
+ defineValue(self_, 'importShim', Object.freeze(importShim));
713
728
  const shimModeOptions = { ...esmsInitOptions, shimMode: true };
714
729
  if (optionsScript) optionsScript.innerHTML = JSON.stringify(shimModeOptions);
715
- self.esmsInitOptions = shimModeOptions;
730
+ self_.esmsInitOptions = shimModeOptions;
716
731
 
717
732
  const loadAll = async (load, seen) => {
718
733
  seen[load.u] = 1;
@@ -815,7 +830,7 @@
815
830
  let firstPolyfillLoad = true;
816
831
  let legacyAcceptingImportMaps = true;
817
832
 
818
- const topLevelLoad = async (
833
+ async function topLevelLoad(
819
834
  url,
820
835
  parentUrl,
821
836
  fetchOpts,
@@ -823,7 +838,7 @@
823
838
  nativelyLoaded,
824
839
  lastStaticLoadPromise,
825
840
  sourceType
826
- ) => {
841
+ ) {
827
842
  await initPromise;
828
843
  await importMapPromise;
829
844
  url = (await resolve(url, parentUrl)).r;
@@ -873,11 +888,11 @@
873
888
  if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
874
889
  revokeObjectURLs(Object.keys(seen));
875
890
  return module;
876
- };
891
+ }
877
892
 
878
893
  const revokeObjectURLs = registryKeys => {
879
894
  let curIdx = 0;
880
- const handler = self.requestIdleCallback || self.requestAnimationFrame;
895
+ const handler = self_.requestIdleCallback || self_.requestAnimationFrame || (fn => setTimeout(fn, 0));
881
896
  handler(cleanup);
882
897
  function cleanup() {
883
898
  for (const key of registryKeys.slice(curIdx, (curIdx += 100))) {
@@ -944,7 +959,8 @@
944
959
 
945
960
  // once all deps have loaded we can inline the dependency resolution blobs
946
961
  // and define this blob
947
- (resolvedSource = ''), (lastIndex = 0);
962
+ resolvedSource = '';
963
+ lastIndex = 0;
948
964
 
949
965
  for (const { s: start, e: end, ss: statementStart, se: statementEnd, d: dynamicImportIndex, t, a } of imports) {
950
966
  // source phase
@@ -1073,10 +1089,11 @@
1073
1089
 
1074
1090
  const doFetch = async (url, fetchOpts, parent) => {
1075
1091
  if (enforceIntegrity && !fetchOpts.integrity) throw Error(`No integrity for ${url}${fromParent(parent)}.`);
1076
- const poolQueue = pushFetchPool();
1092
+ let res,
1093
+ poolQueue = pushFetchPool();
1077
1094
  if (poolQueue) await poolQueue;
1078
1095
  try {
1079
- var res = await fetchHook(url, fetchOpts);
1096
+ res = await fetchHook(url, fetchOpts);
1080
1097
  } catch (e) {
1081
1098
  e.message = `Unable to fetch ${url}${fromParent(parent)} - see network log for details.\n` + e.message;
1082
1099
  throw e;
@@ -1098,24 +1115,22 @@
1098
1115
  if (!esmsTsTransform) esmsTsTransform = m.transform;
1099
1116
  };
1100
1117
 
1101
- const contentTypeRegEx = /^(text|application)\/((x-)?javascript|wasm|json|css|typescript)(;|$)/;
1102
1118
  async function defaultSourceHook(url, fetchOpts, parent) {
1103
- const res = await doFetch(url, fetchOpts, parent);
1104
- let [, , t] = (res.headers.get('content-type') || '').match(contentTypeRegEx) || [];
1105
- if (!t) {
1106
- if (url.endsWith('.ts') || url.endsWith('.mts')) t = 'ts';
1107
- else
1108
- throw Error(
1109
- `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
1110
- );
1119
+ let res = await doFetch(url, fetchOpts, parent),
1120
+ contentType,
1121
+ [, json, type, jsts] =
1122
+ (contentType = res.headers.get('content-type') || '').match(
1123
+ /^(?:[^/;]+\/(?:[^/+;]+\+)?(json)|(?:text|application)\/(?:x-)?((java|type)script|wasm|css))(?:;|$)/
1124
+ ) || [];
1125
+ if (!(type = json || (jsts ? jsts[0] + 's' : type || (/\.m?ts(\?|#|$)/.test(url) && 'ts')))) {
1126
+ throw Error(
1127
+ `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
1128
+ );
1111
1129
  }
1112
1130
  return {
1113
1131
  url: res.url,
1114
- source: t === 'wasm' ? await WebAssembly.compileStreaming(res) : await res.text(),
1115
- type:
1116
- t[0] === 'x' || (t[0] === 'j' && t[1] === 'a') ? 'js'
1117
- : t[0] === 't' ? 'ts'
1118
- : t
1132
+ source: await (type > 'v' ? WebAssembly.compileStreaming(res) : res.text()),
1133
+ type
1119
1134
  };
1120
1135
  }
1121
1136
 
@@ -1149,7 +1164,7 @@
1149
1164
  }
1150
1165
  source += `if(h)h.accept(m=>({${obj}}=m))`;
1151
1166
  } else if (type === 'json') {
1152
- source = `${hotPrefix}j=${source};export{j as default};if(h)h.accept(m=>j=m.default)`;
1167
+ source = `${hotPrefix}j=JSON.parse(${JSON.stringify(source)});export{j as default};if(h)h.accept(m=>j=m.default)`;
1153
1168
  } else if (type === 'css') {
1154
1169
  source = `${hotPrefix}s=h&&h.data.s||new CSSStyleSheet();s.replaceSync(${JSON.stringify(
1155
1170
  source.replace(
@@ -1238,7 +1253,7 @@
1238
1253
 
1239
1254
  const linkLoad = (load, fetchOpts) => {
1240
1255
  if (load.L) return;
1241
- load.L = load.f.then(async () => {
1256
+ load.L = load.f.then(() => {
1242
1257
  let childFetchOpts = fetchOpts;
1243
1258
  load.d = load.a[0]
1244
1259
  .map(({ n, d, t, a, se }) => {