fix: avoid stray semicolon after a parenthesized sequence element - #21533
#21533fix: avoid stray semicolon after a parenthesized sequence element#21533alexander-akait merged 1 commit intomainwebpack/webpack:mainfrom claude/webpack-issue-21532-9f511hwebpack/webpack:claude/webpack-issue-21532-9f511hCopy head branch name to clipboard
Conversation
A parenthesized node's range excludes its wrapping parens, so when a
statement-level sequence element was parenthesized (e.g. `({a}=x), fn()`)
the ASI check scanned from the element's range end, hit the closing `)`
before the `,` separator, and misclassified the following imported call as
an ASI position. This spliced a stray `;` after the comma, emitting the
invalid `expr, ;expr`. Skip grouping `)` when scanning for the separator.
🦋 Changeset detectedLatest commit: a1c394a 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 (cea3698). Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@cea3698
yarn add -D webpack@https://pkg.pr.new/webpack@cea3698
pnpm add -D webpack@https://pkg.pr.new/webpack@cea3698 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #21533 +/- ##
=======================================
Coverage 93.79% 93.79%
=======================================
Files 620 620
Lines 73329 73330 +1
Branches 21202 21203 +1
=======================================
+ Hits 68778 68779 +1
Misses 4551 4551
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 1 benchmark
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Memory | benchmark "asset-modules-resource", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
643.4 KB | 844.7 KB | -23.83% |
| ⚡ | Memory | benchmark "devtool-eval", scenario '{"name":"mode-development-rebuild","mode":"development","watch":true}' |
3.1 MB | 1.3 MB | ×2.4 |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing claude/webpack-issue-21532-9f511h (a1c394a) with main (6926396)
Summary
Fixes #21532. Since 5.109.0 (#21453), ASI positions are derived from the source text instead of acorn's
onInsertedSemicolon. A parenthesized node's range excludes its wrapping parens, so for a statement-level sequence whose first element is parenthesized (e.g.({a}=x), fn(), y), the ASI scan started at that element's range end, hit the closing)before the,separator, and misclassified the following imported call as an ASI position — splicing a stray;after the comma and emitting invalidexpr, ;expr(which then breaks Terser). The fix skips grouping)when scanning for the separator.What kind of change does this PR introduce?
fix
Did you add tests for your changes?
Yes — a
test/configCases/scope-hoisting/import-in-parenthesized-sequenceregression case (fails withSyntaxError: Unexpected token ';'before the fix) and a focused_isAsiPositionunit test intest/WebpackParser.unittest.jscovering the)-skip branch.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
n/a
Use of AI
Yes — investigation, the fix, and the tests were produced with Claude Code, then reviewed and verified locally (unit, ConfigTestCases, StatsTestCases suites all green).
Generated by Claude Code
Note
Medium Risk
Touches core parser ASI logic used during code generation; the change is narrow but affects emitted bundle syntax in edge cases.
Overview
Fixes a regression in source-text ASI detection (since 5.109.0) where webpack could emit invalid JavaScript under module concatenation / scope hoisting.
When a statement-level comma sequence starts with a parenthesized expression (e.g.
({ a, b } = source), check(a), …), acorn’s range ends inside the parens._isAsiPositionscanned forward from that offset, saw)before the,, treated the next imported call as needing ASI, and inserted a stray;— yieldingexpr, ;exprand downstream minifier failures.The change makes
_nextTokenCharCodeskip grouping)(like whitespace/comments) so the real,or;separator is found. Adds a scope-hoisting config regression withModuleConcatenationPluginand a unit test for_isAsiPositionon nested parens.Reviewed by Cursor Bugbot for commit a1c394a. Bugbot is set up for automated code reviews on this repo. Configure here.