Fix comments in return statement argument (#657)

* Extend ReturnStatement case to better handle comments in argument 🎉.

* Update test.

* Add missing space between return and left parenthese.

* Fix current tests and add new tests.

* Do not break one-liner returns.

* Revert specific test.

* Patch from #683.
master
Davy Duperron 2017-02-14 03:35:42 +01:00 committed by Christopher Chedeau
parent d09e455a71
commit b661fecd9c
4 changed files with 136 additions and 2 deletions

View File

@ -561,7 +561,18 @@ function genericPrintNoParens(path, options, print) {
case "ReturnStatement":
parts.push("return");
if (n.argument) {
if (n.argument &&
n.argument.comments &&
n.argument.comments.some(comment => comment.leading)) {
parts.push(
concat([
' (',
indent(options.tabWidth, concat([softline, path.call(print, "argument")])),
line,
')'
])
);
} else if (n.argument) {
parts.push(" ", path.call(print, "argument"));
}

View File

@ -112,6 +112,32 @@ expect(() => {}).toTriggerReadyStateChanges(
"
`;
exports[`test dangling_array.js 1`] = `
"expect(() => {}).toTriggerReadyStateChanges([
// Nothing.
]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expect(() => {}).toTriggerReadyStateChanges(
[
// Nothing.
]
);
"
`;
exports[`test dangling_array.js 2`] = `
"expect(() => {}).toTriggerReadyStateChanges([
// Nothing.
]);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
expect(() => {}).toTriggerReadyStateChanges(
[
// Nothing.
]
);
"
`;
exports[`test first-line.js 1`] = `
"a // comment
b
@ -872,6 +898,84 @@ function name() {
"
`;
exports[`test return-statement.js 1`] = `
"function a() {
return (
// Comment
<div />
);
}
function b() {
return (
// Comment
!!x
);
}
function c() {
return 1337; // Comment
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function a() {
return (
/* Comment*/
<div />
);
}
function b() {
return (
// Comment
!!x
);
}
function c() {
return 1337; // Comment
}
"
`;
exports[`test return-statement.js 2`] = `
"function a() {
return (
// Comment
<div />
);
}
function b() {
return (
// Comment
!!x
);
}
function c() {
return 1337; // Comment
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function a() {
return (
// Comment
<div />
);
}
function b() {
return (
// Comment
!!x
);
}
function c() {
return 1337; // Comment
}
"
`;
exports[`test try.js 1`] = `
"// comment 1
try {

View File

@ -0,0 +1,17 @@
function a() {
return (
// Comment
<div />
);
}
function b() {
return (
// Comment
!!x
);
}
function c() {
return 1337; // Comment
}

View File

@ -72,7 +72,9 @@ class E<X> extends C<X> {
//x:X;
set(x: X): X {
/*return x;*/ this.x = x;
return /*this.x; */ this.get();
return (
/*this.x; */ this.get()
);
}
}