Skip to content

[Bug]: Parser fails to parse conditional type with generic arrow function at the extends position #14600

@Andarist

Description

@Andarist

💻

  • Would you like to work on a fix?

How are you using Babel?

Other (Next.js, Gatsby, vue-cli, ...)

Input code

export type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2
  ? true
  : false) extends <A>() => A extends A1 ? true : false
  ? true
  : false;

Configuration file name

No response

Configuration

module.exports = {
  presets: [
    [
      '@babel/preset-typescript',
      { isTSX: true, allExtensions: true, disallowAmbiguousJSXLike: true }
    ]
  ],
};

Current and expected behavior

Current

/repl.tsx: Unexpected token, expected "?" (3:30)

  1 | export type Equals<A1 extends any, A2 extends any> = (<A>() => A extends A2
  2 |   ? true
> 3 |   : false) extends <A>() => A extends A1 ? true : false
    |                               ^
  4 |   ? true
  5 |   : false;

Expected

It should parse OK. Both TypeScript and Prettier parse this. Babel was also parsing this correctly a few versions back.

Environment

https://babeljs.io/repl#?browsers=ie%2011&build=&builtIns=false&corejs=3.6&spec=false&loose=false&code_lz=KYDwDg9gTgLgBDAnmYcCiBHArgQwDYDOAPAIICMcoMwAdgCYFw42IA0cJATJSNfY80QA-OAF44AClJCJASjEiSPPgw6cAUHDgB-BFCzBNcAFxwAZvgLB5VWqulyFHZXcbkdegyfOXDW3TD6ft4WhMAA3EA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env%2Creact%2Ctypescript&prettier=false&targets=&version=7.18.3&externalPlugins=%40babel%2Fplugin-proposal-object-rest-spread%407.6.2&assumptions=%7B%7D

Possible solution

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions