es-module-shims 2.1.1 → 2.2.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 +73 -32
- package/dist/es-module-shims.debug.js +199 -190
- package/dist/es-module-shims.js +192 -183
- package/dist/es-module-shims.wasm.js +192 -183
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims Wasm 2.
|
|
1
|
+
/* ES Module Shims Wasm 2.2.0 */
|
|
2
2
|
(function () {
|
|
3
3
|
|
|
4
4
|
const hasDocument = typeof document !== 'undefined';
|
|
@@ -49,15 +49,11 @@
|
|
|
49
49
|
|
|
50
50
|
const enable = Array.isArray(esmsInitOptions.polyfillEnable) ? esmsInitOptions.polyfillEnable : [];
|
|
51
51
|
const enableAll = esmsInitOptions.polyfillEnable === 'all' || enable.includes('all');
|
|
52
|
-
const enableLatest = esmsInitOptions.polyfillEnable === 'latest' || enable.includes('latest');
|
|
53
|
-
const cssModulesEnabled = enable.includes('css-modules') || enableAll || enableLatest;
|
|
54
|
-
const jsonModulesEnabled = enable.includes('json-modules') || enableAll || enableLatest;
|
|
55
52
|
const wasmInstancePhaseEnabled =
|
|
56
53
|
enable.includes('wasm-modules') || enable.includes('wasm-module-instances') || enableAll;
|
|
57
54
|
const wasmSourcePhaseEnabled =
|
|
58
55
|
enable.includes('wasm-modules') || enable.includes('wasm-module-sources') || enableAll;
|
|
59
56
|
const deferPhaseEnabled = enable.includes('import-defer') || enableAll;
|
|
60
|
-
const typescriptEnabled = enable.includes('typescript') || enableAll;
|
|
61
57
|
|
|
62
58
|
const onpolyfill =
|
|
63
59
|
esmsInitOptions.onpolyfill ?
|
|
@@ -292,116 +288,114 @@
|
|
|
292
288
|
}
|
|
293
289
|
}
|
|
294
290
|
|
|
295
|
-
// support browsers without dynamic import support (eg Firefox 6x)
|
|
296
|
-
let supportsJsonType = false;
|
|
297
|
-
let supportsCssType = false;
|
|
298
|
-
|
|
299
|
-
const supports = hasDocument && HTMLScriptElement.supports;
|
|
300
|
-
|
|
301
|
-
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
302
|
-
let supportsWasmInstancePhase = false;
|
|
303
|
-
let supportsWasmSourcePhase = false;
|
|
304
|
-
let supportsMultipleImportMaps = false;
|
|
305
|
-
|
|
306
|
-
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
307
|
-
|
|
308
|
-
let featureDetectionPromise = (async function () {
|
|
309
|
-
if (!hasDocument)
|
|
310
|
-
return Promise.all([
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
(
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
wasmInstancePhaseEnabled &&
|
|
322
|
-
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
323
|
-
() => (supportsWasmInstancePhase = true),
|
|
324
|
-
noop
|
|
325
|
-
),
|
|
326
|
-
wasmSourcePhaseEnabled &&
|
|
327
|
-
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
328
|
-
() => (supportsWasmSourcePhase = true),
|
|
329
|
-
noop
|
|
330
|
-
)
|
|
331
|
-
]);
|
|
332
|
-
|
|
333
|
-
return new Promise(resolve => {
|
|
334
|
-
const iframe = document.createElement('iframe');
|
|
335
|
-
iframe.style.display = 'none';
|
|
336
|
-
iframe.setAttribute('nonce', nonce);
|
|
337
|
-
function cb({ data }) {
|
|
338
|
-
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
|
|
339
|
-
if (!isFeatureDetectionMessage) return;
|
|
340
|
-
[
|
|
341
|
-
,
|
|
342
|
-
supportsImportMaps,
|
|
343
|
-
supportsMultipleImportMaps,
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
supportsWasmSourcePhase,
|
|
347
|
-
supportsWasmInstancePhase
|
|
348
|
-
] = data;
|
|
349
|
-
resolve();
|
|
350
|
-
document.head.removeChild(iframe);
|
|
351
|
-
window.removeEventListener('message', cb, false);
|
|
352
|
-
}
|
|
353
|
-
window.addEventListener('message', cb, false);
|
|
354
|
-
|
|
355
|
-
// Feature checking with careful avoidance of unnecessary work - all gated on initial import map supports check.
|
|
356
|
-
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=${
|
|
357
|
-
supportsImportMaps
|
|
358
|
-
};sp=${
|
|
359
|
-
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
360
|
-
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
361
|
-
: 'false'
|
|
362
|
-
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
363
|
-
supportsImportMaps
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
iframe
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
//
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
if (onloadCalledWhileNotReady) doOnload();
|
|
404
|
-
});
|
|
291
|
+
// support browsers without dynamic import support (eg Firefox 6x)
|
|
292
|
+
let supportsJsonType = false;
|
|
293
|
+
let supportsCssType = false;
|
|
294
|
+
|
|
295
|
+
const supports = hasDocument && HTMLScriptElement.supports;
|
|
296
|
+
|
|
297
|
+
let supportsImportMaps = supports && supports.name === 'supports' && supports('importmap');
|
|
298
|
+
let supportsWasmInstancePhase = false;
|
|
299
|
+
let supportsWasmSourcePhase = false;
|
|
300
|
+
let supportsMultipleImportMaps = false;
|
|
301
|
+
|
|
302
|
+
const wasmBytes = [0, 97, 115, 109, 1, 0, 0, 0];
|
|
303
|
+
|
|
304
|
+
let featureDetectionPromise = (async function () {
|
|
305
|
+
if (!hasDocument)
|
|
306
|
+
return Promise.all([
|
|
307
|
+
import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
|
|
308
|
+
() => (
|
|
309
|
+
(supportsJsonType = true),
|
|
310
|
+
import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
|
|
311
|
+
() => (supportsCssType = true),
|
|
312
|
+
noop
|
|
313
|
+
)
|
|
314
|
+
),
|
|
315
|
+
noop
|
|
316
|
+
),
|
|
317
|
+
wasmInstancePhaseEnabled &&
|
|
318
|
+
import(createBlob(`import"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
319
|
+
() => (supportsWasmInstancePhase = true),
|
|
320
|
+
noop
|
|
321
|
+
),
|
|
322
|
+
wasmSourcePhaseEnabled &&
|
|
323
|
+
import(createBlob(`import source x from"${createBlob(new Uint8Array(wasmBytes), 'application/wasm')}"`)).then(
|
|
324
|
+
() => (supportsWasmSourcePhase = true),
|
|
325
|
+
noop
|
|
326
|
+
)
|
|
327
|
+
]);
|
|
328
|
+
|
|
329
|
+
return new Promise(resolve => {
|
|
330
|
+
const iframe = document.createElement('iframe');
|
|
331
|
+
iframe.style.display = 'none';
|
|
332
|
+
iframe.setAttribute('nonce', nonce);
|
|
333
|
+
function cb({ data }) {
|
|
334
|
+
const isFeatureDetectionMessage = Array.isArray(data) && data[0] === 'esms';
|
|
335
|
+
if (!isFeatureDetectionMessage) return;
|
|
336
|
+
[
|
|
337
|
+
,
|
|
338
|
+
supportsImportMaps,
|
|
339
|
+
supportsMultipleImportMaps,
|
|
340
|
+
supportsJsonType,
|
|
341
|
+
supportsCssType,
|
|
342
|
+
supportsWasmSourcePhase,
|
|
343
|
+
supportsWasmInstancePhase
|
|
344
|
+
] = data;
|
|
345
|
+
resolve();
|
|
346
|
+
document.head.removeChild(iframe);
|
|
347
|
+
window.removeEventListener('message', cb, false);
|
|
348
|
+
}
|
|
349
|
+
window.addEventListener('message', cb, false);
|
|
350
|
+
|
|
351
|
+
// 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.
|
|
352
|
+
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=${
|
|
353
|
+
supportsImportMaps ? `c(b(\`import"\${b('{}','text/json')}"with{type:"json"}\`))` : 'false'
|
|
354
|
+
};sp=${
|
|
355
|
+
supportsImportMaps && wasmSourcePhaseEnabled ?
|
|
356
|
+
`c(b(\`import source x from "\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))`
|
|
357
|
+
: 'false'
|
|
358
|
+
};Promise.all([${supportsImportMaps ? 'true' : "c('x')"},${supportsImportMaps ? "c('y')" : false},cm,${
|
|
359
|
+
supportsImportMaps ? `cm.then(s=>s?c(b(\`import"\${b('','text/css')\}"with{type:"css"}\`)):false)` : 'false'
|
|
360
|
+
},sp,${
|
|
361
|
+
supportsImportMaps && wasmInstancePhaseEnabled ?
|
|
362
|
+
`${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
|
|
363
|
+
: 'false'
|
|
364
|
+
}]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
|
|
365
|
+
|
|
366
|
+
// Safari will call onload eagerly on head injection, but we don't want the Wechat
|
|
367
|
+
// path to trigger before setting srcdoc, therefore we track the timing
|
|
368
|
+
let readyForOnload = false,
|
|
369
|
+
onloadCalledWhileNotReady = false;
|
|
370
|
+
function doOnload() {
|
|
371
|
+
if (!readyForOnload) {
|
|
372
|
+
onloadCalledWhileNotReady = true;
|
|
373
|
+
return;
|
|
374
|
+
}
|
|
375
|
+
// WeChat browser doesn't support setting srcdoc scripts
|
|
376
|
+
// But iframe sandboxes don't support contentDocument so we do this as a fallback
|
|
377
|
+
const doc = iframe.contentDocument;
|
|
378
|
+
if (doc && doc.head.childNodes.length === 0) {
|
|
379
|
+
const s = doc.createElement('script');
|
|
380
|
+
if (nonce) s.setAttribute('nonce', nonce);
|
|
381
|
+
s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
|
|
382
|
+
doc.head.appendChild(s);
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
iframe.onload = doOnload;
|
|
387
|
+
// WeChat browser requires append before setting srcdoc
|
|
388
|
+
document.head.appendChild(iframe);
|
|
389
|
+
|
|
390
|
+
// setting srcdoc is not supported in React native webviews on iOS
|
|
391
|
+
// setting src to a blob URL results in a navigation event in webviews
|
|
392
|
+
// document.write gives usability warnings
|
|
393
|
+
readyForOnload = true;
|
|
394
|
+
if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
|
|
395
|
+
else iframe.contentDocument.write(importMapTest);
|
|
396
|
+
// retrigger onload for Safari only if necessary
|
|
397
|
+
if (onloadCalledWhileNotReady) doOnload();
|
|
398
|
+
});
|
|
405
399
|
})();
|
|
406
400
|
|
|
407
401
|
/* es-module-lexer 1.7.0 */
|
|
@@ -460,12 +454,16 @@
|
|
|
460
454
|
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
461
455
|
// because we can't syntactically pass through to dynamic import with a second argument
|
|
462
456
|
let url = await importHandler(id, opts, parentUrl);
|
|
463
|
-
let source =
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
457
|
+
let source = undefined;
|
|
458
|
+
let ts = false;
|
|
459
|
+
if (typeof opts === 'object') {
|
|
460
|
+
ts = opts.lang === 'ts';
|
|
461
|
+
if (typeof opts.with === 'object' && typeof opts.with.type === 'string') {
|
|
462
|
+
source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
|
|
463
|
+
url += '?entry';
|
|
464
|
+
}
|
|
467
465
|
}
|
|
468
|
-
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
|
|
466
|
+
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined, ts);
|
|
469
467
|
}
|
|
470
468
|
|
|
471
469
|
// import.source()
|
|
@@ -477,7 +475,7 @@
|
|
|
477
475
|
opts = undefined;
|
|
478
476
|
}
|
|
479
477
|
const url = await importHandler(specifier, opts, parentUrl);
|
|
480
|
-
const load = getOrCreateLoad(url, { credentials: 'same-origin' },
|
|
478
|
+
const load = getOrCreateLoad(url, { credentials: 'same-origin' }, undefined, undefined);
|
|
481
479
|
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
482
480
|
onpolyfill();
|
|
483
481
|
firstPolyfillLoad = false;
|
|
@@ -539,14 +537,13 @@
|
|
|
539
537
|
baselinePassthrough =
|
|
540
538
|
esmsInitOptions.polyfillEnable !== true &&
|
|
541
539
|
supportsImportMaps &&
|
|
542
|
-
|
|
543
|
-
|
|
540
|
+
supportsJsonType &&
|
|
541
|
+
supportsCssType &&
|
|
544
542
|
(!wasmInstancePhaseEnabled || supportsWasmInstancePhase) &&
|
|
545
543
|
(!wasmSourcePhaseEnabled || supportsWasmSourcePhase) &&
|
|
546
544
|
!deferPhaseEnabled &&
|
|
547
545
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
548
|
-
!importMapSrc
|
|
549
|
-
!typescriptEnabled;
|
|
546
|
+
!importMapSrc;
|
|
550
547
|
if (
|
|
551
548
|
!shimMode &&
|
|
552
549
|
wasmSourcePhaseEnabled &&
|
|
@@ -630,19 +627,18 @@
|
|
|
630
627
|
let firstPolyfillLoad = true;
|
|
631
628
|
let legacyAcceptingImportMaps = true;
|
|
632
629
|
|
|
633
|
-
async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
|
|
634
|
-
legacyAcceptingImportMaps = false;
|
|
630
|
+
async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, typescript) {
|
|
635
631
|
await initPromise;
|
|
636
632
|
await importMapPromise;
|
|
637
633
|
if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
|
|
638
634
|
// early analysis opt-out - no need to even fetch if we have feature support
|
|
639
|
-
if (!shimMode && baselinePassthrough) {
|
|
635
|
+
if (!shimMode && baselinePassthrough && !typescript) {
|
|
640
636
|
// for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
|
641
637
|
if (nativelyLoaded) return null;
|
|
642
638
|
await lastStaticLoadPromise;
|
|
643
639
|
return dynamicImport(source ? createBlob(source) : url);
|
|
644
640
|
}
|
|
645
|
-
const load = getOrCreateLoad(url, fetchOpts,
|
|
641
|
+
const load = getOrCreateLoad(url, fetchOpts, undefined, source);
|
|
646
642
|
linkLoad(load, fetchOpts);
|
|
647
643
|
const seen = {};
|
|
648
644
|
await loadAll(load, seen);
|
|
@@ -660,12 +656,12 @@
|
|
|
660
656
|
onpolyfill();
|
|
661
657
|
firstPolyfillLoad = false;
|
|
662
658
|
}
|
|
663
|
-
const module = await (
|
|
659
|
+
const module = await (shimMode || load.n || load.N || (!nativelyLoaded && source) ?
|
|
660
|
+
dynamicImport(load.b, load.u)
|
|
661
|
+
: import(load.u));
|
|
664
662
|
// if the top-level load is a shell, run its update function
|
|
665
663
|
if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
|
|
666
664
|
if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
|
667
|
-
// when tla is supported, this should return the tla promise as an actual handle
|
|
668
|
-
// so readystate can still correspond to the sync subgraph exec completions
|
|
669
665
|
return module;
|
|
670
666
|
}
|
|
671
667
|
|
|
@@ -679,7 +675,7 @@
|
|
|
679
675
|
if (batchStartIndex > keysLength) return;
|
|
680
676
|
for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
|
|
681
677
|
const load = registry[key];
|
|
682
|
-
if (load && load.b) URL.revokeObjectURL(load.b);
|
|
678
|
+
if (load && load.b && load.b !== load.u) URL.revokeObjectURL(load.b);
|
|
683
679
|
}
|
|
684
680
|
batch++;
|
|
685
681
|
schedule(cleanup);
|
|
@@ -741,6 +737,14 @@
|
|
|
741
737
|
}
|
|
742
738
|
// dependency source replacements
|
|
743
739
|
else if (dynamicImportIndex === -1) {
|
|
740
|
+
let keepAssertion = false;
|
|
741
|
+
if (a > 0 && !shimMode) {
|
|
742
|
+
const assertion = source.slice(a, statementEnd - 1);
|
|
743
|
+
// strip assertions only when unsupported in polyfill mode
|
|
744
|
+
keepAssertion =
|
|
745
|
+
(supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css'));
|
|
746
|
+
}
|
|
747
|
+
|
|
744
748
|
// defer phase stripping
|
|
745
749
|
if (t === 6) {
|
|
746
750
|
pushStringTo(statementStart);
|
|
@@ -768,9 +772,6 @@
|
|
|
768
772
|
}
|
|
769
773
|
}
|
|
770
774
|
|
|
771
|
-
// strip import assertions unless we support them
|
|
772
|
-
const stripAssertion = (!supportsCssType && !supportsJsonType) || !(a > 0);
|
|
773
|
-
|
|
774
775
|
pushStringTo(start - 1);
|
|
775
776
|
resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
|
|
776
777
|
|
|
@@ -779,7 +780,7 @@
|
|
|
779
780
|
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
|
|
780
781
|
depLoad.s = undefined;
|
|
781
782
|
}
|
|
782
|
-
lastIndex =
|
|
783
|
+
lastIndex = keepAssertion ? end + 1 : statementEnd;
|
|
783
784
|
}
|
|
784
785
|
// import.meta
|
|
785
786
|
else if (dynamicImportIndex === -2) {
|
|
@@ -841,7 +842,6 @@
|
|
|
841
842
|
}
|
|
842
843
|
|
|
843
844
|
pushStringTo(source.length);
|
|
844
|
-
console.log(resolvedSource);
|
|
845
845
|
|
|
846
846
|
if (sourceURLCommentStart === -1) resolvedSource += sourceURLCommentPrefix + load.r;
|
|
847
847
|
|
|
@@ -937,14 +937,13 @@
|
|
|
937
937
|
)});export default s;`,
|
|
938
938
|
t: 'css'
|
|
939
939
|
};
|
|
940
|
-
} else if (
|
|
941
|
-
(shimMode || typescriptEnabled) &&
|
|
942
|
-
(tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
|
|
943
|
-
) {
|
|
940
|
+
} else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
|
|
944
941
|
const source = await res.text();
|
|
945
942
|
if (!esmsTsTransform) await initTs();
|
|
946
943
|
const transformed = esmsTsTransform(source, url);
|
|
947
|
-
|
|
944
|
+
// even if the TypeScript is valid JavaScript, unless it was a top-level inline source, it wasn't served with
|
|
945
|
+
// a valid JS MIME here, so we must still polyfill it
|
|
946
|
+
return { r, s: transformed === undefined ? source : transformed, t: 'ts' };
|
|
948
947
|
} else
|
|
949
948
|
throw Error(
|
|
950
949
|
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
@@ -952,13 +951,7 @@
|
|
|
952
951
|
}
|
|
953
952
|
|
|
954
953
|
function isUnsupportedType(type) {
|
|
955
|
-
if (
|
|
956
|
-
(type === 'css' && !cssModulesEnabled) ||
|
|
957
|
-
(type === 'json' && !jsonModulesEnabled) ||
|
|
958
|
-
(type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) ||
|
|
959
|
-
(type === 'ts' && !typescriptEnabled)
|
|
960
|
-
)
|
|
961
|
-
throw featErr(`${type}-modules`);
|
|
954
|
+
if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
|
|
962
955
|
return (
|
|
963
956
|
(type === 'css' && !supportsCssType) ||
|
|
964
957
|
(type === 'json' && !supportsJsonType) ||
|
|
@@ -994,9 +987,9 @@
|
|
|
994
987
|
b: undefined,
|
|
995
988
|
// shellUrl
|
|
996
989
|
s: undefined,
|
|
997
|
-
// needsShim
|
|
990
|
+
// needsShim: does it fail execution in the current native loader?
|
|
998
991
|
n: false,
|
|
999
|
-
// shouldShim
|
|
992
|
+
// shouldShim: does it need to be loaded by the polyfill loader?
|
|
1000
993
|
N: false,
|
|
1001
994
|
// type
|
|
1002
995
|
t: null,
|
|
@@ -1004,7 +997,7 @@
|
|
|
1004
997
|
m: null
|
|
1005
998
|
};
|
|
1006
999
|
load.f = (async () => {
|
|
1007
|
-
if (
|
|
1000
|
+
if (load.S === undefined) {
|
|
1008
1001
|
// preload fetch options override fetch options (race)
|
|
1009
1002
|
({ r: load.r, s: load.S, t: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
|
|
1010
1003
|
if (!load.n && load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
|
|
@@ -1032,17 +1025,25 @@
|
|
|
1032
1025
|
load.L = load.f.then(async () => {
|
|
1033
1026
|
let childFetchOpts = fetchOpts;
|
|
1034
1027
|
load.d = load.a[0]
|
|
1035
|
-
.map(({ n, d, t, a }) => {
|
|
1028
|
+
.map(({ n, d, t, a, se }) => {
|
|
1036
1029
|
const phaseImport = t >= 4;
|
|
1037
1030
|
const sourcePhase = phaseImport && t < 6;
|
|
1038
1031
|
if (phaseImport) {
|
|
1039
1032
|
if (!shimMode && (sourcePhase ? !wasmSourcePhaseEnabled : !deferPhaseEnabled))
|
|
1040
|
-
throw featErr(sourcePhase ? '
|
|
1033
|
+
throw featErr(sourcePhase ? 'wasm-module-sources' : 'import-defer');
|
|
1041
1034
|
if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
|
|
1042
1035
|
}
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1036
|
+
let source = undefined;
|
|
1037
|
+
if (a > 0 && !shimMode) {
|
|
1038
|
+
const assertion = load.S.slice(a, se - 1);
|
|
1039
|
+
// no need to fetch JSON/CSS if supported, since it's a leaf node, we'll just strip the assertion syntax
|
|
1040
|
+
if (assertion.includes('json')) {
|
|
1041
|
+
if (supportsJsonType) source = '';
|
|
1042
|
+
else load.n = true;
|
|
1043
|
+
} else if (assertion.includes('css')) {
|
|
1044
|
+
if (supportsCssType) source = '';
|
|
1045
|
+
else load.n = true;
|
|
1046
|
+
}
|
|
1046
1047
|
}
|
|
1047
1048
|
if (d !== -1 || !n) return;
|
|
1048
1049
|
const resolved = resolve(n, load.r || load.u);
|
|
@@ -1051,7 +1052,9 @@
|
|
|
1051
1052
|
if (d !== -1) return;
|
|
1052
1053
|
if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
|
|
1053
1054
|
if (childFetchOpts.integrity) childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
|
|
1054
|
-
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r,
|
|
1055
|
+
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, source), s: sourcePhase };
|
|
1056
|
+
// assertion case -> inline the CSS / JSON URL directly
|
|
1057
|
+
if (source === '') child.l.b = child.l.u;
|
|
1055
1058
|
if (!child.s) linkLoad(child.l, fetchOpts);
|
|
1056
1059
|
// load, sourcePhase
|
|
1057
1060
|
return child;
|
|
@@ -1158,42 +1161,48 @@
|
|
|
1158
1161
|
|
|
1159
1162
|
function processScript(script, ready = readyStateCompleteCnt > 0) {
|
|
1160
1163
|
if (epCheck(script, ready)) return;
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
+
// does this load block readystate complete
|
|
1165
|
+
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
1166
|
+
// does this load block DOMContentLoaded
|
|
1167
|
+
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
1168
|
+
const isLoadScript = loadCnt > 0;
|
|
1169
|
+
if (isLoadScript) loadCnt++;
|
|
1170
|
+
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
1171
|
+
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
1172
|
+
let loadPromise;
|
|
1173
|
+
const ts = script.lang === 'ts';
|
|
1174
|
+
if (ts && !script.src) {
|
|
1175
|
+
loadPromise = Promise.resolve(esmsTsTransform || initTs())
|
|
1164
1176
|
.then(() => {
|
|
1165
|
-
const transformed = esmsTsTransform(
|
|
1177
|
+
const transformed = esmsTsTransform(script.innerHTML, baseUrl);
|
|
1166
1178
|
if (transformed !== undefined) {
|
|
1167
1179
|
onpolyfill();
|
|
1168
1180
|
firstPolyfillLoad = false;
|
|
1169
1181
|
}
|
|
1170
1182
|
return topLevelLoad(
|
|
1171
|
-
baseUrl,
|
|
1183
|
+
script.src || baseUrl,
|
|
1172
1184
|
getFetchOpts(script),
|
|
1173
|
-
transformed === undefined ?
|
|
1174
|
-
transformed === undefined,
|
|
1175
|
-
|
|
1185
|
+
transformed === undefined ? script.innerHTML : transformed,
|
|
1186
|
+
!shimMode && transformed === undefined,
|
|
1187
|
+
isBlockingReadyScript && lastStaticLoadPromise,
|
|
1188
|
+
true
|
|
1176
1189
|
);
|
|
1177
1190
|
})
|
|
1178
1191
|
.catch(throwError);
|
|
1192
|
+
} else {
|
|
1193
|
+
loadPromise = topLevelLoad(
|
|
1194
|
+
script.src || baseUrl,
|
|
1195
|
+
getFetchOpts(script),
|
|
1196
|
+
!script.src ? script.innerHTML : undefined,
|
|
1197
|
+
!shimMode,
|
|
1198
|
+
isBlockingReadyScript && lastStaticLoadPromise,
|
|
1199
|
+
ts
|
|
1200
|
+
).catch(throwError);
|
|
1179
1201
|
}
|
|
1180
|
-
// does this load block readystate complete
|
|
1181
|
-
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
1182
|
-
// does this load block DOMContentLoaded
|
|
1183
|
-
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
1184
|
-
const isLoadScript = loadCnt > 0;
|
|
1185
|
-
if (isLoadScript) loadCnt++;
|
|
1186
|
-
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
1187
|
-
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
1188
|
-
const loadPromise = topLevelLoad(
|
|
1189
|
-
script.src || baseUrl,
|
|
1190
|
-
getFetchOpts(script),
|
|
1191
|
-
!script.src && script.innerHTML,
|
|
1192
|
-
!shimMode,
|
|
1193
|
-
isBlockingReadyScript && lastStaticLoadPromise
|
|
1194
|
-
).catch(throwError);
|
|
1195
1202
|
if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
|
|
1196
|
-
if (isBlockingReadyScript
|
|
1203
|
+
if (isBlockingReadyScript && !ts) {
|
|
1204
|
+
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
|
1205
|
+
}
|
|
1197
1206
|
if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
|
|
1198
1207
|
if (isLoadScript) loadPromise.then(loadCheck);
|
|
1199
1208
|
}
|