refactor: derive ASI positions from source instead of acorn's onInsertedSemicolon - #21453
Conversation
Stop passing onInsertedSemicolon to acorn; determine automatic-semicolon- insertion positions from the source text via getLocation's source instead. Custom parsers no longer need to collect and return a semicolons set, so the oxc example drops its collect-all-semicolons workaround.
🦋 Changeset detectedLatest commit: 88f1fee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview is available (e4a217e). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@e4a217e
yarn add -D webpack@https://pkg.pr.new/webpack@e4a217e
pnpm add -D webpack@https://pkg.pr.new/webpack@e4a217e |
Types CoverageCoverage after merging refactor/derive-asi-from-source into main will be
Coverage Report |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21453 +/- ##
=======================================
Coverage 93.38% 93.39%
=======================================
Files 610 610
Lines 71494 71528 +34
Branches 20458 20479 +21
=======================================
+ Hits 66762 66800 +38
+ Misses 4732 4728 -4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will regress 2 benchmarks
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "import-meta-glob", scenario '{"name":"mode-development","mode":"development"}' |
1.3 MB | 2.2 MB | -40.38% |
| ❌ | Memory | benchmark "many-chunks-commonjs", scenario '{"name":"mode-production","mode":"production"}' |
7.6 MB | 9.5 MB | -20.13% |
| ⚡ | Memory | benchmark "concatenate-modules", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
395 KB | 153.8 KB | ×2.6 |
| ⚡ | Memory | benchmark "context-esm", scenario '{"name":"mode-production","mode":"production"}' |
9.3 MB | 7.7 MB | +20.25% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing refactor/derive-asi-from-source (88f1fee) with main (4968684)
Footnotes
-
27 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
Summary
Now that the parser has the module source available during the walk (locations are derived from node offsets), automatic-semicolon-insertion positions can be read straight from the source text instead of being collected via acorn's
onInsertedSemicoloncallback. This drops thesemicolonsoption/callback from the parse path and, more importantly, means custom parsers no longer have to collect and return asemicolonsset — so the oxc example loses its "scan the whole source for every semicolon" workaround.isAsiPositionnow treats a statement terminated by a real;or continued by a,(a sequence element) as non-ASI, andset/unsetAsiPositionrecord overrides in a lazily-allocated map.What kind of change does this PR introduce?
refactor
Did you add tests for your changes?
Yes — rewrote the ASI unit tests in
test/WebpackParser.unittest.jsto cover source-derived positions, set/unset overrides, whitespace/comment skipping and the no-source fallback; existing integration cases (parsing/harmony*,module/custom-javascript-parser,parsing/precreated-ast) exercise the behavior end-to-end.Does this PR introduce a breaking change?
No. Custom
parsefunctions may still return asemicolonsset (it is simply ignored) and no longer need to; output is unchanged.If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a — the in-repo
custom-javascript-parserexample (README + parser sources) is updated in this PR.Use of AI
AI (Claude) was used to help implement the refactor, write the tests, and run the before/after parse/build/GC benchmarks; all changes were reviewed and verified against the existing test suite.
Generated by Claude Code