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.
@@ -1,4 +1,4 @@
1
- /* ES Module Shims Wasm 2.1.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
- cssModulesEnabled &&
312
- import(createBlob(`import"${createBlob('', 'text/css')}"with{type:"css"}`)).then(
313
- () => (supportsCssType = true),
314
- noop
315
- ),
316
- jsonModulesEnabled &&
317
- import(createBlob(`import"${createBlob('{}', 'text/json')}"with{type:"json"}`)).then(
318
- () => (supportsJsonType = true),
319
- noop
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
- supportsCssType,
345
- supportsJsonType,
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. JSON gates on CSS feature check, Wasm instance phase gates on wasm source phase 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 && cssModulesEnabled ? `c(b(\`import"\${b('','text/css')}"with{type:"css"}\`))` : 'false'
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 && jsonModulesEnabled ?
364
- `${cssModulesEnabled ? 'cm.then(s=>s?' : ''}c(b(\`import"\${b('{}','text/json')\}"with{type:"json"}\`))${cssModulesEnabled ? ':false)' : ''}`
365
- : 'false'
366
- },sp,${
367
- supportsImportMaps && wasmInstancePhaseEnabled ?
368
- `${wasmSourcePhaseEnabled ? 'sp.then(s=>s?' : ''}c(b(\`import"\${b(new Uint8Array(${JSON.stringify(wasmBytes)}),'application/wasm')\}"\`))${wasmSourcePhaseEnabled ? ':false)' : ''}`
369
- : 'false'
370
- }]).then(a=>parent.postMessage(['esms'].concat(a),'*'))<${''}/script>`;
371
-
372
- // Safari will call onload eagerly on head injection, but we don't want the Wechat
373
- // path to trigger before setting srcdoc, therefore we track the timing
374
- let readyForOnload = false,
375
- onloadCalledWhileNotReady = false;
376
- function doOnload() {
377
- if (!readyForOnload) {
378
- onloadCalledWhileNotReady = true;
379
- return;
380
- }
381
- // WeChat browser doesn't support setting srcdoc scripts
382
- // But iframe sandboxes don't support contentDocument so we do this as a fallback
383
- const doc = iframe.contentDocument;
384
- if (doc && doc.head.childNodes.length === 0) {
385
- const s = doc.createElement('script');
386
- if (nonce) s.setAttribute('nonce', nonce);
387
- s.innerHTML = importMapTest.slice(15 + (nonce ? nonce.length : 0), -9);
388
- doc.head.appendChild(s);
389
- }
390
- }
391
-
392
- iframe.onload = doOnload;
393
- // WeChat browser requires append before setting srcdoc
394
- document.head.appendChild(iframe);
395
-
396
- // setting srcdoc is not supported in React native webviews on iOS
397
- // setting src to a blob URL results in a navigation event in webviews
398
- // document.write gives usability warnings
399
- readyForOnload = true;
400
- if ('srcdoc' in iframe) iframe.srcdoc = importMapTest;
401
- else iframe.contentDocument.write(importMapTest);
402
- // retrigger onload for Safari only if necessary
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 = null;
464
- if (typeof opts === 'object' && typeof opts.with === 'object' && typeof opts.with.type === 'string') {
465
- source = `export{default}from'${url}'with{type:"${opts.with.type}"}`;
466
- url += '?entry';
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' }, null, null);
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
- (!jsonModulesEnabled || supportsJsonType) &&
543
- (!cssModulesEnabled || supportsCssType) &&
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, null, source);
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 (!shimMode && !load.n && !load.N ? import(load.u) : dynamicImport(load.b, load.u));
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 = stripAssertion ? statementEnd : end + 1;
783
+ lastIndex = keepAssertion ? end + 1 : statementEnd;
783
784
  }
784
785
  // import.meta
785
786
  else if (dynamicImportIndex === -2) {
@@ -936,14 +937,13 @@
936
937
  )});export default s;`,
937
938
  t: 'css'
938
939
  };
939
- } else if (
940
- (shimMode || typescriptEnabled) &&
941
- (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts'))
942
- ) {
940
+ } else if (tsContentType.test(contentType) || url.endsWith('.ts') || url.endsWith('.mts')) {
943
941
  const source = await res.text();
944
942
  if (!esmsTsTransform) await initTs();
945
943
  const transformed = esmsTsTransform(source, url);
946
- return { r, s: transformed === undefined ? source : transformed, t: transformed !== undefined ? 'ts' : 'js' };
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' };
947
947
  } else
948
948
  throw Error(
949
949
  `Unsupported Content-Type "${contentType}" loading ${url}${fromParent(parent)}. Modules must be served with a valid MIME type like application/javascript.`
@@ -951,13 +951,7 @@
951
951
  }
952
952
 
953
953
  function isUnsupportedType(type) {
954
- if (
955
- (type === 'css' && !cssModulesEnabled) ||
956
- (type === 'json' && !jsonModulesEnabled) ||
957
- (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) ||
958
- (type === 'ts' && !typescriptEnabled)
959
- )
960
- throw featErr(`${type}-modules`);
954
+ if (type === 'wasm' && !wasmInstancePhaseEnabled && !wasmSourcePhaseEnabled) throw featErr(`wasm-modules`);
961
955
  return (
962
956
  (type === 'css' && !supportsCssType) ||
963
957
  (type === 'json' && !supportsJsonType) ||
@@ -993,9 +987,9 @@
993
987
  b: undefined,
994
988
  // shellUrl
995
989
  s: undefined,
996
- // needsShim
990
+ // needsShim: does it fail execution in the current native loader?
997
991
  n: false,
998
- // shouldShim
992
+ // shouldShim: does it need to be loaded by the polyfill loader?
999
993
  N: false,
1000
994
  // type
1001
995
  t: null,
@@ -1003,7 +997,7 @@
1003
997
  m: null
1004
998
  };
1005
999
  load.f = (async () => {
1006
- if (!load.S) {
1000
+ if (load.S === undefined) {
1007
1001
  // preload fetch options override fetch options (race)
1008
1002
  ({ r: load.r, s: load.S, t: load.t } = await (fetchCache[url] || fetchModule(url, fetchOpts, parent)));
1009
1003
  if (!load.n && load.t !== 'js' && !shimMode && isUnsupportedType(load.t)) {
@@ -1031,17 +1025,25 @@
1031
1025
  load.L = load.f.then(async () => {
1032
1026
  let childFetchOpts = fetchOpts;
1033
1027
  load.d = load.a[0]
1034
- .map(({ n, d, t, a }) => {
1028
+ .map(({ n, d, t, a, se }) => {
1035
1029
  const phaseImport = t >= 4;
1036
1030
  const sourcePhase = phaseImport && t < 6;
1037
1031
  if (phaseImport) {
1038
1032
  if (!shimMode && (sourcePhase ? !wasmSourcePhaseEnabled : !deferPhaseEnabled))
1039
- throw featErr(sourcePhase ? 'source-phase' : 'defer-phase');
1033
+ throw featErr(sourcePhase ? 'wasm-module-sources' : 'import-defer');
1040
1034
  if (!sourcePhase || !supportsWasmSourcePhase) load.n = true;
1041
1035
  }
1042
- if (a > 0) {
1043
- if (!shimMode && !cssModulesEnabled && !jsonModulesEnabled) throw featErr('css-modules / json-modules');
1044
- if (!supportsCssType && !supportsJsonType) load.n = true;
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
+ }
1045
1047
  }
1046
1048
  if (d !== -1 || !n) return;
1047
1049
  const resolved = resolve(n, load.r || load.u);
@@ -1050,7 +1052,9 @@
1050
1052
  if (d !== -1) return;
1051
1053
  if (skip && skip(resolved.r) && !sourcePhase) return { l: { b: resolved.r }, s: false };
1052
1054
  if (childFetchOpts.integrity) childFetchOpts = Object.assign({}, childFetchOpts, { integrity: undefined });
1053
- const child = { l: getOrCreateLoad(resolved.r, childFetchOpts, load.r, null), s: sourcePhase };
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;
1054
1058
  if (!child.s) linkLoad(child.l, fetchOpts);
1055
1059
  // load, sourcePhase
1056
1060
  return child;
@@ -1157,42 +1161,48 @@
1157
1161
 
1158
1162
  function processScript(script, ready = readyStateCompleteCnt > 0) {
1159
1163
  if (epCheck(script, ready)) return;
1160
- if (script.lang === 'ts' && !script.src) {
1161
- const source = script.innerHTML;
1162
- return initTs()
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())
1163
1176
  .then(() => {
1164
- const transformed = esmsTsTransform(source, baseUrl);
1177
+ const transformed = esmsTsTransform(script.innerHTML, baseUrl);
1165
1178
  if (transformed !== undefined) {
1166
1179
  onpolyfill();
1167
1180
  firstPolyfillLoad = false;
1168
1181
  }
1169
1182
  return topLevelLoad(
1170
- baseUrl,
1183
+ script.src || baseUrl,
1171
1184
  getFetchOpts(script),
1172
- transformed === undefined ? source : transformed,
1173
- transformed === undefined,
1174
- undefined
1185
+ transformed === undefined ? script.innerHTML : transformed,
1186
+ !shimMode && transformed === undefined,
1187
+ isBlockingReadyScript && lastStaticLoadPromise,
1188
+ true
1175
1189
  );
1176
1190
  })
1177
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);
1178
1201
  }
1179
- // does this load block readystate complete
1180
- const isBlockingReadyScript = script.getAttribute('async') === null && readyStateCompleteCnt > 0;
1181
- // does this load block DOMContentLoaded
1182
- const isDomContentLoadedScript = domContentLoadedCnt > 0;
1183
- const isLoadScript = loadCnt > 0;
1184
- if (isLoadScript) loadCnt++;
1185
- if (isBlockingReadyScript) readyStateCompleteCnt++;
1186
- if (isDomContentLoadedScript) domContentLoadedCnt++;
1187
- const loadPromise = topLevelLoad(
1188
- script.src || baseUrl,
1189
- getFetchOpts(script),
1190
- !script.src && script.innerHTML,
1191
- !shimMode,
1192
- isBlockingReadyScript && lastStaticLoadPromise
1193
- ).catch(throwError);
1194
1202
  if (!noLoadEventRetriggers) loadPromise.then(() => script.dispatchEvent(new Event('load')));
1195
- if (isBlockingReadyScript) lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1203
+ if (isBlockingReadyScript && !ts) {
1204
+ lastStaticLoadPromise = loadPromise.then(readyStateCompleteCheck);
1205
+ }
1196
1206
  if (isDomContentLoadedScript) loadPromise.then(domContentLoadedCheck);
1197
1207
  if (isLoadScript) loadPromise.then(loadCheck);
1198
1208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "es-module-shims",
3
- "version": "2.1.2",
3
+ "version": "2.2.0",
4
4
  "description": "Shims for the latest ES module features",
5
5
  "main": "dist/es-module-shims.js",
6
6
  "exports": {