Skip to content

fix(parser): support async arrow functions in default exports#5443

Open
AdityaOP007 wants to merge 2 commits into
boa-dev:mainfrom
AdityaOP007:fix/export-default-async-arrow-parser
Open

fix(parser): support async arrow functions in default exports#5443
AdityaOP007 wants to merge 2 commits into
boa-dev:mainfrom
AdityaOP007:fix/export-default-async-arrow-parser

Conversation

@AdityaOP007

Copy link
Copy Markdown

Summary

#5442

This PR fixes a parser issue where valid ECMAScript syntax using an async arrow function as a default export was incorrectly rejected.

Previously, statements like:

export default async (x) => x;

resulted in a parser error because export default async always assumed an async function declaration instead of allowing an AssignmentExpression. According to the ECMAScript specification, an async arrow function is a valid AssignmentExpression and should parse successfully.

What Changed

  • Updated the default export parser to apply the correct ECMAScript lookahead for async.
  • Only parses a hoistable async function when async is followed by function (with no line terminator).
  • Falls back to parsing an AssignmentExpression in all other cases, allowing async arrow functions to be handled by the existing parser logic.
  • Added parser tests covering valid async arrow default exports, invalid syntax, regression scenarios, and AST validation to ensure the generated syntax tree is correct.

Result

The following syntax now parses successfully:

export default async () => 1;
export default async x => x;
export default async (x) => x;
export default async (a, b) => a + b;

Existing valid forms such as:

export default async function () {}
export const fn = async (x) => x;

continue to work as expected.

Validation

  • cargo fmt
  • cargo clippy -- -D warnings
  • ✅ Parser test suite passed
  • ✅ Workspace tests passed

This change brings the parser behavior in line with the ECMAScript specification while preserving existing functionality and adding regression coverage to prevent similar issues in the future.

@AdityaOP007
AdityaOP007 requested a review from a team as a code owner July 23, 2026 13:01
@github-actions github-actions Bot added Waiting On Review Waiting on reviews from the maintainers C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests. and removed Waiting On Review Waiting on reviews from the maintainers labels Jul 23, 2026
@github-actions github-actions Bot added this to the v1.0.0 milestone Jul 23, 2026
@github-actions github-actions Bot added the Waiting On Review Waiting on reviews from the maintainers label Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-Parser Issues surrounding the parser C-Tests Issues and PRs related to the tests. Waiting On Review Waiting on reviews from the maintainers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant