-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ternary operator > lambda > ternary fails to parse himself after formatting #2194
Comments
Thanks for reporting, @deddu! |
@k15a fyi, if prettier generates a piece of code that doesn't parse or produces an output with a different meaning, this should be flagged as high pri. It should not happen, ever :) |
This looks like an issue with babylon, flow parser handles it fine. cc @hzoo |
Looks related to issues regarding babel/babylon#58 |
@hzoo looks like it indeed, and there's already a PR for it! You are on fire :) |
* Distinguish between ternary's : and arrow fn's return type * Correctly parse nested arrow functions inside conditional expressions Defer the conversion of arrow function parameters to assignable nodes so that it is possible to use the (invalid) ast to get the exact position of the (wrong) arrow functions. * Check params of arrow fns w/ type params or w/o return type * Fix also async functions * Add test from prettier prettier/prettier#2194 * Don't check arrow params if they are valid at the first attemp * Use state instead of relying on the "noArrowParamsConversion" parameter * Remove noArrowParamsConversion
This was fixed in babel/babylon@a9a55fb, but then reverted in babel/babylon@8829853. babel/babylon#596 has the next iteration of the fix. |
That pr was released in babylon v.7.0.0-beta.27! |
@nicolo-ribaudo Thanks for the heads-up! Would you be interested in making a PR bumping the babylon version and adding a test case? :) |
Sure, I can do that this evening (CET) |
I have a PR ready for this, but the latest Babylon version can't be bumped in Prettier b/c we split the TS/Flow types. I have an update ready for this as well but waiting for an upstream change in |
The following nested ternary
gets formatted to
which consequently fails a subsequent parsing with
SyntaxError: Invalid left-hand side in arrow function parameters (2:11)
;(using prettier 1.44)
The text was updated successfully, but these errors were encountered: