es-module-shims 1.5.15 → 1.5.18
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 +5 -5
- package/dist/es-module-shims.js +104 -90
- package/dist/es-module-shims.wasm.js +104 -98
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Shims modern ES Modules features like import maps on top of the baseline modules support in browsers supported by [95% of users](https://caniuse.com/#feat=es6-module).
|
|
4
4
|
|
|
5
|
-
When running in polyfill mode, [the
|
|
5
|
+
When running in polyfill mode, [the 72% of users](https://caniuse.com/import-maps) with import maps entirely bypass the shim code entirely.
|
|
6
6
|
|
|
7
|
-
For the remaining
|
|
7
|
+
For the remaining 28% of users, the highly performant (see [benchmarks](#benchmarks)) production and [CSP-compatible](#csp-support) shim kicks in to rewrite module specifiers driven by the [Web Assembly ES Module Lexer](https://github.com/guybedford/es-module-lexer).
|
|
8
8
|
|
|
9
9
|
The following modules features are polyfilled:
|
|
10
10
|
|
|
@@ -29,7 +29,7 @@ Because we are still using the native module loader the edge cases work out comp
|
|
|
29
29
|
Include ES Module Shims with a `async` attribute on the script, then include an import map and module scripts normally:
|
|
30
30
|
|
|
31
31
|
```html
|
|
32
|
-
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.
|
|
32
|
+
<script async src="https://ga.jspm.io/npm:es-module-shims@1.5.18/dist/es-module-shims.js"></script>
|
|
33
33
|
|
|
34
34
|
<!-- https://generator.jspm.io/#U2NhYGBkDM0rySzJSU1hKEpNTC5xMLTQM9Az0C1K1jMAAKFS5w0gAA -->
|
|
35
35
|
<script type="importmap">
|
|
@@ -176,8 +176,8 @@ ES Module Shims is designed for production performance. A [comprehensive benchma
|
|
|
176
176
|
|
|
177
177
|
Benchmark summary:
|
|
178
178
|
|
|
179
|
-
* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [
|
|
180
|
-
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [
|
|
179
|
+
* [ES Module Shims Chrome Passthrough](bench/README.md#chrome-passthrough-performance) (for [72% of users](https://caniuse.com/import-maps)) results in ~5ms extra initialization time over native for ES Module Shims fetching, execution and initialization, and on a slow connection the additional non-blocking bandwidth cost of its 10KB compressed download as expected.
|
|
180
|
+
* [ES Module Shims Polyfilling](bench/README.md#native-v-polyfill-performance) (for the remaining [28% of users](https://caniuse.com/import-maps)) is on average 1.4x - 1.5x slower than native module loading, and up to 1.8x slower on slow networks (most likely due to the browser preloader), both for cached and uncached loads, and this result scales linearly up to 10MB and 20k modules loaded executing on the fastest connection in just over 2 seconds in Firefox.
|
|
181
181
|
* [Very large import maps](bench/README.md#large-import-maps-performance) (100s of entries) cost only a few extra milliseconds upfront for the additional loading cost.
|
|
182
182
|
|
|
183
183
|
## Features
|
package/dist/es-module-shims.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims 1.5.
|
|
1
|
+
/* ES Module Shims 1.5.18 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -101,22 +101,14 @@
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/*
|
|
105
|
-
* Import maps implementation
|
|
106
|
-
*
|
|
107
|
-
* To make lookups fast we pre-resolve the entire import map
|
|
108
|
-
* and then match based on backtracked hash lookups
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
104
|
function resolveUrl (relUrl, parentUrl) {
|
|
112
105
|
return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (isURL(relUrl) ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
|
|
113
106
|
}
|
|
114
107
|
|
|
115
108
|
function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
parentUrl = parentUrl.slice(0, queryHashIndex);
|
|
109
|
+
const hIdx = parentUrl.indexOf('#'), qIdx = parentUrl.indexOf('?');
|
|
110
|
+
if (hIdx + qIdx > -2)
|
|
111
|
+
parentUrl = parentUrl.slice(0, hIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx);
|
|
120
112
|
if (relUrl.indexOf('\\') !== -1)
|
|
121
113
|
relUrl = relUrl.replace(backslashRegEx, '/');
|
|
122
114
|
// protocol-relative
|
|
@@ -258,40 +250,52 @@
|
|
|
258
250
|
}
|
|
259
251
|
}
|
|
260
252
|
|
|
261
|
-
let
|
|
262
|
-
window.addEventListener('error', _err => err = _err);
|
|
263
|
-
const inject = (s, errUrl) => new Promise((resolve, reject) => {
|
|
264
|
-
err = undefined;
|
|
265
|
-
s.ep = true;
|
|
266
|
-
if (nonce)
|
|
267
|
-
s.setAttribute('nonce', nonce);
|
|
268
|
-
|
|
269
|
-
// Safari is unique in supporting module script error events
|
|
270
|
-
s.addEventListener('error', cb);
|
|
271
|
-
s.addEventListener('load', cb);
|
|
272
|
-
|
|
273
|
-
function cb (_err) {
|
|
274
|
-
document.head.removeChild(s);
|
|
275
|
-
if (self._esmsi) {
|
|
276
|
-
resolve(self._esmsi, baseUrl);
|
|
277
|
-
self._esmsi = undefined;
|
|
278
|
-
}
|
|
279
|
-
else {
|
|
280
|
-
reject(!(_err instanceof Event) && _err || err && err.error || new Error(`Error loading or executing the graph of ${errUrl} (check the console for ${s.src}).`));
|
|
281
|
-
err = undefined;
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
document.head.appendChild(s);
|
|
286
|
-
});
|
|
253
|
+
let dynamicImport = !hasDocument && (0, eval)('u=>import(u)');
|
|
287
254
|
|
|
288
|
-
|
|
289
|
-
type: 'module',
|
|
290
|
-
src: createBlob(`import*as m from'${url}';self._esmsi=m`)
|
|
291
|
-
}), opts && opts.errUrl || url);
|
|
255
|
+
let supportsDynamicImport;
|
|
292
256
|
|
|
293
|
-
|
|
294
|
-
|
|
257
|
+
const dynamicImportCheck = hasDocument && new Promise(resolve => {
|
|
258
|
+
const s = Object.assign(document.createElement('script'), {
|
|
259
|
+
src: createBlob('self._d=u=>import(u)'),
|
|
260
|
+
ep: true
|
|
261
|
+
});
|
|
262
|
+
s.setAttribute('nonce', nonce);
|
|
263
|
+
s.addEventListener('load', () => {
|
|
264
|
+
if (!(supportsDynamicImport = !!(dynamicImport = self._d))) {
|
|
265
|
+
let err;
|
|
266
|
+
window.addEventListener('error', _err => err = _err);
|
|
267
|
+
dynamicImport = (url, opts) => new Promise((resolve, reject) => {
|
|
268
|
+
const s = Object.assign(document.createElement('script'), {
|
|
269
|
+
type: 'module',
|
|
270
|
+
src: createBlob(`import*as m from'${url}';self._esmsi=m`)
|
|
271
|
+
});
|
|
272
|
+
err = undefined;
|
|
273
|
+
s.ep = true;
|
|
274
|
+
if (nonce)
|
|
275
|
+
s.setAttribute('nonce', nonce);
|
|
276
|
+
// Safari is unique in supporting module script error events
|
|
277
|
+
s.addEventListener('error', cb);
|
|
278
|
+
s.addEventListener('load', cb);
|
|
279
|
+
function cb (_err) {
|
|
280
|
+
document.head.removeChild(s);
|
|
281
|
+
if (self._esmsi) {
|
|
282
|
+
resolve(self._esmsi, baseUrl);
|
|
283
|
+
self._esmsi = undefined;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
reject(!(_err instanceof Event) && _err || err && err.error || new Error(`Error loading ${opts && opts.errUrl || url} (${s.src}).`));
|
|
287
|
+
err = undefined;
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
document.head.appendChild(s);
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
document.head.removeChild(s);
|
|
294
|
+
delete self._d;
|
|
295
|
+
resolve();
|
|
296
|
+
});
|
|
297
|
+
document.head.appendChild(s);
|
|
298
|
+
});
|
|
295
299
|
|
|
296
300
|
// support browsers without dynamic import support (eg Firefox 6x)
|
|
297
301
|
let supportsJsonAssertions = false;
|
|
@@ -299,53 +303,63 @@
|
|
|
299
303
|
|
|
300
304
|
let supportsImportMaps = hasDocument && HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
|
|
301
305
|
let supportsImportMeta = supportsImportMaps;
|
|
302
|
-
let supportsDynamicImport = false;
|
|
303
306
|
|
|
304
|
-
const
|
|
305
|
-
|
|
307
|
+
const importMetaCheck = 'import.meta';
|
|
308
|
+
const cssModulesCheck = `import"x"assert{type:"css"}`;
|
|
309
|
+
const jsonModulesCheck = `import"x"assert{type:"json"}`;
|
|
310
|
+
|
|
311
|
+
const featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
|
|
312
|
+
if (!supportsDynamicImport || supportsImportMaps && !cssModulesEnabled && !jsonModulesEnabled)
|
|
306
313
|
return;
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
314
|
+
|
|
315
|
+
if (!hasDocument)
|
|
316
|
+
return Promise.all([
|
|
317
|
+
supportsImportMaps || dynamicImport(createBlob(importMetaCheck)).then(() => supportsImportMeta = true, noop),
|
|
318
|
+
cssModulesEnabled && dynamicImport(createBlob(cssModulesCheck.replace('x', createBlob('', 'text/css')))).then(() => supportsCssAssertions = true, noop),
|
|
319
|
+
jsonModulesEnabled && dynamicImport(createBlob(jsonModulescheck.replace('x', createBlob('{}', 'text/json')))).then(() => supportsJsonAssertions = true, noop),
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
return new Promise(resolve => {
|
|
323
|
+
const iframe = document.createElement('iframe');
|
|
324
|
+
iframe.style.display = 'none';
|
|
325
|
+
iframe.setAttribute('nonce', nonce);
|
|
326
|
+
function cb ({ data: [a, b, c, d] }) {
|
|
327
|
+
supportsImportMaps = a;
|
|
328
|
+
supportsImportMeta = b;
|
|
329
|
+
supportsCssAssertions = c;
|
|
330
|
+
supportsJsonAssertions = d;
|
|
331
|
+
resolve();
|
|
332
|
+
document.head.removeChild(iframe);
|
|
333
|
+
window.removeEventListener('message', cb, false);
|
|
334
|
+
}
|
|
335
|
+
window.addEventListener('message', cb, false);
|
|
336
|
+
|
|
337
|
+
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText:\`{"imports":{"x":"\${b('')}"}}\`}));Promise.all([${
|
|
338
|
+
supportsImportMaps ? 'true,true' : `'x',b('${importMetaCheck}')`}, ${cssModulesEnabled ? `b('${cssModulesCheck}'.replace('x',b('','text/css')))` : 'false'}, ${
|
|
339
|
+
jsonModulesEnabled ? `b('${jsonModulesCheck}'.replace('x',b('{}','text/json')))` : 'false'}].map(x =>typeof x==='string'?import(x).then(x =>!!x,()=>false):x)).then(a=>parent.postMessage(a,'*'))<${''}/script>`;
|
|
340
|
+
|
|
341
|
+
iframe.onload = () => {
|
|
342
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
343
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
344
|
+
const doc = iframe.contentDocument;
|
|
345
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
346
|
+
const s = doc.createElement('script');
|
|
347
|
+
if (nonce)
|
|
348
|
+
s.setAttribute('nonce', nonce);
|
|
349
|
+
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
350
|
+
doc.head.appendChild(s);
|
|
333
351
|
}
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
iframe.contentDocument.write(importMapTest);
|
|
346
|
-
document.head.appendChild(iframe);
|
|
347
|
-
});
|
|
348
|
-
}
|
|
352
|
+
};
|
|
353
|
+
// WeChat browser requires append before setting srcdoc
|
|
354
|
+
document.head.appendChild(iframe);
|
|
355
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
356
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
357
|
+
// document.write gives usability warnings
|
|
358
|
+
if ('srcdoc' in iframe)
|
|
359
|
+
iframe.srcdoc = importMapTest;
|
|
360
|
+
else
|
|
361
|
+
iframe.contentDocument.write(importMapTest);
|
|
362
|
+
});
|
|
349
363
|
});
|
|
350
364
|
|
|
351
365
|
/* es-module-lexer 1.0.3 */
|
|
@@ -619,9 +633,9 @@
|
|
|
619
633
|
}
|
|
620
634
|
}
|
|
621
635
|
|
|
622
|
-
// support progressive cycle binding updates
|
|
636
|
+
// support progressive cycle binding updates (try statement avoids tdz errors)
|
|
623
637
|
if (load.s)
|
|
624
|
-
resolvedSource += `\n;import{u$_}from'${load.s}';u$_({
|
|
638
|
+
resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports.filter(e => e.ln).map(({ s, e, ln }) => `${source.slice(s, e)}: ${ln}`).join(',')}})}catch(_){};\n`;
|
|
625
639
|
|
|
626
640
|
pushStringTo(source.length);
|
|
627
641
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 1.5.
|
|
1
|
+
/* ES Module Shims Wasm 1.5.18 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasWindow = typeof window !== 'undefined';
|
|
@@ -101,22 +101,14 @@
|
|
|
101
101
|
}
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/*
|
|
105
|
-
* Import maps implementation
|
|
106
|
-
*
|
|
107
|
-
* To make lookups fast we pre-resolve the entire import map
|
|
108
|
-
* and then match based on backtracked hash lookups
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
104
|
function resolveUrl (relUrl, parentUrl) {
|
|
112
105
|
return resolveIfNotPlainOrUrl(relUrl, parentUrl) || (isURL(relUrl) ? relUrl : resolveIfNotPlainOrUrl('./' + relUrl, parentUrl));
|
|
113
106
|
}
|
|
114
107
|
|
|
115
108
|
function resolveIfNotPlainOrUrl (relUrl, parentUrl) {
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
parentUrl = parentUrl.slice(0, queryHashIndex);
|
|
109
|
+
const hIdx = parentUrl.indexOf('#'), qIdx = parentUrl.indexOf('?');
|
|
110
|
+
if (hIdx + qIdx > -2)
|
|
111
|
+
parentUrl = parentUrl.slice(0, hIdx === -1 ? qIdx : qIdx === -1 || qIdx > hIdx ? hIdx : qIdx);
|
|
120
112
|
if (relUrl.indexOf('\\') !== -1)
|
|
121
113
|
relUrl = relUrl.replace(backslashRegEx, '/');
|
|
122
114
|
// protocol-relative
|
|
@@ -258,48 +250,52 @@
|
|
|
258
250
|
}
|
|
259
251
|
}
|
|
260
252
|
|
|
261
|
-
let
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
err = undefined;
|
|
253
|
+
let dynamicImport = !hasDocument && (0, eval)('u=>import(u)');
|
|
254
|
+
|
|
255
|
+
let supportsDynamicImport;
|
|
256
|
+
|
|
257
|
+
const dynamicImportCheck = hasDocument && new Promise(resolve => {
|
|
258
|
+
const s = Object.assign(document.createElement('script'), {
|
|
259
|
+
src: createBlob('self._d=u=>import(u)'),
|
|
260
|
+
ep: true
|
|
261
|
+
});
|
|
262
|
+
s.setAttribute('nonce', nonce);
|
|
263
|
+
s.addEventListener('load', () => {
|
|
264
|
+
if (!(supportsDynamicImport = !!(dynamicImport = self._d))) {
|
|
265
|
+
let err;
|
|
266
|
+
window.addEventListener('error', _err => err = _err);
|
|
267
|
+
dynamicImport = (url, opts) => new Promise((resolve, reject) => {
|
|
268
|
+
const s = Object.assign(document.createElement('script'), {
|
|
269
|
+
type: 'module',
|
|
270
|
+
src: createBlob(`import*as m from'${url}';self._esmsi=m`)
|
|
271
|
+
});
|
|
272
|
+
err = undefined;
|
|
273
|
+
s.ep = true;
|
|
274
|
+
if (nonce)
|
|
275
|
+
s.setAttribute('nonce', nonce);
|
|
276
|
+
// Safari is unique in supporting module script error events
|
|
277
|
+
s.addEventListener('error', cb);
|
|
278
|
+
s.addEventListener('load', cb);
|
|
279
|
+
function cb (_err) {
|
|
280
|
+
document.head.removeChild(s);
|
|
281
|
+
if (self._esmsi) {
|
|
282
|
+
resolve(self._esmsi, baseUrl);
|
|
283
|
+
self._esmsi = undefined;
|
|
284
|
+
}
|
|
285
|
+
else {
|
|
286
|
+
reject(!(_err instanceof Event) && _err || err && err.error || new Error(`Error loading ${opts && opts.errUrl || url} (${s.src}).`));
|
|
287
|
+
err = undefined;
|
|
288
|
+
}
|
|
298
289
|
}
|
|
290
|
+
document.head.appendChild(s);
|
|
299
291
|
});
|
|
300
|
-
}
|
|
301
|
-
|
|
302
|
-
|
|
292
|
+
}
|
|
293
|
+
document.head.removeChild(s);
|
|
294
|
+
delete self._d;
|
|
295
|
+
resolve();
|
|
296
|
+
});
|
|
297
|
+
document.head.appendChild(s);
|
|
298
|
+
});
|
|
303
299
|
|
|
304
300
|
// support browsers without dynamic import support (eg Firefox 6x)
|
|
305
301
|
let supportsJsonAssertions = false;
|
|
@@ -307,53 +303,63 @@
|
|
|
307
303
|
|
|
308
304
|
let supportsImportMaps = hasDocument && HTMLScriptElement.supports ? HTMLScriptElement.supports('importmap') : false;
|
|
309
305
|
let supportsImportMeta = supportsImportMaps;
|
|
310
|
-
let supportsDynamicImport = false;
|
|
311
306
|
|
|
312
|
-
const
|
|
313
|
-
|
|
307
|
+
const importMetaCheck = 'import.meta';
|
|
308
|
+
const cssModulesCheck = `import"x"assert{type:"css"}`;
|
|
309
|
+
const jsonModulesCheck = `import"x"assert{type:"json"}`;
|
|
310
|
+
|
|
311
|
+
const featureDetectionPromise = Promise.resolve(dynamicImportCheck).then(() => {
|
|
312
|
+
if (!supportsDynamicImport || supportsImportMaps && !cssModulesEnabled && !jsonModulesEnabled)
|
|
314
313
|
return;
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
314
|
+
|
|
315
|
+
if (!hasDocument)
|
|
316
|
+
return Promise.all([
|
|
317
|
+
supportsImportMaps || dynamicImport(createBlob(importMetaCheck)).then(() => supportsImportMeta = true, noop),
|
|
318
|
+
cssModulesEnabled && dynamicImport(createBlob(cssModulesCheck.replace('x', createBlob('', 'text/css')))).then(() => supportsCssAssertions = true, noop),
|
|
319
|
+
jsonModulesEnabled && dynamicImport(createBlob(jsonModulescheck.replace('x', createBlob('{}', 'text/json')))).then(() => supportsJsonAssertions = true, noop),
|
|
320
|
+
]);
|
|
321
|
+
|
|
322
|
+
return new Promise(resolve => {
|
|
323
|
+
const iframe = document.createElement('iframe');
|
|
324
|
+
iframe.style.display = 'none';
|
|
325
|
+
iframe.setAttribute('nonce', nonce);
|
|
326
|
+
function cb ({ data: [a, b, c, d] }) {
|
|
327
|
+
supportsImportMaps = a;
|
|
328
|
+
supportsImportMeta = b;
|
|
329
|
+
supportsCssAssertions = c;
|
|
330
|
+
supportsJsonAssertions = d;
|
|
331
|
+
resolve();
|
|
332
|
+
document.head.removeChild(iframe);
|
|
333
|
+
window.removeEventListener('message', cb, false);
|
|
334
|
+
}
|
|
335
|
+
window.addEventListener('message', cb, false);
|
|
336
|
+
|
|
337
|
+
const importMapTest = `<script nonce=${nonce || ''}>b=(s,type='text/javascript')=>URL.createObjectURL(new Blob([s],{type}));document.head.appendChild(Object.assign(document.createElement('script'),{type:'importmap',nonce:"${nonce}",innerText:\`{"imports":{"x":"\${b('')}"}}\`}));Promise.all([${
|
|
338
|
+
supportsImportMaps ? 'true,true' : `'x',b('${importMetaCheck}')`}, ${cssModulesEnabled ? `b('${cssModulesCheck}'.replace('x',b('','text/css')))` : 'false'}, ${
|
|
339
|
+
jsonModulesEnabled ? `b('${jsonModulesCheck}'.replace('x',b('{}','text/json')))` : 'false'}].map(x =>typeof x==='string'?import(x).then(x =>!!x,()=>false):x)).then(a=>parent.postMessage(a,'*'))<${''}/script>`;
|
|
340
|
+
|
|
341
|
+
iframe.onload = () => {
|
|
342
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
343
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
344
|
+
const doc = iframe.contentDocument;
|
|
345
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
346
|
+
const s = doc.createElement('script');
|
|
347
|
+
if (nonce)
|
|
348
|
+
s.setAttribute('nonce', nonce);
|
|
349
|
+
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
350
|
+
doc.head.appendChild(s);
|
|
341
351
|
}
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
iframe.contentDocument.write(importMapTest);
|
|
354
|
-
document.head.appendChild(iframe);
|
|
355
|
-
});
|
|
356
|
-
}
|
|
352
|
+
};
|
|
353
|
+
// WeChat browser requires append before setting srcdoc
|
|
354
|
+
document.head.appendChild(iframe);
|
|
355
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
356
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
357
|
+
// document.write gives usability warnings
|
|
358
|
+
if ('srcdoc' in iframe)
|
|
359
|
+
iframe.srcdoc = importMapTest;
|
|
360
|
+
else
|
|
361
|
+
iframe.contentDocument.write(importMapTest);
|
|
362
|
+
});
|
|
357
363
|
});
|
|
358
364
|
|
|
359
365
|
/* es-module-lexer 1.0.3 */
|
|
@@ -627,9 +633,9 @@
|
|
|
627
633
|
}
|
|
628
634
|
}
|
|
629
635
|
|
|
630
|
-
// support progressive cycle binding updates
|
|
636
|
+
// support progressive cycle binding updates (try statement avoids tdz errors)
|
|
631
637
|
if (load.s)
|
|
632
|
-
resolvedSource += `\n;import{u$_}from'${load.s}';u$_({
|
|
638
|
+
resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports.filter(e => e.ln).map(({ s, e, ln }) => `${source.slice(s, e)}: ${ln}`).join(',')}})}catch(_){};\n`;
|
|
633
639
|
|
|
634
640
|
pushStringTo(source.length);
|
|
635
641
|
}
|