Skip to content

Parser rejects async arrow function in export default position #5442

Description

@Shine-neko

export default async (x) => x; fails to parse, while Node.js and other engines accept it.

Reproduction

// repro.mjs
export default async (x) => x;
SyntaxError: expected token 'function', got '(' in async function declaration at line 1, col 22

All parenthesised and unparenthesised forms fail:

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

Closely related forms that parse fine

This narrows the problem to export default combined with an async arrow:

export default async function (x) { return x; }  // ok
const f = async (x) => x; export default f;      // ok
export const g = async (x) => x;                 // ok

Node accepts every failing form above (verified with node --input-type=module).

Spec

export default takes an AssignmentExpression (ExportDeclaration), and AsyncArrowFunction is reachable from it, so these should parse.

Version

main @ 5718cc81111ceff12d6054ab948146a45bc6e114

Found while running a real-world CLI whose command handlers are written as export default async (options) => { … }.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions