throw the error when there is flow shorthand annotation comment with other comments
See original GitHub issuePrettier 1.19.1 Playground link
--parser babel
Input:
f(
// comment
(0 /*: number */)
);
Output:
ensureAllCommentsPrinted/<@https://prettier.io/lib/standalone.js:15543:15
ensureAllCommentsPrinted@https://prettier.io/lib/standalone.js:15541:17
coreFormat@https://prettier.io/lib/standalone.js:15592:29
format@https://prettier.io/lib/standalone.js:15832:75
formatWithCursor@https://prettier.io/lib/standalone.js:15848:14
withPlugins/<@https://prettier.io/lib/standalone.js:31794:17
format@https://prettier.io/lib/standalone.js:31802:14
formatCode@https://prettier.io/worker.js:234:21
handleMessage@https://prettier.io/worker.js:185:18
self.onmessage@https://prettier.io/worker.js:155:14
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:
- Remove the : in the comment on line 3
- Remove the ( and ) on line 3
- Remove the comment on line 2
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Comment Types - JavaScript. Flow
These comments allow Flow to work in plain JavaScript files without any additional work. Comment types syntax. There are two primary pieces of...
Read more >Best practices for writing code comments - Stack Overflow Blog
Rule 4: Comments should dispel confusion, not cause it. Rule 5: Explain unidiomatic code in comments. Rule 6: Provide links to the original ......
Read more >@babel/plugin-transform-flow-comments | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >Why doesn't logical OR work with error throwing in JavaScript?
As other answers have stated, it is because throw is a statement, which can't be used in contexts which expect expressions, such as...
Read more >Comment (computer programming) - Wikipedia
In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Not an issue anymore because support for Flow comments was removed in https://github.com/prettier/prettier/pull/13687
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 (
--parser flow
).I see three solutions:
Which of the above solutions sounds best? Does anyone have any other ideas on how to fix this crash?
cc @swac, @j-f1, @lydell
AST comparison
Input program
--parser babel
AST (abridged)--parser flow
AST (abridged)