|
1 |
| -/* ES Module Shims 1.5.8 */ |
| 1 | +/* ES Module Shims 1.5.9 */ |
2 | 2 | (function () {
|
3 | 3 |
|
4 | 4 | const hasWindow = typeof window !== 'undefined';
|
|
16 | 16 | const importHook = globalHook(shimMode && esmsInitOptions.onimport);
|
17 | 17 | const resolveHook = globalHook(shimMode && esmsInitOptions.resolve);
|
18 | 18 | let fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
19 |
| - const metaHook = esmsInitOptions.meta ? globalHook(shimModule && esmsInitOptions.meta) : noop; |
| 19 | + const metaHook = esmsInitOptions.meta ? globalHook(shimMode && esmsInitOptions.meta) : noop; |
20 | 20 |
|
21 | 21 | const skip = esmsInitOptions.skip ? new RegExp(esmsInitOptions.skip) : null;
|
22 | 22 |
|
|
44 | 44 | const cssModulesEnabled = enable.includes('css-modules');
|
45 | 45 | const jsonModulesEnabled = enable.includes('json-modules');
|
46 | 46 |
|
47 |
| - function setShimMode () { |
48 |
| - shimMode = true; |
49 |
| - } |
50 |
| - |
51 | 47 | const edge = !navigator.userAgentData && !!navigator.userAgent.match(/Edge\/\d+\.\d+/);
|
52 | 48 |
|
53 | 49 | const baseUrl = hasDocument
|
|
66 | 62 |
|
67 | 63 | function fromParent (parent) {
|
68 | 64 | return parent ? ` imported from ${parent}` : '';
|
| 65 | + } |
| 66 | + |
| 67 | + let importMapSrcOrLazy = false; |
| 68 | + |
| 69 | + function setImportMapSrcOrLazy () { |
| 70 | + importMapSrcOrLazy = true; |
| 71 | + } |
| 72 | + |
| 73 | + // shim mode is determined on initialization, no late shim mode |
| 74 | + if (!shimMode) { |
| 75 | + if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) { |
| 76 | + shimMode = true; |
| 77 | + } |
| 78 | + else { |
| 79 | + let seenScript = false; |
| 80 | + for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) { |
| 81 | + if (!seenScript) { |
| 82 | + if (script.type === 'module' && !script.ep) |
| 83 | + seenScript = true; |
| 84 | + } |
| 85 | + else if (script.type === 'importmap' && seenScript) { |
| 86 | + importMapSrcOrLazy = true; |
| 87 | + break; |
| 88 | + } |
| 89 | + } |
| 90 | + } |
69 | 91 | }
|
70 | 92 |
|
71 | 93 | const backslashRegEx = /\\/g;
|
|
243 | 265 | function dynamicImportScript (url, { errUrl = url } = {}) {
|
244 | 266 | err = undefined;
|
245 | 267 | const src = createBlob(`import*as m from'${url}';self._esmsi=m`);
|
246 |
| - const s = Object.assign(document.createElement('script'), { type: 'module', src }); |
| 268 | + const s = Object.assign(document.createElement('script'), { type: 'module', src, ep: true }); |
247 | 269 | s.setAttribute('nonce', nonce);
|
248 | 270 | s.setAttribute('noshim', '');
|
249 | 271 | const p = new Promise((resolve, reject) => {
|
|
402 | 424 | }
|
403 | 425 |
|
404 | 426 | let importMap = { imports: {}, scopes: {} };
|
405 |
| - let importMapSrcOrLazy = false; |
406 | 427 | let baselinePassthrough;
|
407 | 428 |
|
408 | 429 | const initPromise = featureDetectionPromise.then(() => {
|
409 |
| - // shim mode is determined on initialization, no late shim mode |
410 |
| - if (!shimMode) { |
411 |
| - if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) { |
412 |
| - setShimMode(); |
413 |
| - } |
414 |
| - else { |
415 |
| - let seenScript = false; |
416 |
| - for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) { |
417 |
| - if (!seenScript) { |
418 |
| - if (script.type === 'module') |
419 |
| - seenScript = true; |
420 |
| - } |
421 |
| - else if (script.type === 'importmap') { |
422 |
| - importMapSrcOrLazy = true; |
423 |
| - break; |
424 |
| - } |
425 |
| - } |
426 |
| - } |
427 |
| - } |
428 | 430 | baselinePassthrough = esmsInitOptions.polyfillEnable !== true && supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
429 | 431 | if (hasDocument) {
|
430 | 432 | if (!supportsImportMaps) {
|
431 | 433 | const supports = HTMLScriptElement.supports || (type => type === 'classic' || type === 'module');
|
432 | 434 | HTMLScriptElement.supports = type => type === 'importmap' || supports(type);
|
433 | 435 | }
|
434 |
| - |
435 | 436 | if (shimMode || !baselinePassthrough) {
|
436 | 437 | new MutationObserver(mutations => {
|
437 | 438 | for (const mutation of mutations) {
|
|
476 | 477 | if (!shimMode)
|
477 | 478 | acceptingImportMaps = false;
|
478 | 479 | await importMapPromise;
|
479 |
| - if (importHook) await importHook(id, typeof args[1] !== 'string' ? args[1] : {}, parentUrl); |
| 480 | + if (importHook) await importHook(url, typeof fetchOpts !== 'string' ? fetchOpts : {}, ''); |
480 | 481 | // early analysis opt-out - no need to even fetch if we have feature support
|
481 | 482 | if (!shimMode && baselinePassthrough) {
|
482 | 483 | // for polyfill case, only dynamic import needs a return value here, and dynamic import will never pass nativelyLoaded
|
|
824 | 825 | if (script.src) {
|
825 | 826 | if (!shimMode)
|
826 | 827 | return;
|
827 |
| - importMapSrcOrLazy = true; |
| 828 | + setImportMapSrcOrLazy(); |
828 | 829 | }
|
829 | 830 | if (acceptingImportMaps) {
|
830 | 831 | importMapPromise = importMapPromise
|
|
0 commit comments