fix: forward semicolons from meta.webpackAST (#19252)

This commit is contained in:
David Michon 2025-02-26 04:03:47 -08:00 committed by GitHub
parent d6679b3333
commit 3755a3ec8a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 1 deletions

View File

@ -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, {

View File

@ -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
});