Fix own line last if comment (#1219)

Fixes #1205
master
Christopher Chedeau 2017-04-12 17:26:44 -07:00 committed by GitHub
parent ee7cfa9501
commit 5d8ffd0c2e
3 changed files with 27 additions and 1 deletions

View File

@ -161,6 +161,7 @@ function attach(comments, ast, text, options) {
handleMemberExpressionComments(enclosingNode, followingNode, comment) ||
handleIfStatementComments(
text,
precedingNode,
enclosingNode,
followingNode,
comment
@ -209,6 +210,7 @@ function attach(comments, ast, text, options) {
handleTemplateLiteralComments(enclosingNode, comment) ||
handleIfStatementComments(
text,
precedingNode,
enclosingNode,
followingNode,
comment
@ -240,6 +242,7 @@ function attach(comments, ast, text, options) {
if (
handleIfStatementComments(
text,
precedingNode,
enclosingNode,
followingNode,
comment
@ -391,6 +394,7 @@ function addBlockOrNotComment(node, comment) {
// }
function handleIfStatementComments(
text,
precedingNode,
enclosingNode,
followingNode,
comment
@ -408,7 +412,8 @@ function handleIfStatementComments(
// The only workaround I found is to look at the next character to see if
// it is a ).
if (getNextNonSpaceNonCommentCharacter(text, comment) === ")") {
return false;
addTrailingComment(precedingNode, comment);
return true;
}
if (followingNode.type === "BlockStatement") {

View File

@ -122,6 +122,13 @@ if (code === 92 /* '\\' */ /* '\\' */) {}
if (code === 92) /* '\\' */ {}
if (code === 92) { /* '\\' */ }
if (
1
// Comment
) {
a;
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (code === 92 /* '\\' */) {
}
@ -135,4 +142,11 @@ if (code === 92) {
/* '\\' */
}
if (
1
// Comment
) {
a;
}
`;

View File

@ -3,3 +3,10 @@ if (code === 92 /* '\' */ /* '\' */) {}
if (code === 92) /* '\' */ {}
if (code === 92) { /* '\' */ }
if (
1
// Comment
) {
a;
}