Skip to content

fix(parser): check async arrow conditions for Flow generic async arrows - #18534

Merged
JLHwung merged 1 commit into
babel:mainfrom
JLHwung:fix-parser-flow-async-arrow-conditions
Nov 18, 2026
Merged

JLHwung merged 1 commit into
babel:mainfrom
JLHwung:fix-parser-flow-async-arrow-conditions

Conversation

@JLHwung

@JLHwung JLHwung commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
Q                       A
Fixed Issues? Babel parser accepts invalid "async\n(b) => c" when flow plugin is enabled
Patch: Bug Fix? Yes
Major: Breaking Change?
Minor: New Feature?
Tests Added + Pass? Yes
Documentation PR Link
Any Dependency Changes?
Need backport? 7.x
License MIT

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 atPossibleAsyncArrow method.

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
@JLHwung JLHwung added PR: Bug Fix 🐛 A type of pull request used for our changelog categories area: flow pkg: parser 7.x: needs backport labels Nov 5, 2026
@babel-bot

Copy link
Copy Markdown
Collaborator

Build successful! You can test your changes in the REPL here: https://babeljs.io/repl/build/63032

@pkg-pr-new

pkg-pr-new Bot commented Nov 5, 2026

Copy link
Copy Markdown

Open in StackBlitz

commit: cb82fab

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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 async identifier 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

@JLHwung
JLHwung added this pull request to the merge queue Nov 18, 2026
Merged via the queue into babel:main with commit 24f41d1 Nov 18, 2026
72 of 74 checks passed
@JLHwung
JLHwung deleted the fix-parser-flow-async-arrow-conditions branch November 18, 2026 18:57
@babel-bot

Copy link
Copy Markdown
Collaborator

Backported to 7.x in #18656.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: flow pkg: parser PR: Bug Fix 🐛 A type of pull request used for our changelog categories

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants