-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
throw the error when there is flow shorthand annotation comment with other comments #7429
Comments
Thanks for reporting! Prettier seems to throw the error when there is flow shorthand annotation comment with other comments. // Input
(0 /*: number */ /* comment */)
|
If a Flow shorthand annotation comment is detected, Prettier disables the default comment handling and implements custom handling for Flow comments. (This custom handling was implemented in pull request #5280.) The problem is that the custom handling only prints one comment (the first trailing comment), and forgets about all other comments. Prettier's sanity checks detect the fact that some comments were not printed, and reports an error. This issue does not reproduce when using Flow's parser ( I see three solutions:
Which of the above solutions sounds best? Does anyone have any other ideas on how to fix this crash? AST comparisonInput program
|
I was trying to fix this, before I saw comment by @strager , spend a lot of time figure how it works... I tried a solution similar to solution1. Finnally make it work for |
Prettier 1.19.1 --parser flow Input: f(
(1
// comment
/*: number */
/* comment*/
)
); Output: f(
(1 /*: // comment
number */)
/* comment*/
); Is this valid code? |
Seems to be valid. Use Flow's playground. |
Opened a new issue, maybe we should fix this first |
Not an issue anymore because support for Flow comments was removed in #13687 |
Prettier 1.19.1
Playground link
Input:
Output:
Expected behavior:
Prettier exits successfully. Prettier does not change the formatting of this code.
Observations:
The following changes to the input make the crash disappear:
The text was updated successfully, but these errors were encountered: