forked from prettier/prettier
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix comments print in
IfStatement
(prettier#15076)
- Loading branch information
Showing
4 changed files
with
86 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#### Fix comments print in `IfStatement` (#15076 by @fisker) | ||
|
||
<!-- prettier-ignore --> | ||
```js | ||
function a(b) { | ||
if (b) return 1; // comment | ||
else return 2; | ||
} | ||
|
||
/* Prettier stable */ | ||
Error: Comment "comment" was not printed. Please report this error! | ||
|
||
/* Prettier main */ | ||
function a(b) { | ||
if (b) return 1; // comment | ||
else return 2; | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,37 @@ | ||
if (a === 0) doSomething(); // comment A1 | ||
if (a === 0) doSomething(); // comment A1 | ||
else if (a === 1) doSomethingElse(); // comment B1 | ||
else if (a === 2) doSomethingElse(); // comment C1 | ||
|
||
if (a === 0) doSomething(); /* comment A2 */ | ||
if (a === 0) doSomething(); /* comment A2 */ | ||
else if (a === 1) doSomethingElse(); /* comment B2 */ | ||
else if (a === 2) doSomethingElse(); /* comment C2 */ | ||
|
||
if (a === 0) expr; // comment A3 | ||
if (a === 0) expr; // comment A3 | ||
else if (a === 1) expr; // comment B3 | ||
else if (a === 2) expr; // comment C3 | ||
|
||
if (a === 0) expr; /* comment A4 */ | ||
if (a === 0) expr; /* comment A4 */ | ||
else if (a === 1) expr; /* comment B4 */ | ||
else if (a === 2) expr; /* comment C4 */ | ||
|
||
if (a === 0) looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // comment A5 | ||
if (a === 0) looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // comment A5 | ||
else if (a === 1) looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // comment B5 | ||
else if (a === 2) looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong; // comment C5 | ||
|
||
function a() { | ||
if (a) return; /* comment 6a */ | ||
else return 2; | ||
|
||
if (a) return 1; /* comment 6b */ | ||
else return 2; | ||
|
||
if (a) throw e; /* comment 6d */ | ||
else return 2; | ||
|
||
// TODO[@fisker]: fix this | ||
// if (a) var a = 1; /* comment 6e */ | ||
// else return 2; | ||
|
||
if (a) if (b); /* comment 6f */ | ||
else return 2; | ||
} |