mirror of https://github.com/webpack/webpack.git
Merge pull request #14687 from webpack/bugfix/esm-single-quote
fix using single quotes with esm files
This commit is contained in:
commit
3c17f90bb3
|
@ -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 */
|
/* istanbul ignore next */
|
||||||
/**
|
/**
|
||||||
* @param {number} mtime mtime
|
* @param {number} mtime mtime
|
||||||
|
@ -1657,17 +1662,13 @@ class FileSystemInfo {
|
||||||
let dependency;
|
let dependency;
|
||||||
if (imp.d === -1) {
|
if (imp.d === -1) {
|
||||||
// import ... from "..."
|
// import ... from "..."
|
||||||
dependency = JSON.parse(
|
dependency = parseString(
|
||||||
source.substring(imp.s - 1, imp.e + 1)
|
source.substring(imp.s - 1, imp.e + 1)
|
||||||
);
|
);
|
||||||
} else if (imp.d > -1) {
|
} else if (imp.d > -1) {
|
||||||
// import()
|
// import()
|
||||||
let expr = source.substring(imp.s, imp.e).trim();
|
let expr = source.substring(imp.s, imp.e).trim();
|
||||||
if (expr[0] === "'")
|
dependency = parseString(expr);
|
||||||
expr = `"${expr
|
|
||||||
.slice(1, -1)
|
|
||||||
.replace(/"/g, '\\"')}"`;
|
|
||||||
dependency = JSON.parse(expr);
|
|
||||||
} else {
|
} else {
|
||||||
// e.g. import.meta
|
// e.g. import.meta
|
||||||
continue;
|
continue;
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
export { default } from "./esm-dep.mjs";
|
export { default } from "./esm-dep.mjs";
|
||||||
|
// prettier-ignore
|
||||||
|
import './esm-dep.mjs';
|
||||||
|
|
||||||
export const asyncDep = (
|
export const asyncDep = (
|
||||||
await import("../../js/buildDepsInput/esm-async-dependency.mjs")
|
await import("../../js/buildDepsInput/esm-async-dependency.mjs")
|
||||||
).default;
|
).default;
|
||||||
|
// prettier-ignore
|
||||||
|
await import('../../js/buildDepsInput/esm-async-dependency.mjs')
|
||||||
|
|
Loading…
Reference in New Issue