es-module-shims 2.4.1 → 2.5.0
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 +1 -1
- package/dist/es-module-shims-typescript.js +4 -3
- package/dist/es-module-shims.debug.js +397 -387
- package/dist/es-module-shims.js +385 -377
- package/dist/es-module-shims.wasm.js +385 -377
- package/package.json +2 -2
|
@@ -1,285 +1,288 @@
|
|
|
1
|
-
/** ES Module Shims @version 2.
|
|
1
|
+
/** ES Module Shims @version 2.5.0 */
|
|
2
2
|
(function (exports) {
|
|
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;
|
|
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) => {
|
|
27
|
+
metaObj.hot = new Hot(url);
|
|
28
|
+
};
|
|
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 = null;
|
|
54
|
+
hotState.A = true;
|
|
55
|
+
const seen = [this.url];
|
|
56
|
+
for (const p of hotState.p) invalidate(p, this.url, seen);
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
const versionedRegEx = /\?v=\d+$/;
|
|
61
|
+
const stripVersion = url => {
|
|
62
|
+
const versionMatch = url.match(versionedRegEx);
|
|
63
|
+
return versionMatch ? url.slice(0, -versionMatch[0].length) : url;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const toVersioned = (url, hotState) => {
|
|
67
|
+
const { v } = hotState;
|
|
68
|
+
return url + (v ? '?v=' + v : '');
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
let hotRegistry = {},
|
|
72
|
+
curInvalidationRoots = new Set(),
|
|
73
|
+
curInvalidationInterval;
|
|
74
|
+
const getHotState = url =>
|
|
75
|
+
hotRegistry[url] ||
|
|
76
|
+
(hotRegistry[url] = {
|
|
77
|
+
// version
|
|
78
|
+
v: 0,
|
|
79
|
+
// accept list ([deps, cb] pairs)
|
|
80
|
+
a: null,
|
|
81
|
+
// accepting acceptors
|
|
82
|
+
A: true,
|
|
83
|
+
// unload callback
|
|
84
|
+
u: null,
|
|
85
|
+
// entry point or inline script source
|
|
86
|
+
e: false,
|
|
87
|
+
// hot data
|
|
88
|
+
d: {},
|
|
89
|
+
// parents
|
|
90
|
+
p: [],
|
|
91
|
+
// source type
|
|
92
|
+
t: undefined
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
invalidate = (url, fromUrl, seen = []) => {
|
|
96
|
+
if (!seen.includes(url)) {
|
|
97
|
+
seen.push(url);
|
|
98
|
+
console.info(`es-module-shims: hot reload ${url}`);
|
|
99
|
+
const hotState = hotRegistry[url];
|
|
100
|
+
if (hotState) {
|
|
101
|
+
hotState.A = false;
|
|
102
|
+
if (
|
|
103
|
+
fromUrl &&
|
|
104
|
+
hotState.a &&
|
|
105
|
+
hotState.a.some(([d]) => d && (typeof d === 'string' ? d === fromUrl : d.includes(fromUrl)))
|
|
106
|
+
) {
|
|
107
|
+
curInvalidationRoots.add(fromUrl);
|
|
108
|
+
} else {
|
|
109
|
+
if (hotState.e || hotState.a) curInvalidationRoots.add(url);
|
|
110
|
+
hotState.v++;
|
|
111
|
+
if (!hotState.a) for (const parent of hotState.p) invalidate(parent, url, seen);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
if (!curInvalidationInterval) curInvalidationInterval = setTimeout(handleInvalidations, hotReloadInterval);
|
|
115
|
+
}
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
const handleInvalidations = () => {
|
|
119
|
+
curInvalidationInterval = null;
|
|
120
|
+
const earlyRoots = new Set();
|
|
121
|
+
for (const root of curInvalidationRoots) {
|
|
122
|
+
const hotState = hotRegistry[root];
|
|
123
|
+
topLevelLoad(
|
|
124
|
+
toVersioned(root, hotState),
|
|
125
|
+
baseUrl,
|
|
126
|
+
defaultFetchOpts,
|
|
127
|
+
typeof hotState.e === 'string' ? hotState.e : undefined,
|
|
128
|
+
false,
|
|
129
|
+
undefined,
|
|
130
|
+
hotState.t
|
|
131
|
+
).then(m => {
|
|
132
|
+
if (hotState.a) {
|
|
133
|
+
hotState.a.every(([d, c]) => d === null && !earlyRoots.has(c) && c(m));
|
|
134
|
+
// unload should be the latest unload handler from the just loaded module
|
|
135
|
+
if (hotState.u) {
|
|
136
|
+
hotState.u(hotState.d);
|
|
137
|
+
hotState.u = null;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
for (const parent of hotState.p) {
|
|
141
|
+
const hotState = hotRegistry[parent];
|
|
142
|
+
if (hotState && hotState.a)
|
|
143
|
+
hotState.a.every(async ([d, c]) => {
|
|
144
|
+
return (
|
|
145
|
+
d &&
|
|
146
|
+
!earlyRoots.has(c) &&
|
|
147
|
+
(typeof d === 'string' ?
|
|
148
|
+
d === root && c(m)
|
|
149
|
+
: c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d, getHotState(d))))))))
|
|
150
|
+
);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}, throwError);
|
|
154
|
+
}
|
|
155
|
+
curInvalidationRoots = new Set();
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
return [
|
|
159
|
+
_importHook ? chain(_importHook, hotImportHook) : hotImportHook,
|
|
160
|
+
_resolveHook ?
|
|
161
|
+
(id, parent, defaultResolve) =>
|
|
162
|
+
hotResolveHook(id, parent, (id, parent) => _resolveHook(id, parent, defaultResolve))
|
|
163
|
+
: hotResolveHook,
|
|
164
|
+
_metaHook ? chain(_metaHook, hotMetaHook) : hotMetaHook
|
|
165
|
+
];
|
|
166
|
+
};
|
|
10
167
|
|
|
11
|
-
|
|
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 parents = getHotState(url).p;
|
|
17
|
-
if (!parents.includes(originalParent)) parents.push(originalParent);
|
|
18
|
-
return toVersioned(url);
|
|
19
|
-
};
|
|
20
|
-
const hotImportHook = (url, _, __, source, sourceType) => {
|
|
21
|
-
const hotState = getHotState(url);
|
|
22
|
-
hotState.e = typeof source === 'string' ? source : true;
|
|
23
|
-
hotState.t = sourceType;
|
|
24
|
-
};
|
|
25
|
-
const hotMetaHook = (metaObj, url) => {
|
|
26
|
-
metaObj.hot = new Hot(url);
|
|
27
|
-
};
|
|
168
|
+
const hasDocument = typeof document !== 'undefined';
|
|
28
169
|
|
|
29
|
-
|
|
30
|
-
constructor(url) {
|
|
31
|
-
this.data = getHotState((this.url = stripVersion(url))).d;
|
|
32
|
-
}
|
|
33
|
-
accept(deps, cb) {
|
|
34
|
-
if (typeof deps === 'function') {
|
|
35
|
-
cb = deps;
|
|
36
|
-
deps = null;
|
|
37
|
-
}
|
|
38
|
-
const hotState = getHotState(this.url);
|
|
39
|
-
if (!hotState.A) return;
|
|
40
|
-
(hotState.a = hotState.a || []).push([
|
|
41
|
-
typeof deps === 'string' ? defaultResolve(deps, this.url)
|
|
42
|
-
: deps ? deps.map(d => defaultResolve(d, this.url))
|
|
43
|
-
: null,
|
|
44
|
-
cb
|
|
45
|
-
]);
|
|
46
|
-
}
|
|
47
|
-
dispose(cb) {
|
|
48
|
-
getHotState(this.url).u = cb;
|
|
49
|
-
}
|
|
50
|
-
invalidate() {
|
|
51
|
-
const hotState = getHotState(this.url);
|
|
52
|
-
hotState.a = null;
|
|
53
|
-
hotState.A = true;
|
|
54
|
-
const seen = [this.url];
|
|
55
|
-
for (const p of hotState.p) invalidate(p, this.url, seen);
|
|
56
|
-
}
|
|
57
|
-
};
|
|
170
|
+
const noop = () => {};
|
|
58
171
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
172
|
+
const chain = (a, b) =>
|
|
173
|
+
function () {
|
|
174
|
+
a.apply(this, arguments);
|
|
175
|
+
b.apply(this, arguments);
|
|
63
176
|
};
|
|
64
177
|
|
|
65
|
-
|
|
66
|
-
const v = getHotState(url).v;
|
|
67
|
-
return url + (v ? '?v=' + v : '');
|
|
68
|
-
};
|
|
178
|
+
const dynamicImport = (u, errUrl) => import(u);
|
|
69
179
|
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
});
|
|
180
|
+
const defineValue = (obj, prop, value) =>
|
|
181
|
+
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
93
182
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
d === root && c(m)
|
|
145
|
-
: c(await Promise.all(d.map(d => (earlyRoots.push(c), importShim(toVersioned(d)))))))
|
|
146
|
-
);
|
|
147
|
-
});
|
|
148
|
-
}
|
|
149
|
-
}, throwError);
|
|
150
|
-
}
|
|
151
|
-
curInvalidationRoots = new Set();
|
|
152
|
-
}, hotReloadInterval);
|
|
153
|
-
};
|
|
183
|
+
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
184
|
+
|
|
185
|
+
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
186
|
+
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
187
|
+
|
|
188
|
+
const version = "2.5.0";
|
|
189
|
+
|
|
190
|
+
const r$1 = esmsInitOptions.version;
|
|
191
|
+
if (self.importShim || (r$1 && r$1 !== version)) {
|
|
192
|
+
console.info(
|
|
193
|
+
`es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
|
|
194
|
+
);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// shim mode is determined on initialization, no late shim mode
|
|
199
|
+
const shimMode =
|
|
200
|
+
esmsInitOptions.shimMode ||
|
|
201
|
+
(hasDocument &&
|
|
202
|
+
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
203
|
+
.length > 0);
|
|
204
|
+
|
|
205
|
+
let importHook,
|
|
206
|
+
resolveHook,
|
|
207
|
+
fetchHook = fetch,
|
|
208
|
+
metaHook,
|
|
209
|
+
tsTransform =
|
|
210
|
+
esmsInitOptions.tsTransform ||
|
|
211
|
+
(hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
|
|
212
|
+
'./es-module-shims-typescript.js';
|
|
213
|
+
|
|
214
|
+
const defaultFetchOpts = { credentials: 'same-origin' };
|
|
215
|
+
|
|
216
|
+
const {
|
|
217
|
+
revokeBlobURLs,
|
|
218
|
+
noLoadEventRetriggers,
|
|
219
|
+
enforceIntegrity,
|
|
220
|
+
hotReload,
|
|
221
|
+
hotReloadInterval = 100,
|
|
222
|
+
nativePassthrough = !hotReload
|
|
223
|
+
} = esmsInitOptions;
|
|
224
|
+
|
|
225
|
+
const globalHook = name => (typeof name === 'string' ? self[name] : name);
|
|
226
|
+
|
|
227
|
+
if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
|
|
228
|
+
if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
|
|
229
|
+
if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
|
|
230
|
+
if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
|
|
231
|
+
|
|
232
|
+
if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
|
|
154
233
|
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
234
|
+
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
235
|
+
|
|
236
|
+
let nonce = esmsInitOptions.nonce;
|
|
237
|
+
if (!nonce && hasDocument) {
|
|
238
|
+
const nonceElement = document.querySelector('script[nonce]');
|
|
239
|
+
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
|
|
243
|
+
|
|
244
|
+
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
245
|
+
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
246
|
+
const wasmInstancePhaseEnabled =
|
|
247
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
|
|
248
|
+
const wasmSourcePhaseEnabled =
|
|
249
|
+
enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
|
|
250
|
+
const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
|
|
251
|
+
|
|
252
|
+
const onpolyfill =
|
|
253
|
+
esmsInitOptions.onpolyfill ?
|
|
254
|
+
globalHook(esmsInitOptions.onpolyfill)
|
|
255
|
+
: () => {
|
|
256
|
+
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
const baseUrl =
|
|
260
|
+
hasDocument ?
|
|
261
|
+
document.baseURI
|
|
262
|
+
: `${location.protocol}//${location.host}${
|
|
263
|
+
location.pathname.includes('/') ?
|
|
264
|
+
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
265
|
+
: location.pathname
|
|
266
|
+
}`;
|
|
267
|
+
|
|
268
|
+
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
269
|
+
let { skip } = esmsInitOptions;
|
|
270
|
+
if (Array.isArray(skip)) {
|
|
271
|
+
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
272
|
+
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
273
|
+
} else if (typeof skip === 'string') {
|
|
274
|
+
const r = new RegExp(skip);
|
|
275
|
+
skip = s => r.test(s);
|
|
276
|
+
} else if (skip instanceof RegExp) {
|
|
277
|
+
skip = s => skip.test(s);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
281
|
+
|
|
282
|
+
const throwError = err => {
|
|
283
|
+
(self.reportError || dispatchError)(err), void onerror(err);
|
|
163
284
|
};
|
|
164
285
|
|
|
165
|
-
const hasDocument = typeof document !== 'undefined';
|
|
166
|
-
|
|
167
|
-
const noop = () => {};
|
|
168
|
-
|
|
169
|
-
const chain = (a, b) =>
|
|
170
|
-
function () {
|
|
171
|
-
a.apply(this, arguments);
|
|
172
|
-
b.apply(this, arguments);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
const dynamicImport = (u, errUrl) => import(u);
|
|
176
|
-
|
|
177
|
-
const defineValue = (obj, prop, value) =>
|
|
178
|
-
Object.defineProperty(obj, prop, { writable: false, configurable: false, value });
|
|
179
|
-
|
|
180
|
-
const optionsScript = hasDocument ? document.querySelector('script[type=esms-options]') : undefined;
|
|
181
|
-
|
|
182
|
-
const esmsInitOptions = optionsScript ? JSON.parse(optionsScript.innerHTML) : {};
|
|
183
|
-
Object.assign(esmsInitOptions, self.esmsInitOptions || {});
|
|
184
|
-
|
|
185
|
-
const version = "2.4.1";
|
|
186
|
-
|
|
187
|
-
const r$1 = esmsInitOptions.version;
|
|
188
|
-
if (self.importShim || (r$1 && r$1 !== version)) {
|
|
189
|
-
console.info(
|
|
190
|
-
`es-module-shims: skipping initialization as ${r$1 ? `configured for ${r$1}` : 'another instance has already registered'}`
|
|
191
|
-
);
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// shim mode is determined on initialization, no late shim mode
|
|
196
|
-
const shimMode =
|
|
197
|
-
esmsInitOptions.shimMode ||
|
|
198
|
-
(hasDocument &&
|
|
199
|
-
document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]')
|
|
200
|
-
.length > 0);
|
|
201
|
-
|
|
202
|
-
let importHook,
|
|
203
|
-
resolveHook,
|
|
204
|
-
fetchHook = fetch,
|
|
205
|
-
metaHook,
|
|
206
|
-
tsTransform =
|
|
207
|
-
esmsInitOptions.tsTransform ||
|
|
208
|
-
(hasDocument && document.currentScript && document.currentScript.src.replace(/(\.\w+)?\.js$/, '-typescript.js')) ||
|
|
209
|
-
'./es-module-shims-typescript.js';
|
|
210
|
-
|
|
211
|
-
const defaultFetchOpts = { credentials: 'same-origin' };
|
|
212
|
-
|
|
213
|
-
const {
|
|
214
|
-
revokeBlobURLs,
|
|
215
|
-
noLoadEventRetriggers,
|
|
216
|
-
enforceIntegrity,
|
|
217
|
-
hotReload,
|
|
218
|
-
hotReloadInterval = 100,
|
|
219
|
-
nativePassthrough = !hotReload
|
|
220
|
-
} = esmsInitOptions;
|
|
221
|
-
|
|
222
|
-
const globalHook = name => (typeof name === 'string' ? self[name] : name);
|
|
223
|
-
|
|
224
|
-
if (esmsInitOptions.onimport) importHook = globalHook(esmsInitOptions.onimport);
|
|
225
|
-
if (esmsInitOptions.resolve) resolveHook = globalHook(esmsInitOptions.resolve);
|
|
226
|
-
if (esmsInitOptions.fetch) fetchHook = globalHook(esmsInitOptions.fetch);
|
|
227
|
-
if (esmsInitOptions.meta) metaHook = globalHook(esmsInitOptions.meta);
|
|
228
|
-
|
|
229
|
-
if (hotReload) [importHook, resolveHook, metaHook] = initHotReload();
|
|
230
|
-
|
|
231
|
-
const mapOverrides = esmsInitOptions.mapOverrides;
|
|
232
|
-
|
|
233
|
-
let nonce = esmsInitOptions.nonce;
|
|
234
|
-
if (!nonce && hasDocument) {
|
|
235
|
-
const nonceElement = document.querySelector('script[nonce]');
|
|
236
|
-
if (nonceElement) nonce = nonceElement.nonce || nonceElement.getAttribute('nonce');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
const onerror = globalHook(esmsInitOptions.onerror || console.error.bind(console));
|
|
240
|
-
|
|
241
|
-
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
242
|
-
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
243
|
-
const wasmInstancePhaseEnabled =
|
|
244
|
-
enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
|
|
245
|
-
const wasmSourcePhaseEnabled =
|
|
246
|
-
enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
|
|
247
|
-
const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
|
|
248
|
-
|
|
249
|
-
const onpolyfill =
|
|
250
|
-
esmsInitOptions.onpolyfill ?
|
|
251
|
-
globalHook(esmsInitOptions.onpolyfill)
|
|
252
|
-
: () => {
|
|
253
|
-
console.log(`%c^^ Module error above is polyfilled and can be ignored ^^`, 'font-weight:900;color:#391');
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
const baseUrl =
|
|
257
|
-
hasDocument ?
|
|
258
|
-
document.baseURI
|
|
259
|
-
: `${location.protocol}//${location.host}${
|
|
260
|
-
location.pathname.includes('/') ?
|
|
261
|
-
location.pathname.slice(0, location.pathname.lastIndexOf('/') + 1)
|
|
262
|
-
: location.pathname
|
|
263
|
-
}`;
|
|
264
|
-
|
|
265
|
-
const createBlob = (source, type = 'text/javascript') => URL.createObjectURL(new Blob([source], { type }));
|
|
266
|
-
let { skip } = esmsInitOptions;
|
|
267
|
-
if (Array.isArray(skip)) {
|
|
268
|
-
const l = skip.map(s => new URL(s, baseUrl).href);
|
|
269
|
-
skip = s => l.some(i => (i[i.length - 1] === '/' && s.startsWith(i)) || s === i);
|
|
270
|
-
} else if (typeof skip === 'string') {
|
|
271
|
-
const r = new RegExp(skip);
|
|
272
|
-
skip = s => r.test(s);
|
|
273
|
-
} else if (skip instanceof RegExp) {
|
|
274
|
-
skip = s => skip.test(s);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
const dispatchError = error => self.dispatchEvent(Object.assign(new Event('error'), { error }));
|
|
278
|
-
|
|
279
|
-
const throwError = err => {
|
|
280
|
-
(self.reportError || dispatchError)(err), void onerror(err);
|
|
281
|
-
};
|
|
282
|
-
|
|
283
286
|
const fromParent = parent => (parent ? ` imported from ${parent}` : '');
|
|
284
287
|
|
|
285
288
|
const backslashRegEx = /\\/g;
|
|
@@ -476,121 +479,121 @@
|
|
|
476
479
|
}
|
|
477
480
|
};
|
|
478
481
|
|
|
479
|
-
// support browsers without dynamic import support (eg Firefox 6x)
|
|
480
|
-
let supportsJsonType = false;
|
|
481
|
-
let supportsCssType = false;
|
|
482
|
-
|
|
483
|
-
const supports = hasDocument && HTMLScriptElement.supports;
|
|
484
|
-
|
|
485
|
-
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
486
|
-
let supportsWasmInstancePhase = false;
|
|
487
|
-
let supportsWasmSourcePhase = false;
|
|
488
|
-
let supportsMultipleImportMaps = false;
|
|
489
|
-
|
|
490
|
-
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
491
|
-
|
|
492
|
-
let featureDetectionPromise = (async function () {
|
|
493
|
-
if (!hasDocument)
|
|
494
|
-
return Promise.all([
|
|
495
|
-
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
496
|
-
() => (
|
|
497
|
-
(supportsJsonType = true),
|
|
498
|
-
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
499
|
-
() => (supportsCssType = true),
|
|
500
|
-
noop
|
|
501
|
-
)
|
|
502
|
-
),
|
|
503
|
-
noop
|
|
504
|
-
),
|
|
505
|
-
wasmInstancePhaseEnabled &&
|
|
506
|
-
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
507
|
-
() => (supportsWasmInstancePhase = true),
|
|
508
|
-
noop
|
|
509
|
-
),
|
|
510
|
-
wasmSourcePhaseEnabled &&
|
|
511
|
-
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
512
|
-
() => (supportsWasmSourcePhase = true),
|
|
513
|
-
noop
|
|
514
|
-
)
|
|
515
|
-
]);
|
|
516
|
-
|
|
517
|
-
const msgTag = `s${version}`;
|
|
518
|
-
return new Promise(resolve => {
|
|
519
|
-
const iframe = document.createElement('iframe');
|
|
520
|
-
iframe.style.display = 'none';
|
|
521
|
-
iframe.setAttribute('nonce', nonce);
|
|
522
|
-
function cb({ data }) {
|
|
523
|
-
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
524
|
-
if (!isFeatureDetectionMessage) return;
|
|
525
|
-
[
|
|
526
|
-
,
|
|
527
|
-
supportsImportMaps,
|
|
528
|
-
supportsMultipleImportMaps,
|
|
529
|
-
supportsJsonType,
|
|
530
|
-
supportsCssType,
|
|
531
|
-
supportsWasmSourcePhase,
|
|
532
|
-
supportsWasmInstancePhase
|
|
533
|
-
] = data;
|
|
534
|
-
resolve();
|
|
535
|
-
document.head.removeChild(iframe);
|
|
536
|
-
window.removeEventListener('message', cb, false);
|
|
537
|
-
}
|
|
538
|
-
window.addEventListener('message', cb, false);
|
|
539
|
-
|
|
540
|
-
// Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
|
|
541
|
-
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
542
|
-
supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
543
|
-
};sp=${
|
|
544
|
-
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
545
|
-
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
546
|
-
: 'false'
|
|
547
|
-
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
548
|
-
supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
|
|
549
|
-
},sp,${
|
|
550
|
-
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
551
|
-
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
552
|
-
: 'false'
|
|
553
|
-
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
554
|
-
|
|
555
|
-
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
556
|
-
// path to trigger before setting srcdoc, therefore we track the timing
|
|
557
|
-
let readyForOnload = false,
|
|
558
|
-
onloadCalledWhileNotReady = false;
|
|
559
|
-
function doOnload() {
|
|
560
|
-
if (!readyForOnload) {
|
|
561
|
-
onloadCalledWhileNotReady = true;
|
|
562
|
-
return;
|
|
563
|
-
}
|
|
564
|
-
// WeChat browser doesn't support setting srcdoc scripts
|
|
565
|
-
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
566
|
-
const doc = iframe.contentDocument;
|
|
567
|
-
if (doc && doc.head.childNodes.length === 0) {
|
|
568
|
-
const s = doc.createElement('script');
|
|
569
|
-
if (nonce) s.setAttribute('nonce', nonce);
|
|
570
|
-
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
571
|
-
doc.head.appendChild(s);
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
iframe.onload = doOnload;
|
|
576
|
-
// WeChat browser requires append before setting srcdoc
|
|
577
|
-
document.head.appendChild(iframe);
|
|
578
|
-
|
|
579
|
-
// setting srcdoc is not supported in React native webviews on iOS
|
|
580
|
-
// setting src to a blob URL results in a navigation event in webviews
|
|
581
|
-
// document.write gives usability warnings
|
|
582
|
-
readyForOnload = true;
|
|
583
|
-
if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
|
|
584
|
-
else iframe.contentDocument.write(importMapTest);
|
|
585
|
-
// retrigger onload for Safari only if necessary
|
|
586
|
-
if (onloadCalledWhileNotReady) doOnload();
|
|
587
|
-
});
|
|
588
|
-
})();
|
|
589
|
-
|
|
590
|
-
featureDetectionPromise = featureDetectionPromise.then(() => {
|
|
591
|
-
console.info(
|
|
592
|
-
`es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
|
|
593
|
-
);
|
|
482
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
483
|
+
let supportsJsonType = false;
|
|
484
|
+
let supportsCssType = false;
|
|
485
|
+
|
|
486
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
487
|
+
|
|
488
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
489
|
+
let supportsWasmInstancePhase = false;
|
|
490
|
+
let supportsWasmSourcePhase = false;
|
|
491
|
+
let supportsMultipleImportMaps = false;
|
|
492
|
+
|
|
493
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
494
|
+
|
|
495
|
+
let featureDetectionPromise = (async function () {
|
|
496
|
+
if (!hasDocument)
|
|
497
|
+
return Promise.all([
|
|
498
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
499
|
+
() => (
|
|
500
|
+
(supportsJsonType = true),
|
|
501
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
502
|
+
() => (supportsCssType = true),
|
|
503
|
+
noop
|
|
504
|
+
)
|
|
505
|
+
),
|
|
506
|
+
noop
|
|
507
|
+
),
|
|
508
|
+
wasmInstancePhaseEnabled &&
|
|
509
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
510
|
+
() => (supportsWasmInstancePhase = true),
|
|
511
|
+
noop
|
|
512
|
+
),
|
|
513
|
+
wasmSourcePhaseEnabled &&
|
|
514
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
515
|
+
() => (supportsWasmSourcePhase = true),
|
|
516
|
+
noop
|
|
517
|
+
)
|
|
518
|
+
]);
|
|
519
|
+
|
|
520
|
+
const msgTag = `s${version}`;
|
|
521
|
+
return new Promise(resolve => {
|
|
522
|
+
const iframe = document.createElement('iframe');
|
|
523
|
+
iframe.style.display = 'none';
|
|
524
|
+
iframe.setAttribute('nonce', nonce);
|
|
525
|
+
function cb({ data }) {
|
|
526
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === msgTag;
|
|
527
|
+
if (!isFeatureDetectionMessage) return;
|
|
528
|
+
[
|
|
529
|
+
,
|
|
530
|
+
supportsImportMaps,
|
|
531
|
+
supportsMultipleImportMaps,
|
|
532
|
+
supportsJsonType,
|
|
533
|
+
supportsCssType,
|
|
534
|
+
supportsWasmSourcePhase,
|
|
535
|
+
supportsWasmInstancePhase
|
|
536
|
+
] = data;
|
|
537
|
+
resolve();
|
|
538
|
+
document.head.removeChild(iframe);
|
|
539
|
+
window.removeEventListener('message', cb, false);
|
|
540
|
+
}
|
|
541
|
+
window.addEventListener('message', cb, false);
|
|
542
|
+
|
|
543
|
+
// Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check. CSS gates on JSON feature check, Wasm instance phase gates on wasm source phase check.
|
|
544
|
+
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));c=u=>import(u).then(()=>true,()=>false);i=innerText=>document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText}));i(\`{"imports":{"x":"\${b('')}"}}\`);i(\`{"imports":{"y":"\${b('')}"}}\`);cm=${
|
|
545
|
+
supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
546
|
+
};sp=${
|
|
547
|
+
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
548
|
+
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
549
|
+
: 'false'
|
|
550
|
+
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
551
|
+
supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
|
|
552
|
+
},sp,${
|
|
553
|
+
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
554
|
+
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
555
|
+
: 'false'
|
|
556
|
+
}]).then(a=>parent.postMessage(['${msgTag}'].concat(a),'*'))<${''}/script>`;
|
|
557
|
+
|
|
558
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
559
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
560
|
+
let readyForOnload = false,
|
|
561
|
+
onloadCalledWhileNotReady = false;
|
|
562
|
+
function doOnload() {
|
|
563
|
+
if (!readyForOnload) {
|
|
564
|
+
onloadCalledWhileNotReady = true;
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
568
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
569
|
+
const doc = iframe.contentDocument;
|
|
570
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
571
|
+
const s = doc.createElement('script');
|
|
572
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
573
|
+
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
574
|
+
doc.head.appendChild(s);
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
iframe.onload = doOnload;
|
|
579
|
+
// WeChat browser requires append before setting srcdoc
|
|
580
|
+
document.head.appendChild(iframe);
|
|
581
|
+
|
|
582
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
583
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
584
|
+
// document.write gives usability warnings
|
|
585
|
+
readyForOnload = true;
|
|
586
|
+
if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
|
|
587
|
+
else iframe.contentDocument.write(importMapTest);
|
|
588
|
+
// retrigger onload for Safari only if necessary
|
|
589
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
590
|
+
});
|
|
591
|
+
})();
|
|
592
|
+
|
|
593
|
+
featureDetectionPromise = featureDetectionPromise.then(() => {
|
|
594
|
+
console.info(
|
|
595
|
+
`es-module-shims: detected native support - module types: (${[...(supportsJsonType ? ['json'] : []), ...(supportsCssType ? ['css'] : []), ...(supportsWasmInstancePhase ? ['wasm'] : [])].join(', ')}), ${supportsWasmSourcePhase ? 'source phase' : 'no source phase'}, ${supportsMultipleImportMaps ? '' : 'no '}multiple import maps, ${supportsImportMaps ? '' : 'no '}import maps`
|
|
596
|
+
);
|
|
594
597
|
});
|
|
595
598
|
|
|
596
599
|
/* es-module-lexer 1.7.0 */
|
|
@@ -831,7 +834,8 @@
|
|
|
831
834
|
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
832
835
|
// because we can't syntactically pass through to dynamic import with a second argument
|
|
833
836
|
if (sourceType === 'css' || sourceType === 'json') {
|
|
834
|
-
|
|
837
|
+
// Direct reexport for hot reloading skipped due to Firefox bug https://bugzilla.mozilla.org/show_bug.cgi?id=1965620
|
|
838
|
+
source = `import m from'${url}'with{type:"${sourceType}"};export default m;`;
|
|
835
839
|
url += '?entry';
|
|
836
840
|
}
|
|
837
841
|
|
|
@@ -1138,7 +1142,11 @@
|
|
|
1138
1142
|
s += `if(h)h.accept(m=>({${obj}}=m))`;
|
|
1139
1143
|
return { r, s, t: 'wasm' };
|
|
1140
1144
|
} else if (jsonContentType.test(contentType))
|
|
1141
|
-
return {
|
|
1145
|
+
return {
|
|
1146
|
+
r,
|
|
1147
|
+
s: `${hotPrefix}j=${await res.text()};export{j as default};if(h)h.accept(m=>j=m.default)`,
|
|
1148
|
+
t: 'json'
|
|
1149
|
+
};
|
|
1142
1150
|
else if (cssContentType.test(contentType)) {
|
|
1143
1151
|
return {
|
|
1144
1152
|
r,
|
|
@@ -1153,6 +1161,7 @@
|
|
|
1153
1161
|
} else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
|
|
1154
1162
|
const source = await res.text();
|
|
1155
1163
|
if (!esmsTsTransform) await initTs();
|
|
1164
|
+
console.info(`es-module-shims: Compiling TypeScript file ${url}`);
|
|
1156
1165
|
const transformed = esmsTsTransform(source, url);
|
|
1157
1166
|
// even if the TypeScript is valid JavaScript, unless it was a top-level inline source, it wasn't served with
|
|
1158
1167
|
// a valid JS MIME here, so we must still polyfill it
|
|
@@ -1418,6 +1427,7 @@
|
|
|
1418
1427
|
if (ts && !script.src) {
|
|
1419
1428
|
loadPromise = Promise.resolve(esmsTsTransform || initTs())
|
|
1420
1429
|
.then(() => {
|
|
1430
|
+
console.info(`es-module-shims: Compiling TypeScript module script`, script);
|
|
1421
1431
|
const transformed = esmsTsTransform(script.innerHTML, baseUrl);
|
|
1422
1432
|
if (transformed !== undefined) {
|
|
1423
1433
|
onpolyfill();
|