es-module-shims 2.1.2 → 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 -189
- package/dist/es-module-shims.js +192 -182
- package/dist/es-module-shims.wasm.js +192 -182
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* ES Module Shims 2.
|
|
1
|
+
/* ES Module Shims 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,122 +288,120 @@
|
|
|
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
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
`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`
|
|
410
|
-
);
|
|
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
|
+
});
|
|
399
|
+
})();
|
|
400
|
+
|
|
401
|
+
featureDetectionPromise = featureDetectionPromise.then(() => {
|
|
402
|
+
console.info(
|
|
403
|
+
`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`
|
|
404
|
+
);
|
|
411
405
|
});
|
|
412
406
|
|
|
413
407
|
/* es-module-lexer 1.7.0 */
|
|
@@ -469,12 +463,16 @@
|
|
|
469
463
|
// we mock import('./x.css', { with: { type: 'css' }}) support via an inline static reexport
|
|
470
464
|
// because we can't syntactically pass through to dynamic import with a second argument
|
|
471
465
|
let url = await importHandler(id, opts, parentUrl, false);
|
|
472
|
-
let source =
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
466
|
+
let source = undefined;
|
|
467
|
+
let ts = false;
|
|
468
|
+
if (typeof opts === 'object') {
|
|
469
|
+
ts = opts.lang === 'ts';
|
|
470
|
+
if (typeof opts.with === 'object' && typeof opts.with.type === 'string') {
|
|
471
|
+
source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
|
|
472
|
+
url += '?entry';
|
|
473
|
+
}
|
|
476
474
|
}
|
|
477
|
-
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined);
|
|
475
|
+
return topLevelLoad(url, { credentials: 'same-origin' }, source, undefined, undefined, ts);
|
|
478
476
|
}
|
|
479
477
|
|
|
480
478
|
// import.source()
|
|
@@ -486,7 +484,7 @@
|
|
|
486
484
|
opts = undefined;
|
|
487
485
|
}
|
|
488
486
|
const url = await importHandler(specifier, opts, parentUrl, true);
|
|
489
|
-
const load = getOrCreateLoad(url, { credentials: 'same-origin' },
|
|
487
|
+
const load = getOrCreateLoad(url, { credentials: 'same-origin' }, undefined, undefined);
|
|
490
488
|
if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) {
|
|
491
489
|
onpolyfill();
|
|
492
490
|
firstPolyfillLoad = false;
|
|
@@ -548,14 +546,13 @@
|
|
|
548
546
|
baselinePassthrough =
|
|
549
547
|
esmsInitOptions.polyfillEnable !== true &&
|
|
550
548
|
supportsImportMaps &&
|
|
551
|
-
|
|
552
|
-
|
|
549
|
+
supportsJsonType &&
|
|
550
|
+
supportsCssType &&
|
|
553
551
|
(!wasmInstancePhaseEnabled || supportsWasmInstancePhase) &&
|
|
554
552
|
(!wasmSourcePhaseEnabled || supportsWasmSourcePhase) &&
|
|
555
553
|
!deferPhaseEnabled &&
|
|
556
554
|
(!multipleImportMaps || supportsMultipleImportMaps) &&
|
|
557
|
-
!importMapSrc
|
|
558
|
-
!typescriptEnabled;
|
|
555
|
+
!importMapSrc;
|
|
559
556
|
if (
|
|
560
557
|
!shimMode &&
|
|
561
558
|
wasmSourcePhaseEnabled &&
|
|
@@ -639,20 +636,19 @@
|
|
|
639
636
|
let firstPolyfillLoad = true;
|
|
640
637
|
let legacyAcceptingImportMaps = true;
|
|
641
638
|
|
|
642
|
-
async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
|
|
643
|
-
legacyAcceptingImportMaps = false;
|
|
639
|
+
async function topLevelLoad(url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise, typescript) {
|
|
644
640
|
await initPromise;
|
|
645
641
|
await importMapPromise;
|
|
646
642
|
if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, '');
|
|
647
643
|
// early analysis opt-out - no need to even fetch if we have feature support
|
|
648
|
-
if (!shimMode && baselinePassthrough) {
|
|
644
|
+
if (!shimMode && baselinePassthrough && !typescript) {
|
|
649
645
|
console.info(`es-module-shims: early exit for ${url} due to baseline modules support`);
|
|
650
646
|
// for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
|
651
647
|
if (nativelyLoaded) return null;
|
|
652
648
|
await lastStaticLoadPromise;
|
|
653
649
|
return dynamicImport(source ? createBlob(source) : url);
|
|
654
650
|
}
|
|
655
|
-
const load = getOrCreateLoad(url, fetchOpts,
|
|
651
|
+
const load = getOrCreateLoad(url, fetchOpts, undefined, source);
|
|
656
652
|
linkLoad(load, fetchOpts);
|
|
657
653
|
const seen = {};
|
|
658
654
|
await loadAll(load, seen);
|
|
@@ -673,12 +669,12 @@
|
|
|
673
669
|
onpolyfill();
|
|
674
670
|
firstPolyfillLoad = false;
|
|
675
671
|
}
|
|
676
|
-
const module = await (
|
|
672
|
+
const module = await (shimMode || load.n || load.N || (!nativelyLoaded && source) ?
|
|
673
|
+
dynamicImport(load.b, load.u)
|
|
674
|
+
: import(load.u));
|
|
677
675
|
// if the top-level load is a shell, run its update function
|
|
678
676
|
if (load.s) (await dynamicImport(load.s, load.u)).u$_(module);
|
|
679
677
|
if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
|
680
|
-
// when tla is supported, this should return the tla promise as an actual handle
|
|
681
|
-
// so readystate can still correspond to the sync subgraph exec completions
|
|
682
678
|
return module;
|
|
683
679
|
}
|
|
684
680
|
|
|
@@ -692,7 +688,7 @@
|
|
|
692
688
|
if (batchStartIndex > keysLength) return;
|
|
693
689
|
for (const key of registryKeys.slice(batchStartIndex, batchStartIndex + 100)) {
|
|
694
690
|
const load = registry[key];
|
|
695
|
-
if (load && load.b) URL.revokeObjectURL(load.b);
|
|
691
|
+
if (load && load.b && load.b !== load.u) URL.revokeObjectURL(load.b);
|
|
696
692
|
}
|
|
697
693
|
batch++;
|
|
698
694
|
schedule(cleanup);
|
|
@@ -756,6 +752,14 @@
|
|
|
756
752
|
}
|
|
757
753
|
// dependency source replacements
|
|
758
754
|
else if (dynamicImportIndex === -1) {
|
|
755
|
+
let keepAssertion = false;
|
|
756
|
+
if (a > 0 && !shimMode) {
|
|
757
|
+
const assertion = source.slice(a, statementEnd - 1);
|
|
758
|
+
// strip assertions only when unsupported in polyfill mode
|
|
759
|
+
keepAssertion =
|
|
760
|
+
(supportsJsonType && assertion.includes('json')) || (supportsCssType && assertion.includes('css'));
|
|
761
|
+
}
|
|
762
|
+
|
|
759
763
|
// defer phase stripping
|
|
760
764
|
if (t === 6) {
|
|
761
765
|
pushStringTo(statementStart);
|
|
@@ -783,9 +787,6 @@
|
|
|
783
787
|
}
|
|
784
788
|
}
|
|
785
789
|
|
|
786
|
-
// strip import assertions unless we support them
|
|
787
|
-
const stripAssertion = (!supportsCssType && !supportsJsonType) || !(a > 0);
|
|
788
|
-
|
|
789
790
|
pushStringTo(start - 1);
|
|
790
791
|
resolvedSource += `/*${source.slice(start - 1, end + 1)}*/'${blobUrl}'`;
|
|
791
792
|
|
|
@@ -794,7 +795,7 @@
|
|
|
794
795
|
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
|
|
795
796
|
depLoad.s = undefined;
|
|
796
797
|
}
|
|
797
|
-
lastIndex =
|
|
798
|
+
lastIndex = keepAssertion ? end + 1 : statementEnd;
|
|
798
799
|
}
|
|
799
800
|
// import.meta
|
|
800
801
|
else if (dynamicImportIndex === -2) {
|
|
@@ -951,14 +952,13 @@
|
|
|
951
952
|
)});export default s;`,
|
|
952
953
|
t: 'css'
|
|
953
954
|
};
|
|
954
|
-
} else if (
|
|
955
|
-
(shimMode || typescriptEnabled) &&
|
|
956
|
-
(tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
|
|
957
|
-
) {
|
|
955
|
+
} else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
|
|
958
956
|
const source = await res.text();
|
|
959
957
|
if (!esmsTsTransform) await initTs();
|
|
960
958
|
const transformed = esmsTsTransform(source, url);
|
|
961
|
-
|
|
959
|
+
// even if the TypeScript is valid JavaScript, unless it was a top-level inline source, it wasn't served with
|
|
960
|
+
// a valid JS MIME here, so we must still polyfill it
|
|
961
|
+
return { r, s: transformed === undefined ? source : transformed, t: 'ts' };
|
|
962
962
|
} else
|
|
963
963
|
throw Error(
|
|
964
964
|
`Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
|
|
@@ -966,13 +966,7 @@
|
|
|
966
966
|
}
|
|
967
967
|
|
|
968
968
|
function isUnsupportedType(type) {
|
|
969
|
-
if (
|
|
970
|
-
(type === 'css' && !cssModulesEnabled) ||
|
|
971
|
-
(type === 'json' && !jsonModulesEnabled) ||
|
|
972
|
-
(type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) ||
|
|
973
|
-
(type === 'ts' && !typescriptEnabled)
|
|
974
|
-
)
|
|
975
|
-
throw featErr(`${type}-modules`);
|
|
969
|
+
if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
|
|
976
970
|
return (
|
|
977
971
|
(type === 'css' && !supportsCssType) ||
|
|
978
972
|
(type === 'json' && !supportsJsonType) ||
|
|
@@ -1008,9 +1002,9 @@
|
|
|
1008
1002
|
b: undefined,
|
|
1009
1003
|
// shellUrl
|
|
1010
1004
|
s: undefined,
|
|
1011
|
-
// needsShim
|
|
1005
|
+
// needsShim: does it fail execution in the current native loader?
|
|
1012
1006
|
n: false,
|
|
1013
|
-
// shouldShim
|
|
1007
|
+
// shouldShim: does it need to be loaded by the polyfill loader?
|
|
1014
1008
|
N: false,
|
|
1015
1009
|
// type
|
|
1016
1010
|
t: null,
|
|
@@ -1018,7 +1012,7 @@
|
|
|
1018
1012
|
m: null
|
|
1019
1013
|
};
|
|
1020
1014
|
load.f = (async () => {
|
|
1021
|
-
if (
|
|
1015
|
+
if (load.S === undefined) {
|
|
1022
1016
|
// preload fetch options override fetch options (race)
|
|
1023
1017
|
({ r: load.r, s: load.S, t: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
|
|
1024
1018
|
if (!load.n && load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
|
|
@@ -1046,17 +1040,25 @@
|
|
|
1046
1040
|
load.L = load.f.then(async () => {
|
|
1047
1041
|
let childFetchOpts = fetchOpts;
|
|
1048
1042
|
load.d = load.a[0]
|
|
1049
|
-
.map(({ n, d, t, a }) => {
|
|
1043
|
+
.map(({ n, d, t, a, se }) => {
|
|
1050
1044
|
const phaseImport = t >= 4;
|
|
1051
1045
|
const sourcePhase = phaseImport && t < 6;
|
|
1052
1046
|
if (phaseImport) {
|
|
1053
1047
|
if (!shimMode && (sourcePhase ? !wasmSourcePhaseEnabled : !deferPhaseEnabled))
|
|
1054
|
-
throw featErr(sourcePhase ? '
|
|
1048
|
+
throw featErr(sourcePhase ? 'wasm-module-sources' : 'import-defer');
|
|
1055
1049
|
if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
|
|
1056
1050
|
}
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1051
|
+
let source = undefined;
|
|
1052
|
+
if (a > 0 && !shimMode) {
|
|
1053
|
+
const assertion = load.S.slice(a, se - 1);
|
|
1054
|
+
// no need to fetch JSON/CSS if supported, since it's a leaf node, we'll just strip the assertion syntax
|
|
1055
|
+
if (assertion.includes('json')) {
|
|
1056
|
+
if (supportsJsonType) source = '';
|
|
1057
|
+
else load.n = true;
|
|
1058
|
+
} else if (assertion.includes('css')) {
|
|
1059
|
+
if (supportsCssType) source = '';
|
|
1060
|
+
else load.n = true;
|
|
1061
|
+
}
|
|
1060
1062
|
}
|
|
1061
1063
|
if (d !== -1 || !n) return;
|
|
1062
1064
|
const resolved = resolve(n, load.r || load.u);
|
|
@@ -1065,7 +1067,9 @@
|
|
|
1065
1067
|
if (d !== -1) return;
|
|
1066
1068
|
if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
|
|
1067
1069
|
if (childFetchOpts.integrity) childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
|
|
1068
|
-
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r,
|
|
1070
|
+
const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, source), s: sourcePhase };
|
|
1071
|
+
// assertion case -> inline the CSS / JSON URL directly
|
|
1072
|
+
if (source === '') child.l.b = child.l.u;
|
|
1069
1073
|
if (!child.s) linkLoad(child.l, fetchOpts);
|
|
1070
1074
|
// load, sourcePhase
|
|
1071
1075
|
return child;
|
|
@@ -1177,43 +1181,49 @@
|
|
|
1177
1181
|
|
|
1178
1182
|
function processScript(script, ready = readyStateCompleteCnt > 0) {
|
|
1179
1183
|
if (epCheck(script, ready)) return;
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1184
|
+
console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
|
|
1185
|
+
// does this load block readystate complete
|
|
1186
|
+
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
1187
|
+
// does this load block DOMContentLoaded
|
|
1188
|
+
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
1189
|
+
const isLoadScript = loadCnt > 0;
|
|
1190
|
+
if (isLoadScript) loadCnt++;
|
|
1191
|
+
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
1192
|
+
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
1193
|
+
let loadPromise;
|
|
1194
|
+
const ts = script.lang === 'ts';
|
|
1195
|
+
if (ts && !script.src) {
|
|
1196
|
+
loadPromise = Promise.resolve(esmsTsTransform || initTs())
|
|
1183
1197
|
.then(() => {
|
|
1184
|
-
const transformed = esmsTsTransform(
|
|
1198
|
+
const transformed = esmsTsTransform(script.innerHTML, baseUrl);
|
|
1185
1199
|
if (transformed !== undefined) {
|
|
1186
1200
|
onpolyfill();
|
|
1187
1201
|
firstPolyfillLoad = false;
|
|
1188
1202
|
}
|
|
1189
1203
|
return topLevelLoad(
|
|
1190
|
-
baseUrl,
|
|
1204
|
+
script.src || baseUrl,
|
|
1191
1205
|
getFetchOpts(script),
|
|
1192
|
-
transformed === undefined ?
|
|
1193
|
-
transformed === undefined,
|
|
1194
|
-
|
|
1206
|
+
transformed === undefined ? script.innerHTML : transformed,
|
|
1207
|
+
!shimMode && transformed === undefined,
|
|
1208
|
+
isBlockingReadyScript && lastStaticLoadPromise,
|
|
1209
|
+
true
|
|
1195
1210
|
);
|
|
1196
1211
|
})
|
|
1197
1212
|
.catch(throwError);
|
|
1213
|
+
} else {
|
|
1214
|
+
loadPromise = topLevelLoad(
|
|
1215
|
+
script.src || baseUrl,
|
|
1216
|
+
getFetchOpts(script),
|
|
1217
|
+
!script.src ? script.innerHTML : undefined,
|
|
1218
|
+
!shimMode,
|
|
1219
|
+
isBlockingReadyScript && lastStaticLoadPromise,
|
|
1220
|
+
ts
|
|
1221
|
+
).catch(throwError);
|
|
1198
1222
|
}
|
|
1199
|
-
console.info(`es-module-shims: checking script ${script.src || '<inline>'}`);
|
|
1200
|
-
// does this load block readystate complete
|
|
1201
|
-
const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
|
|
1202
|
-
// does this load block DOMContentLoaded
|
|
1203
|
-
const isDomContentLoadedScript = domContentLoadedCnt > 0;
|
|
1204
|
-
const isLoadScript = loadCnt > 0;
|
|
1205
|
-
if (isLoadScript) loadCnt++;
|
|
1206
|
-
if (isBlockingReadyScript) readyStateCompleteCnt++;
|
|
1207
|
-
if (isDomContentLoadedScript) domContentLoadedCnt++;
|
|
1208
|
-
const loadPromise = topLevelLoad(
|
|
1209
|
-
script.src || baseUrl,
|
|
1210
|
-
getFetchOpts(script),
|
|
1211
|
-
!script.src && script.innerHTML,
|
|
1212
|
-
!shimMode,
|
|
1213
|
-
isBlockingReadyScript && lastStaticLoadPromise
|
|
1214
|
-
).catch(throwError);
|
|
1215
1223
|
if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
|
|
1216
|
-
if (isBlockingReadyScript
|
|
1224
|
+
if (isBlockingReadyScript && !ts) {
|
|
1225
|
+
lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
|
|
1226
|
+
}
|
|
1217
1227
|
if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
|
|
1218
1228
|
if (isLoadScript) loadPromise.then(loadCheck);
|
|
1219
1229
|
}
|