Preserve inline comment as last argument (#1390)

We already had the logic but only applied it for comments on their own line, we should also do it if they are inline.

Fixes #1380
master
Christopher Chedeau 2017-05-01 14:29:03 -07:00 committed by GitHub
parent 314e96322c
commit 93cad97b14
3 changed files with 125 additions and 0 deletions

View File

@ -192,6 +192,13 @@ function attach(comments, ast, text) {
}
} else if (util.hasNewline(text, locEnd(comment))) {
if (
handleLastFunctionArgComments(
text,
precedingNode,
enclosingNode,
followingNode,
comment
) ||
handleConditionalExpressionComments(
enclosingNode,
precedingNode,

View File

@ -714,6 +714,47 @@ class X {
): $Enum<SectionMode> {
}
}
class Foo {
a(lol /*string*/) {}
b(lol /*string*/
) {}
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {}
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) /*string*/ {}
// prettier-ignore
c(lol /*string*/
) {}
// prettier-ignore
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {}
// prettier-ignore
e(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {} /* string*/
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
type f = (
currentRequest: { a: number }
@ -767,6 +808,42 @@ class X {
): $Enum<SectionMode> {}
}
class Foo {
a(lol /*string*/) {}
b(lol /*string*/) {}
d(lol /*string*/, lol2 /*string*/, lol3 /*string*/, lol4 /*string*/) {}
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) /*string*/ {
}
// prettier-ignore
c(lol /*string*/
) {}
// prettier-ignore
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {}
// prettier-ignore
e(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {} /* string*/
}
`;
exports[`preserve-new-line-last.js 1`] = `

View File

@ -51,3 +51,44 @@ class X {
): $Enum<SectionMode> {
}
}
class Foo {
a(lol /*string*/) {}
b(lol /*string*/
) {}
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {}
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) /*string*/ {}
// prettier-ignore
c(lol /*string*/
) {}
// prettier-ignore
d(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {}
// prettier-ignore
e(
lol /*string*/,
lol2 /*string*/,
lol3 /*string*/,
lol4 /*string*/
) {} /* string*/
}