Skip to content

Revert "Update ES Module Shims to 1.7.3" #189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 68 additions & 89 deletions app/assets/javascripts/es-module-shims.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* ES Module Shims 1.7.3 */
/* ES Module Shims 1.7.2 */
(function () {

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

// once all deps have loaded we can inline the dependency resolution blobs
// and define this blob
let lastIndex = 0, depIndex = 0, dynamicImportEndStack = [];
function pushStringTo (originalIndex) {
while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
const dynamicImportEnd = dynamicImportEndStack.pop();
resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
lastIndex = dynamicImportEnd;
}
resolvedSource += source.slice(lastIndex, originalIndex);
lastIndex = originalIndex;
if (!imports.length) {
resolvedSource += source;
}

for (const { s: start, ss: statementStart, se: statementEnd, d: dynamicImportIndex } of imports) {
// dependency source replacements
if (dynamicImportIndex === -1) {
let depLoad = load.d[depIndex++], blobUrl = depLoad.b, cycleShell = !blobUrl;
if (cycleShell) {
// circular shell creation
if (!(blobUrl = depLoad.s)) {
blobUrl = depLoad.s = createBlob(`export function u$_(m){${
depLoad.a[1].map(({ s, e }, i) => {
const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
}).join(',')
}}${
depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
}export {${
depLoad.a[1].map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`).join(',')
}}\n//# sourceURL=${depLoad.r}?cycle`);
}
else {
// once all deps have loaded we can inline the dependency resolution blobs
// and define this blob
let lastIndex = 0, depIndex = 0, dynamicImportEndStack = [];
function pushStringTo (originalIndex) {
while (dynamicImportEndStack[dynamicImportEndStack.length - 1] < originalIndex) {
const dynamicImportEnd = dynamicImportEndStack.pop();
resolvedSource += `${source.slice(lastIndex, dynamicImportEnd)}, ${urlJsString(load.r)}`;
lastIndex = dynamicImportEnd;
}
resolvedSource += source.slice(lastIndex, originalIndex);
lastIndex = originalIndex;
}
for (const { s: start, ss: statementStart, se: statementEnd, d: dynamicImportIndex } of imports) {
// dependency source replacements
if (dynamicImportIndex === -1) {
let depLoad = load.d[depIndex++], blobUrl = depLoad.b, cycleShell = !blobUrl;
if (cycleShell) {
// circular shell creation
if (!(blobUrl = depLoad.s)) {
blobUrl = depLoad.s = createBlob(`export function u$_(m){${
depLoad.a[1].map(({ s, e }, i) => {
const q = depLoad.S[s] === '"' || depLoad.S[s] === "'";
return `e$_${i}=m${q ? `[` : '.'}${depLoad.S.slice(s, e)}${q ? `]` : ''}`;
}).join(',')
}}${
depLoad.a[1].length ? `let ${depLoad.a[1].map((_, i) => `e$_${i}`).join(',')};` : ''
}export {${
depLoad.a[1].map(({ s, e }, i) => `e$_${i} as ${depLoad.S.slice(s, e)}`).join(',')
}}\n//# sourceURL=${depLoad.r}?cycle`);
}
}

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

// circular shell execution
if (!cycleShell && depLoad.s) {
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
depLoad.s = undefined;
// circular shell execution
if (!cycleShell && depLoad.s) {
resolvedSource += `;import*as m$_${depIndex} from'${depLoad.b}';import{u$_ as u$_${depIndex}}from'${depLoad.s}';u$_${depIndex}(m$_${depIndex})`;
depLoad.s = undefined;
}
lastIndex = statementEnd;
}
// import.meta
else if (dynamicImportIndex === -2) {
load.m = { url: load.r, resolve: metaResolve };
metaHook(load.m, load.u);
pushStringTo(start);
resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
lastIndex = statementEnd;
}
// dynamic import
else {
pushStringTo(statementStart + 6);
resolvedSource += `Shim(`;
dynamicImportEndStack.push(statementEnd - 1);
lastIndex = start;
}
lastIndex = statementEnd;
}
// import.meta
else if (dynamicImportIndex === -2) {
load.m = { url: load.r, resolve: metaResolve };
metaHook(load.m, load.u);
pushStringTo(start);
resolvedSource += `importShim._r[${urlJsString(load.u)}].m`;
lastIndex = statementEnd;
}
// dynamic import
else {
pushStringTo(statementStart + 6);
resolvedSource += `Shim(`;
dynamicImportEndStack.push(statementEnd - 1);
lastIndex = start;
}
}

// support progressive cycle binding updates (try statement avoids tdz errors)
if (load.s)
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`;

function pushSourceURL (commentPrefix, commentStart) {
const urlStart = commentStart + commentPrefix.length;
const commentEnd = source.indexOf('\n', urlStart);
const urlEnd = commentEnd !== -1 ? commentEnd : source.length;
pushStringTo(urlStart);
resolvedSource += new URL(source.slice(urlStart, urlEnd), load.r).href;
lastIndex = urlEnd;
}

let sourceURLCommentStart = source.lastIndexOf(sourceURLCommentPrefix);
let sourceMapURLCommentStart = source.lastIndexOf(sourceMapURLCommentPrefix);

// ignore sourceMap comments before already spliced code
if (sourceURLCommentStart < lastIndex) sourceURLCommentStart = -1;
if (sourceMapURLCommentStart < lastIndex) sourceMapURLCommentStart = -1;
// support progressive cycle binding updates (try statement avoids tdz errors)
if (load.s)
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`;

// sourceURL first / only
if (sourceURLCommentStart !== -1 && (sourceMapURLCommentStart === -1 || sourceMapURLCommentStart > sourceURLCommentStart)) {
pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
pushStringTo(source.length);
}
// sourceMappingURL
if (sourceMapURLCommentStart !== -1) {
pushSourceURL(sourceMapURLCommentPrefix, sourceMapURLCommentStart);
// sourceURL last
if (sourceURLCommentStart !== -1 && (sourceURLCommentStart > sourceMapURLCommentStart))
pushSourceURL(sourceURLCommentPrefix, sourceURLCommentStart);
}

pushStringTo(source.length);

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

load.b = lastLoad = createBlob(resolvedSource);
load.S = undefined;
}

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

const jsContentType = /^(text|application)\/(x-)?javascript(;|$)/;
const jsonContentType = /^(text|application)\/json(;|$)/;
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/es-module-shims.js.map

Large diffs are not rendered by default.

Loading