mirror of https://github.com/webpack/webpack.git
fix: forward semicolons from meta.webpackAST (#19252)
This commit is contained in:
parent
d6679b3333
commit
3755a3ec8a
|
@ -4379,6 +4379,13 @@ class JavascriptParser extends Parser {
|
|||
if (typeof source === "object") {
|
||||
ast = /** @type {Program} */ (source);
|
||||
comments = source.comments;
|
||||
if (source.semicolons) {
|
||||
// Forward semicolon information from the preparsed AST if present
|
||||
// This ensures the output is consistent with that of a fresh AST
|
||||
for (const pos of source.semicolons) {
|
||||
semicolons.add(pos);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
comments = [];
|
||||
ast = JavascriptParser._parse(source, {
|
||||
|
|
|
@ -7,12 +7,14 @@ const acornParser = acorn.Parser;
|
|||
module.exports = function (source) {
|
||||
const comments = [];
|
||||
|
||||
const semicolons = new Set();
|
||||
const ast = acornParser.parse(source, {
|
||||
ranges: true,
|
||||
locations: true,
|
||||
ecmaVersion: 11,
|
||||
sourceType: "module",
|
||||
onComment: comments
|
||||
onComment: comments,
|
||||
onInsertedSemicolon: (pos) => semicolons.add(pos)
|
||||
});
|
||||
|
||||
// change something to test if it's really used
|
||||
|
@ -23,6 +25,8 @@ module.exports = function (source) {
|
|||
|
||||
//@ts-ignore
|
||||
ast.comments = comments;
|
||||
//@ts-ignore
|
||||
ast.semicolons = semicolons;
|
||||
this.callback(null, source, null, {
|
||||
webpackAST: ast
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue