Repository navigation
fix(parser): check async arrow conditions for Flow generic async arrows - #18534
Merged
JLHwung merged 1 commit intoNov 18, 2026
Merged
Conversation
Flow tried to parse `async <T>(...) => ...` whenever `async` was followed by `<`, so `a + async <T>(b) => c`, `new async <T>(b) => c`, `(async) <T>(b) => c` and `async\n<T>(b) => c` were all accepted as arrow functions. Use `atPossibleAsyncArrow`, as the TypeScript plugin does. Assisted-by: Claude Opus 5.5
Collaborator
|
Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63032 |
|
commit: |
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues are reported for the Flow generic async-arrow parsing change.
No open issues 🎉
What changed in this PR
This PR aligns Flow generic async-arrow parsing with Babel’s shared atPossibleAsyncArrow checks, extending the arrow-parsing hardening from #18533.
Changes:
- Replaces the Flow-specific
asyncidentifier check with the shared eligibility check. - Adds seven regression fixtures for invalid generic async arrows.
- Adds a valid parenthesized-arrow fixture to guard against over-rejection.
| File | Description |
|---|---|
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-unary-operand/options.json |
Specifies the expected unary-operand error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-unary-operand/input.js |
Tests an invalid unary operand. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-parenthesized-async/options.json |
Specifies the parenthesized-async error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-parenthesized-async/input.js |
Tests invalid parentheses around async. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-new-callee/options.json |
Specifies the expected constructor-context error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-new-callee/input.js |
Tests an invalid arrow after new. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-line-break/options.json |
Specifies the expected line-break error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-line-break/input.js |
Tests a forbidden newline after async. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-escaped-async/options.json |
Specifies the escaped-keyword error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-escaped-async/input.js |
Tests an escaped spelling of async. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-class-heritage/options.json |
Specifies the expected class-heritage error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-class-heritage/input.js |
Tests an invalid arrow in class heritage. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-binary-operand/options.json |
Specifies the expected binary-operand error. |
packages/babel-parser/test/fixtures/flow/type-generics/invalid-async-arrow-binary-operand/input.js |
Tests an unparenthesized arrow operand. |
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-parenthesized-binary-operand/output.json |
Records the valid parenthesized-arrow syntax tree. |
packages/babel-parser/test/fixtures/flow/type-generics/async-arrow-parenthesized-binary-operand/input.js |
Tests a valid parenthesized arrow operand. |
packages/babel-parser/src/plugins/flow/index.ts |
Uses the shared async-arrow eligibility check. |
Review effort: Balanced
Collaborator
|
Backported to 7.x in #18656. |
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.
In this PR we fix an issue detected by Claude opus when reviewing the #18533 change: The flow parser still uses a problematic old-fashioned way of parsing the async arrow. Here we use the hardened
atPossibleAsyncArrowmethod.