Skip to content
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

fix using single quotes with esm files #14687

Merged
merged 1 commit into from Nov 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/FileSystemInfo.js
Expand Up @@ -692,6 +692,11 @@ class SnapshotOptimization {
}
}

const parseString = str => {
if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
return JSON.parse(str);
};

/* istanbul ignore next */
/**
* @param {number} mtime mtime
Expand Down Expand Up @@ -1657,17 +1662,13 @@ class FileSystemInfo {
let dependency;
if (imp.d === -1) {
// import ... from "..."
dependency = JSON.parse(
dependency = parseString(
source.substring(imp.s - 1, imp.e + 1)
);
} else if (imp.d > -1) {
// import()
let expr = source.substring(imp.s, imp.e).trim();
if (expr[0] === "'")
expr = `"${expr
.slice(1, -1)
.replace(/"/g, '\\"')}"`;
dependency = JSON.parse(expr);
dependency = parseString(expr);
} else {
// e.g. import.meta
continue;
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/buildDependencies/esm.mjs
@@ -1,5 +1,9 @@
export { default } from "./esm-dep.mjs";
// prettier-ignore
import './esm-dep.mjs';

export const asyncDep = (
await import("../../js/buildDepsInput/esm-async-dependency.mjs")
).default;
// prettier-ignore
await import('../../js/buildDepsInput/esm-async-dependency.mjs')