Repository navigation
fix(parser): reject arrow functions after an arrow in an earlier operand - #18533
Merged
Merged
Conversation
`state.canStartArrow` was only cleared after the first operand of a binary
expression, so an arrow function in a later operand left it set for the next
one, and `a + (() => {}) + b => c` was accepted.
Assisted-by: Claude Opus 5.5
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63031 |
|
commit: |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified for the parser regression fix.
No open issues 🎉
What changed in this PR
Fixes a Babel 8 parser regression introduced in #17838 that allowed unparenthesized arrow functions in later binary operands after parsing an earlier nested arrow.
Changes:
- Resets
canStartArrowimmediately before parsing each binary right operand. - Adds rejection fixtures for binary, logical, exponentiation, async-arrow, and F# pipeline cases.
- Adds snapshots covering valid expressions and error recovery.
| File | Description |
|---|---|
packages/babel-parser/test/fixtures/experimental/pipeline-operator-fsharp/fsharp-proposal-ban-arrow-in-binary-operand/options.json |
Specifies the expected pipeline syntax error. |
packages/babel-parser/test/fixtures/experimental/pipeline-operator-fsharp/fsharp-proposal-ban-arrow-in-binary-operand/input.js |
Covers an invalid arrow in a pipeline binary operand. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-logical-argument-after-arrow-in-call/options.json |
Specifies the expected logical-operand error. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-logical-argument-after-arrow-in-call/input.js |
Covers an invalid arrow after a call containing an arrow. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-exponent-argument-after-parenthesized-arrow/options.json |
Specifies the expected exponentiation error. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-exponent-argument-after-parenthesized-arrow/input.js |
Covers an invalid arrow in an exponentiation chain. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-parens-after-parenthesized-arrow/options.json |
Specifies the expected parenthesized-parameter error. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-parens-after-parenthesized-arrow/input.js |
Covers an invalid later arrow with parenthesized parameters. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-async-parens-after-parenthesized-arrow/options.json |
Specifies the expected async-arrow error. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-async-parens-after-parenthesized-arrow/input.js |
Covers an invalid async arrow with parenthesized parameters. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-async-after-parenthesized-arrow/output.json |
Records the missing-semicolon error and recovered syntax tree. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-async-after-parenthesized-arrow/input.js |
Covers an invalid later async arrow without parameter parentheses. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-parenthesized-arrow/options.json |
Specifies the original regression’s expected error. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-parenthesized-arrow/input.js |
Reproduces the reported binary-operand regression. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-arrow-in-template/options.json |
Specifies the expected error after a template operand. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-arrow-in-template/input.js |
Covers an earlier arrow inside template interpolation. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-arrow-in-array/options.json |
Specifies the expected error after an array operand. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/invalid-binary-argument-after-arrow-in-array/input.js |
Covers an earlier arrow inside an array. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/binary-argument-after-parenthesized-arrow/output.json |
Records syntax trees for valid neighboring cases. |
packages/babel-parser/test/fixtures/es2015/arrow-functions/binary-argument-after-parenthesized-arrow/input.js |
Covers valid operands and parenthesized arrow sequences. |
packages/babel-parser/src/parser/expression.ts |
Moves the arrow-start reset to right-operand parsing. |
Review effort: Balanced
nicolo-ribaudo
approved these changes
Nov 9, 2026
JLHwung
added a commit
to JLHwung/babel
that referenced
this pull request
Nov 10, 2026
…and (babel#18533) `state.canStartArrow` was only cleared after the first operand of a binary expression, so an arrow function in a later operand left it set for the next one, and `a + (() => {}) + b => c` was accepted. Assisted-by: Claude Opus 5.5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
a + (() => {}) + b => cIn this PR we fix a regression introduced in #17838: The
canStartArrowwas reset too late: it should have been reset when we have started parsing the right operand of the binary expression. This issue is reported by Claude Fable.