-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Description
Prettier 2.1.2
Playground link
--parser babel
Input:
function x() {
} // first
; // second
Output:
function x() {} // first // second
Expected behavior:
function x() {} // first
// second
Details:
As you can see, the two comments (that should be on their own lines) are merged on a single line. I think this has to do with the lineSuffix
command being used on two tokens on the same line. When that happens, both the suffixes are appended to the same line.
This is obviously very dangerous, and destroys the semantic meaning of the comment. Not only it makes it much harder to read and reason about (since comments cannot be broken), it also means that it will break any tools/parsers that read the comment contents and expect certain strings to be there/not there, like ignores and other directives.
- | First | Second |
---|---|---|
Before | first |
second |
After | first // second |
removed |
This does not just affect JavaScript, but it also affects all other languages, as they have no other means AFAICT of fixing this correctly using other available commands.