Skip to content

Parser misinterprets async() calls in conditional expressions as async arrow functionsย #64231

Description

@camc314

๐Ÿ”Ž Search Terms

parser, async, conditional

๐Ÿ•— Version & Regression Information

  • This is the behavior in every version I tried

โฏ Playground Link

No response

๐Ÿ’ป Code

const a = true;
const b = 1;

function async(): number {
  return b;
}

const first = a ? async() : 0;
//                       TS1005: '=>' expected.

const second = a ? async() : x => x;
//                                TS1005: ':' expected.

๐Ÿ™ Actual behavior

The parser appears to interpret async() as the beginning of an async arrow function and the conditional separator as a return-type annotation.
The first case also produces a syntax diagnostic when parsed as JavaScript after removing the : number annotation. Node accepts and executes that JavaScript equivalent

๐Ÿ™‚ Expected behavior

Both conditional expressions should parse successfully. async() is a call to the function named async, and the following colon separates the conditionalโ€™s branches.

Additional information about the issue

Oxc fix: oxc-project/oxc#26537

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScript

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions