Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
1 task
Andarist opened this issue May 26, 2022 · 1 comment 路 Fixed by #14604
Closed
1 task
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@Andarist
Copy link
Member

馃捇

  • 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

@nicolo-ribaudo
Copy link
Member

nicolo-ribaudo commented May 26, 2022

Minimal example:

type Equals = A extends () => B extends C ? D : E ? F : G;

Related bug:

type Equals = A extends (x: B extends C ? D : E) => 0 ? F : G;

@github-actions github-actions bot added the outdated A closed issue/PR that is archived due to age. Recommended to make a new issue label Aug 26, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: typescript i: bug i: regression outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants