|
1 |
| -/* ES Module Shims 1.3.6 */ |
| 1 | +/* ES Module Shims 1.4.0 */ |
2 | 2 | (function () {
|
3 | 3 |
|
4 | 4 | const edge = navigator.userAgent.match(/Edge\/\d\d\.\d+$/);
|
|
130 | 130 | for (let p in packages) {
|
131 | 131 | const resolvedLhs = resolveIfNotPlainOrUrl(p, baseUrl) || p;
|
132 | 132 | if (outPackages[resolvedLhs]) {
|
133 |
| - throw new Error(`Dynamic import map rejected: Overrides entry "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`); |
| 133 | + throw Error(`Rejected map override "${resolvedLhs}" from ${outPackages[resolvedLhs]} to ${packages[resolvedLhs]}.`); |
134 | 134 | }
|
135 | 135 | let target = packages[p];
|
136 |
| - if (typeof target !== 'string') |
| 136 | + if (typeof target !== 'string') |
137 | 137 | continue;
|
138 | 138 | const mapped = resolveImportMap(parentMap, resolveIfNotPlainOrUrl(target, baseUrl) || target, baseUrl);
|
139 | 139 | if (mapped) {
|
140 | 140 | outPackages[resolvedLhs] = mapped;
|
141 | 141 | continue;
|
142 | 142 | }
|
143 |
| - targetWarning(p, packages[p], 'bare specifier did not resolve'); |
| 143 | + console.warn(`Mapping "${p}" -> "${packages[p]}" does not resolve`); |
144 | 144 | }
|
145 | 145 | }
|
146 | 146 |
|
|
175 | 175 | if (pkgName) {
|
176 | 176 | const pkg = packages[pkgName];
|
177 | 177 | if (pkg === null) return;
|
178 |
| - if (id.length > pkgName.length && pkg[pkg.length - 1] !== '/') |
179 |
| - targetWarning(pkgName, pkg, "should have a trailing '/'"); |
180 |
| - else |
181 |
| - return pkg + id.slice(pkgName.length); |
| 178 | + return pkg + id.slice(pkgName.length); |
182 | 179 | }
|
183 | 180 | }
|
184 | 181 |
|
185 |
| - function targetWarning (match, target, msg) { |
186 |
| - console.warn("Package target " + msg + ", resolving target '" + target + "' for " + match); |
187 |
| - } |
188 |
| - |
189 | 182 | function resolveImportMap (importMap, resolvedOrPlain, parentUrl) {
|
190 | 183 | let scopeUrl = parentUrl && getMatch(parentUrl, importMap.scopes);
|
191 | 184 | while (scopeUrl) {
|
|
215 | 208 | }
|
216 | 209 |
|
217 | 210 | const onerror = globalHook(esmsInitOptions.onerror || noop);
|
218 |
| - const onpolyfill = globalHook(esmsInitOptions.onpolyfill || noop); |
| 211 | + const onpolyfill = esmsInitOptions.onpolyfill ? globalHook(esmsInitOptions.onpolyfill) : () => console.info(`OK: "Uncaught TypeError" module failure has been polyfilled`); |
219 | 212 |
|
220 |
| - const { revokeBlobURLs, noLoadEventRetriggers } = esmsInitOptions; |
| 213 | + const { revokeBlobURLs, noLoadEventRetriggers, enforceIntegrity } = esmsInitOptions; |
221 | 214 |
|
222 | 215 | const fetchHook = esmsInitOptions.fetch ? globalHook(esmsInitOptions.fetch) : fetch;
|
223 | 216 |
|
|
340 | 333 | const initPromise = featureDetectionPromise.then(() => {
|
341 | 334 | // shim mode is determined on initialization, no late shim mode
|
342 | 335 | if (!shimMode) {
|
343 |
| - let seenScript = false; |
344 |
| - for (const script of document.querySelectorAll('script[type="module-shim"],script[type="importmap-shim"],script[type="module"],script[type="importmap"]')) { |
345 |
| - if (!seenScript && script.type === 'module') |
346 |
| - seenScript = true; |
347 |
| - if (script.type.endsWith('-shim')) { |
348 |
| - setShimMode(); |
349 |
| - break; |
350 |
| - } |
351 |
| - if (seenScript && script.type === 'importmap') { |
352 |
| - importMapSrcOrLazy = true; |
353 |
| - break; |
| 336 | + if (document.querySelectorAll('script[type=module-shim],script[type=importmap-shim],link[rel=modulepreload-shim]').length) { |
| 337 | + setShimMode(); |
| 338 | + } |
| 339 | + else { |
| 340 | + let seenScript = false; |
| 341 | + for (const script of document.querySelectorAll('script[type=module],script[type=importmap]')) { |
| 342 | + if (!seenScript) { |
| 343 | + if (script.type === 'module') |
| 344 | + seenScript = true; |
| 345 | + } |
| 346 | + else if (script.type === 'importmap') { |
| 347 | + importMapSrcOrLazy = true; |
| 348 | + break; |
| 349 | + } |
354 | 350 | }
|
355 | 351 | }
|
356 | 352 | }
|
357 | 353 | baselinePassthrough = supportsDynamicImport && supportsImportMeta && supportsImportMaps && (!jsonModulesEnabled || supportsJsonAssertions) && (!cssModulesEnabled || supportsCssAssertions) && !importMapSrcOrLazy && !false;
|
358 |
| - if (!baselinePassthrough) onpolyfill(); |
359 | 354 | if (shimMode || !baselinePassthrough) {
|
360 | 355 | new MutationObserver(mutations => {
|
361 | 356 | for (const mutation of mutations) {
|
362 | 357 | if (mutation.type !== 'childList') continue;
|
363 | 358 | for (const node of mutation.addedNodes) {
|
364 | 359 | if (node.tagName === 'SCRIPT') {
|
365 |
| - if (!shimMode && node.type === 'module' || shimMode && node.type === 'module-shim') |
| 360 | + if (node.type === (shimMode ? 'module-shim' : 'module')) |
366 | 361 | processScript(node);
|
367 |
| - if (!shimMode && node.type === 'importmap' || shimMode && node.type === 'importmap-shim') |
| 362 | + if (node.type === (shimMode ? 'importmap-shim' : 'importmap')) |
368 | 363 | processImportMap(node);
|
369 | 364 | }
|
370 |
| - else if (node.tagName === 'LINK' && node.rel === 'modulepreload') |
| 365 | + else if (node.tagName === 'LINK' && node.rel === (shimMode ? 'modulepreload-shim' : 'modulepreload')) |
371 | 366 | processPreload(node);
|
372 | 367 | }
|
373 | 368 | }
|
|
378 | 373 | }
|
379 | 374 | });
|
380 | 375 | let importMapPromise = initPromise;
|
381 |
| - |
| 376 | + let firstPolyfillLoad = true; |
382 | 377 | let acceptingImportMaps = true;
|
| 378 | + |
383 | 379 | async function topLevelLoad (url, fetchOpts, source, nativelyLoaded, lastStaticLoadPromise) {
|
384 | 380 | if (!shimMode)
|
385 | 381 | acceptingImportMaps = false;
|
|
403 | 399 | if (revokeBlobURLs) revokeObjectURLs(Object.keys(seen));
|
404 | 400 | return module;
|
405 | 401 | }
|
| 402 | + if (firstPolyfillLoad && !shimMode && load.n && nativelyLoaded) { |
| 403 | + onpolyfill(); |
| 404 | + firstPolyfillLoad = false; |
| 405 | + } |
406 | 406 | const module = await dynamicImport(!shimMode && !load.n && nativelyLoaded ? load.u : load.b, { errUrl: load.u });
|
407 | 407 | // if the top-level load is a shell, run its update function
|
408 | 408 | if (load.s)
|
|
544 | 544 | const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
|
545 | 545 | const jsonContentType = /^(text|application)\/json(;|$)/;
|
546 | 546 | const cssContentType = /^(text|application)\/css(;|$)/;
|
547 |
| - const wasmContentType = /^application\/wasm(;|$)/; |
548 | 547 |
|
549 | 548 | const cssUrlRegEx = /url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g;
|
550 | 549 |
|
|
562 | 561 | }
|
563 | 562 |
|
564 | 563 | async function doFetch (url, fetchOpts) {
|
| 564 | + if (enforceIntegrity && !fetchOpts.integrity) |
| 565 | + throw Error(`No integrity for ${url}`); |
565 | 566 | const poolQueue = pushFetchPool();
|
566 | 567 | if (poolQueue) await poolQueue;
|
567 | 568 | try {
|
|
571 | 572 | popFetchPool();
|
572 | 573 | }
|
573 | 574 | if (!res.ok)
|
574 |
| - throw new Error(`${res.status} ${res.statusText} ${res.url}`); |
| 575 | + throw Error(`${res.status} ${res.statusText} ${res.url}`); |
575 | 576 | const contentType = res.headers.get('content-type');
|
576 | 577 | if (jsContentType.test(contentType))
|
577 | 578 | return { r: res.url, s: await res.text(), t: 'js' };
|
|
581 | 582 | return { r: res.url, s: `var s=new CSSStyleSheet();s.replaceSync(${
|
582 | 583 | JSON.stringify((await res.text()).replace(cssUrlRegEx, (_match, quotes, relUrl1, relUrl2) => `url(${quotes}${resolveUrl(relUrl1 || relUrl2, url)}${quotes})`))
|
583 | 584 | });export default s;`, t: 'css' };
|
584 |
| - else if (wasmContentType.test(contentType)) |
585 |
| - throw new Error('WASM modules not supported'); |
586 | 585 | else
|
587 |
| - throw new Error(`Unknown Content-Type "${contentType}"`); |
| 586 | + throw Error(`Unsupported Content-Type "${contentType}"`); |
588 | 587 | }
|
589 | 588 |
|
590 | 589 | function getOrCreateLoad (url, fetchOpts, source) {
|
|
624 | 623 | ({ r: load.r, s: source, t } = await (fetchCache[url] || doFetch(url, fetchOpts)));
|
625 | 624 | if (t && !shimMode) {
|
626 | 625 | if (t === 'css' && !cssModulesEnabled || t === 'json' && !jsonModulesEnabled)
|
627 |
| - throw new Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`); |
| 626 | + throw Error(`${t}-modules require <script type="esms-options">{ "polyfillEnable": ["${t}-modules"] }<${''}/script>`); |
628 | 627 | if (t === 'css' && !supportsCssAssertions || t === 'json' && !supportsJsonAssertions)
|
629 | 628 | load.n = true;
|
630 | 629 | }
|
|
663 | 662 | }
|
664 | 663 |
|
665 | 664 | function processScriptsAndPreloads () {
|
666 |
| - for (const script of document.querySelectorAll(shimMode ? 'script[type="module-shim"]' : 'script[type="module"]')) |
| 665 | + for (const script of document.querySelectorAll(shimMode ? 'script[type=module-shim]' : 'script[type=module]')) |
667 | 666 | processScript(script);
|
668 |
| - for (const link of document.querySelectorAll('link[rel="modulepreload"]')) |
| 667 | + for (const link of document.querySelectorAll(shimMode ? 'link[rel=modulepreload-shim]' : 'link[rel=modulepreload]')) |
669 | 668 | processPreload(link);
|
670 | 669 | }
|
671 | 670 |
|
|
763 | 762 | if (isDomContentLoadedScript) domContentLoadedCnt++;
|
764 | 763 | const blocks = script.getAttribute('async') === null && isReadyScript;
|
765 | 764 | const loadPromise = topLevelLoad(script.src || `${baseUrl}?${id++}`, getFetchOpts(script), !script.src && script.innerHTML, !shimMode, blocks && lastStaticLoadPromise).catch(e => {
|
766 |
| - setTimeout(() => { throw e }); |
| 765 | + // This used to be a setTimeout(() => { throw e }) but this breaks Safari stacks |
| 766 | + console.error(e); |
767 | 767 | onerror(e);
|
768 | 768 | });
|
769 | 769 | if (blocks)
|
|
0 commit comments