Skip to content

Commit 4edd043

Browse files
committed
fix using single quotes with esm files
1 parent 3aed1fe commit 4edd043

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

lib/FileSystemInfo.js

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -692,6 +692,11 @@ class SnapshotOptimization {
692692
}
693693
}
694694

695+
const parseString = str => {
696+
if (str[0] === "'") str = `"${str.slice(1, -1).replace(/"/g, '\\"')}"`;
697+
return JSON.parse(str);
698+
};
699+
695700
/* istanbul ignore next */
696701
/**
697702
* @param {number} mtime mtime
@@ -1657,17 +1662,13 @@ class FileSystemInfo {
16571662
let dependency;
16581663
if (imp.d === -1) {
16591664
// import ... from "..."
1660-
dependency = JSON.parse(
1665+
dependency = parseString(
16611666
source.substring(imp.s - 1, imp.e + 1)
16621667
);
16631668
} else if (imp.d > -1) {
16641669
// import()
16651670
let expr = source.substring(imp.s, imp.e).trim();
1666-
if (expr[0] === "'")
1667-
expr = `"${expr
1668-
.slice(1, -1)
1669-
.replace(/"/g, '\\"')}"`;
1670-
dependency = JSON.parse(expr);
1671+
dependency = parseString(expr);
16711672
} else {
16721673
// e.g. import.meta
16731674
continue;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
export { default } from "./esm-dep.mjs";
2+
// prettier-ignore
3+
import './esm-dep.mjs';
24

35
export const asyncDep = (
46
await import("../../js/buildDepsInput/esm-async-dependency.mjs")
57
).default;
8+
// prettier-ignore
9+
await import('../../js/buildDepsInput/esm-async-dependency.mjs')

0 commit comments

Comments
 (0)