Visitar URL original
fix(javascript): serialize parse-error locations in the persistent cache · webpack/webpack@1a633dc · GitHub
Skip to content

Commit 1a633dc

Browse files
alexander-akaitclaude
authored andcommitted
fix(javascript): serialize parse-error locations in the persistent cache
Register a serializer for the parser's ParserPosition so modules carrying a ModuleParseError stay serializable, restoring the acorn Position behavior (deserializes to a plain line/column object).
1 parent d4f3562 commit 1a633dc

3 files changed

Lines changed: 33 additions & 1 deletion

File tree

‎.changeset/160-js-parser-acorn-exactness.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Match acorn on `**` arrows, LS/PS cooking, string export names, `program` reuse.
5+
Match acorn on `**` arrows, LS/PS cooking, string export names, `program` reuse; serialize parse-error locations.

‎lib/javascript/syntax.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11686,6 +11686,7 @@ const collectCjsRequireSpecifiers = (source) => {
1168611686
};
1168711687

1168811688
module.exports.LEGACY_ASSERT_ATTRIBUTES = LEGACY_ASSERT_ATTRIBUTES;
11689+
module.exports.ParserPosition = ParserPosition;
1168911690
module.exports.WebpackParser = WebpackParser;
1169011691
module.exports.buildLineStarts = buildLineStarts;
1169111692
module.exports.collectCjsRequireSpecifiers = collectCjsRequireSpecifiers;

‎lib/util/registerExternalSerializer.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
ReplaceSource,
1818
SourceMapSource
1919
} = require("webpack-sources");
20+
const ParserPosition = require("../javascript/syntax").ParserPosition;
2021
const { register } = require("./serialization");
2122

2223
/** @typedef {import("acorn").Position} Position */
@@ -294,6 +295,36 @@ register(
294295
})()
295296
);
296297

298+
register(
299+
ParserPosition,
300+
CURRENT_MODULE,
301+
"webpack/ParserPosition",
302+
new (class ParserPositionSerializer {
303+
/**
304+
* Serializes this instance into the provided serializer context.
305+
* @param {ParserPosition} pos the position to be serialized
306+
* @param {import("../serialization/ObjectMiddleware").ObjectSerializerContext<number[]>} context context
307+
* @returns {void}
308+
*/
309+
serialize(pos, { write }) {
310+
write(pos.line);
311+
write(pos.column);
312+
}
313+
314+
/**
315+
* Restores this instance from the provided deserializer context.
316+
* @param {import("../serialization/ObjectMiddleware").ObjectDeserializerContext<number[]>} context context
317+
* @returns {SourcePosition} position
318+
*/
319+
deserialize({ read }) {
320+
return {
321+
line: read(),
322+
column: read()
323+
};
324+
}
325+
})()
326+
);
327+
297328
register(
298329
SourceMapSource,
299330
CURRENT_MODULE,

0 commit comments

Comments
 (0)