Skip to content

Commit c2ab9bc

Browse files
authored
Revert "Update ES Module Shims to 1.7.3 (#188)" (#189)
This reverts commit 952f000.
1 parent 185f4f7 commit c2ab9bc

File tree

3 files changed

+70
-91
lines changed

3 files changed

+70
-91
lines changed

app/assets/javascripts/es-module-shims.js

Lines changed: 68 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* ES Module Shims 1.7.3 */
1+
/* ES Module Shims 1.7.2 */
22
(function () {
33

44
const hasWindow = typeof window !== 'undefined';
@@ -596,109 +596,88 @@
596596
// edge doesnt execute sibling in order, so we fix this up by ensuring all previous executions are explicit dependencies
597597
let resolvedSource = edge && lastLoad ? `import '${lastLoad}';` : '';
598598

599-
// once all deps have loaded we can inline the dependency resolution blobs
600-
// and define this blob
601-
let lastIndex = 0, depIndex = 0, dynamicImportEndStack = [];
602-
function pushStringTo (originalIndex) {
603-
while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
604-
const dynamicImportEnd = dynamicImportEndStack.pop();
605-
resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
606-
lastIndex = dynamicImportEnd;
607-
}
608-
resolvedSource += source.slice(lastIndex, originalIndex);
609-
lastIndex = originalIndex;
599+
if (!imports.length) {
600+
resolvedSource += source;
610601
}
611-
612-
for (const { s: start, ss: statementStart, se: statementEnd, d: dynamicImportIndex } of imports) {
613-
// dependency source replacements
614-
if (dynamicImportIndex === -1) {
615-
let depLoad = load.d[depIndex++], blobUrl = depLoad.b, cycleShell = !blobUrl;
616-
if (cycleShell) {
617-
// circular shell creation
618-
if (!(blobUrl = depLoad.s)) {
619-
blobUrl = depLoad.s = createBlob(`export function u$_(m){${
620-
depLoad.a[1].map(({ s, e }, i) => {
621-
const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
622-
return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
623-
}).join(',')
624-
}}${
625-
depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
626-
}export {${
627-
depLoad.a[1].map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`).join(',')
628-
}}\n//# sourceURL=${depLoad.r}?cycle`);
629-
}
602+
else {
603+
// once all deps have loaded we can inline the dependency resolution blobs
604+
// and define this blob
605+
let lastIndex = 0, depIndex = 0, dynamicImportEndStack = [];
606+
function pushStringTo (originalIndex) {
607+
while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
608+
const dynamicImportEnd = dynamicImportEndStack.pop();
609+
resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
610+
lastIndex = dynamicImportEnd;
630611
}
612+
resolvedSource += source.slice(lastIndex, originalIndex);
613+
lastIndex = originalIndex;
614+
}
615+
for (const { s: start, ss: statementStart, se: statementEnd, d: dynamicImportIndex } of imports) {
616+
// dependency source replacements
617+
if (dynamicImportIndex === -1) {
618+
let depLoad = load.d[depIndex++], blobUrl = depLoad.b, cycleShell = !blobUrl;
619+
if (cycleShell) {
620+
// circular shell creation
621+
if (!(blobUrl = depLoad.s)) {
622+
blobUrl = depLoad.s = createBlob(`export function u$_(m){${
623+
depLoad.a[1].map(({ s, e }, i) => {
624+
const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
625+
return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
626+
}).join(',')
627+
}}${
628+
depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
629+
}export {${
630+
depLoad.a[1].map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`).join(',')
631+
}}\n//# sourceURL=${depLoad.r}?cycle`);
632+
}
633+
}
631634

632-
pushStringTo(start - 1);
633-
resolvedSource += `/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
635+
pushStringTo(start - 1);
636+
resolvedSource += `/*${source.slice(start - 1, statementEnd)}*/${urlJsString(blobUrl)}`;
634637

635-
// circular shell execution
636-
if (!cycleShell && depLoad.s) {
637-
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
638-
depLoad.s = undefined;
638+
// circular shell execution
639+
if (!cycleShell && depLoad.s) {
640+
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
641+
depLoad.s = undefined;
642+
}
643+
lastIndex = statementEnd;
644+
}
645+
// import.meta
646+
else if (dynamicImportIndex === -2) {
647+
load.m = { url: load.r, resolve: metaResolve };
648+
metaHook(load.m, load.u);
649+
pushStringTo(start);
650+
resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
651+
lastIndex = statementEnd;
652+
}
653+
// dynamic import
654+
else {
655+
pushStringTo(statementStart + 6);
656+
resolvedSource += `Shim(`;
657+
dynamicImportEndStack.push(statementEnd - 1);
658+
lastIndex = start;
639659
}
640-
lastIndex = statementEnd;
641-
}
642-
// import.meta
643-
else if (dynamicImportIndex === -2) {
644-
load.m = { url: load.r, resolve: metaResolve };
645-
metaHook(load.m, load.u);
646-
pushStringTo(start);
647-
resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
648-
lastIndex = statementEnd;
649-
}
650-
// dynamic import
651-
else {
652-
pushStringTo(statementStart + 6);
653-
resolvedSource += `Shim(`;
654-
dynamicImportEndStack.push(statementEnd - 1);
655-
lastIndex = start;
656660
}
657-
}
658-
659-
// support progressive cycle binding updates (try statement avoids tdz errors)
660-
if (load.s)
661-
resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports.filter(e => e.ln).map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`).join(',')}})}catch(_){};\n`;
662-
663-
function pushSourceURL (commentPrefix, commentStart) {
664-
const urlStart = commentStart + commentPrefix.length;
665-
const commentEnd = source.indexOf('\n', urlStart);
666-
const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
667-
pushStringTo(urlStart);
668-
resolvedSource += new URL(source.slice(urlStart, urlEnd), load.r).href;
669-
lastIndex = urlEnd;
670-
}
671-
672-
let sourceURLCommentStart = source.lastIndexOf(sourceURLCommentPrefix);
673-
let sourceMapURLCommentStart = source.lastIndexOf(sourceMapURLCommentPrefix);
674661

675-
// ignore sourceMap comments before already spliced code
676-
if (sourceURLCommentStart < lastIndex) sourceURLCommentStart = -1;
677-
if (sourceMapURLCommentStart < lastIndex) sourceMapURLCommentStart = -1;
662+
// support progressive cycle binding updates (try statement avoids tdz errors)
663+
if (load.s)
664+
resolvedSource += `\n;import{u$_}from'${load.s}';try{u$_({${exports.filter(e => e.ln).map(({ s, e, ln }) => `${source.slice(s, e)}:${ln}`).join(',')}})}catch(_){};\n`;
678665

679-
// sourceURL first / only
680-
if (sourceURLCommentStart !== -1 && (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)) {
681-
pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
666+
pushStringTo(source.length);
682667
}
683-
// sourceMappingURL
684-
if (sourceMapURLCommentStart !== -1) {
685-
pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
686-
// sourceURL last
687-
if (sourceURLCommentStart !== -1 && (sourceURLCommentStart > sourceMapURLCommentStart))
688-
pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
689-
}
690-
691-
pushStringTo(source.length);
692668

693-
if (sourceURLCommentStart === -1)
694-
resolvedSource += sourceURLCommentPrefix + load.r;
669+
let hasSourceURL = false;
670+
resolvedSource = resolvedSource.replace(sourceMapURLRegEx, (match, isMapping, url) => (hasSourceURL = !isMapping, match.replace(url, () => new URL(url, load.r))));
671+
if (!hasSourceURL)
672+
resolvedSource += '\n//# sourceURL=' + load.r;
695673

696674
load.b = lastLoad = createBlob(resolvedSource);
697675
load.S = undefined;
698676
}
699677

700-
const sourceURLCommentPrefix = '\n//# sourceURL=';
701-
const sourceMapURLCommentPrefix = '\n//# sourceMappingURL=';
678+
// ; and // trailer support added for Ruby on Rails 7 source maps compatibility
679+
// https://github.com/guybedford/es-module-shims/issues/228
680+
const sourceMapURLRegEx = /\n\/\/# source(Mapping)?URL=([^\n]+)\s*((;|\/\/[^#][^\n]*)\s*)*$/;
702681

703682
const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
704683
const jsonContentType = /^(text|application)\/json(;|$)/;

app/assets/javascripts/es-module-shims.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)