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
This commit is contained in:
Christopher Chedeau authored and GitHub committed 2017-05-01 14:29:03 -07:00
1 parent 314e96322c
commit 93cad97b14
3 files changed
+125

No files matched your search

+7
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,
@@ -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`] = `
+41
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*/
}