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]: Error when parsing ternary inside parens with arrow functions when using Flow #13644

Closed
1 task done
nicolo-ribaudo opened this issue Aug 5, 2021 · 10 comments 路 Fixed by #13655
Closed
1 task done
Labels
area: flow i: bug outdated A closed issue/PR that is archived due to age. Recommended to make a new issue pkg: parser

Comments

@nicolo-ribaudo
Copy link
Member

馃捇

  • Would you like to work on a fix?

How are you using Babel?

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

Input code

(a ? v => (sum += 1) : v => 0);

REPL

Configuration file name

No response

Configuration

No response

Current and expected behavior

It should be parsed successfully, but it throws.

Environment

@babel/parser 7.15.0

Possible solution

No response

Additional context

Originally reported at #11038 (comment)

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Aug 5, 2021

Another test case:

(a ? (sum += 1) : v => 0 : any)

It's a ternary type-casted to any.

Also, (a ? (sum = 1) : v => 0 : any) is ambiguous but it looks like Flow accepts it.

Another one: (a ? (sum = 1) : v => 0 : any : any) is valid; (a ? (sum += 1) : v => 0 : any : any) is not.

@lightmare
Copy link
Contributor

Is there any possibility Flow/TypeScript fix their broken grammar? This mess is unsustainable.

@nicolo-ribaudo
Copy link
Member Author

nicolo-ribaudo commented Aug 5, 2021

Flow's grammar is worse since is also has (x: T) type casts, but I don't think they'll ever change it 馃し

I also found another bug while fixing this: <T>(b => c) should throw but it doesn't.

@julianklumpers
Copy link

What is exactly fixed? I'm still getting this issue with a fresh project and d3-geo installed.

09a56525-3029-454e-982a-7779e7866380

@nicolo-ribaudo
Copy link
Member Author

Can you share your lockfile?

@Nefcanto
Copy link

I also got this error. I attached my package-lock.json file. However, I had to rename it to .png. Pleaes rename it back to .json
package-lock
r.

@nicolo-ribaudo
Copy link
Member Author

The fix was released in @babel/parser 7.15.2. You need to delete this section from your lockfile:

    "@babel/parser": {
      "version": "7.14.8",
      "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.14.8.tgz",
      "integrity": "sha512-syoCQFOoo/fzkWDeM0dLEZi5xqurb5vuyzwIMNZRNun+N/9A4cUZeQaE7dTrB8jGaKuJRBtEOajtnmw0I5hvvA=="
    },

and re-run npm install.

@Nefcanto
Copy link

Thank you @nicolo-ribaudo for responding. I did that, but it ended up having the exact same lines of codes. In other words, it again installed 7.14.8.

@nicolo-ribaudo
Copy link
Member Author

Could you try running npx nls why @babel/parser?

@Nefcanto
Copy link

Well, it seems that it was a cache problem. I completely removed package-lock.json and reinstalled everything from scratch, after a PC restart. It worked. Thank you.

@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 Jan 11, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: flow i: bug 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.

4 participants