Fix placing leading comments for a body of while statement (#9345)
* Add leading comments for while * Add tests * Add changelog
This commit is contained in:
1 parent
b886d9847d
commit
bb238f5765
4 files changed
+42
No files matched your search
@@ -0,0 +1,20 @@
|
||||
#### Fix placing leading comments for a body of while statement (#9345 by @sosukesuzuki)
|
||||
|
||||
<!-- prettier-ignore -->
|
||||
```js
|
||||
// Input
|
||||
while(1) // Comment
|
||||
foo();
|
||||
|
||||
// Prettier stable
|
||||
while (
|
||||
1 // Comment
|
||||
)
|
||||
foo();
|
||||
|
||||
// Prettier master
|
||||
while (1)
|
||||
// Comment
|
||||
foo();
|
||||
|
||||
```
|
||||
@@ -336,6 +336,11 @@ function handleWhileComments(
|
||||
return true;
|
||||
}
|
||||
|
||||
if (enclosingNode.body === followingNode) {
|
||||
addLeadingComment(followingNode, comment);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -5097,6 +5097,9 @@ while(true) {} // comment
|
||||
|
||||
while(true) /* comment */ ++x;
|
||||
|
||||
while(1) // Comment
|
||||
foo();
|
||||
|
||||
=====================================output=====================================
|
||||
while (
|
||||
true
|
||||
@@ -5122,6 +5125,10 @@ while (true) {} // comment
|
||||
|
||||
while (true) /* comment */ ++x
|
||||
|
||||
while (1)
|
||||
// Comment
|
||||
foo()
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
|
||||
@@ -5152,6 +5159,9 @@ while(true) {} // comment
|
||||
|
||||
while(true) /* comment */ ++x;
|
||||
|
||||
while(1) // Comment
|
||||
foo();
|
||||
|
||||
=====================================output=====================================
|
||||
while (
|
||||
true
|
||||
@@ -5177,5 +5187,9 @@ while (true) {} // comment
|
||||
|
||||
while (true) /* comment */ ++x;
|
||||
|
||||
while (1)
|
||||
// Comment
|
||||
foo();
|
||||
|
||||
================================================================================
|
||||
`;
|
||||
@@ -18,3 +18,6 @@ while(
|
||||
while(true) {} // comment
|
||||
|
||||
while(true) /* comment */ ++x;
|
||||
|
||||
while(1) // Comment
|
||||
foo();
|
||||
Reference in new issue
Block a user