Skip to content

Commit

Permalink
Don't inline paren at right of arguments (#1345)
Browse files Browse the repository at this point in the history
Fixes #1338
  • Loading branch information
vjeux committed Apr 19, 2017
1 parent aafcf5f commit 3dc7562
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
8 changes: 6 additions & 2 deletions src/comments.js
Expand Up @@ -244,7 +244,7 @@ function attach(comments, ast, text, options) {
) ||
handleObjectPropertyAssignment(enclosingNode, precedingNode, comment) ||
handleTemplateLiteralComments(enclosingNode, comment) ||
handleCommentInEmptyParens(enclosingNode, comment) ||
handleCommentInEmptyParens(text, enclosingNode, comment) ||
handleOnlyComments(enclosingNode, ast, comment, isLastComment)
) {
// We're good
Expand Down Expand Up @@ -516,7 +516,11 @@ function handleTemplateLiteralComments(enclosingNode, comment) {
return false;
}

function handleCommentInEmptyParens(enclosingNode, comment) {
function handleCommentInEmptyParens(text, enclosingNode, comment) {
if (getNextNonSpaceNonCommentCharacter(text, comment) !== ")") {
return false;
}

// Only add dangling comments to fix the case when no params are present,
// i.e. a function without any argument.
if (
Expand Down
6 changes: 5 additions & 1 deletion src/printer.js
Expand Up @@ -2119,7 +2119,11 @@ function printMethod(path, options, print) {
group(
concat([
path.call(function(valuePath) {
return printFunctionParams(valuePath, print, options);
return comments.printComments(
path,
p => printFunctionParams(valuePath, print, options),
options
)
}, "value"),
path.call(p => printReturnType(p, print), "value")
])
Expand Down
5 changes: 3 additions & 2 deletions tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -14,12 +14,12 @@ const obj = {
class Foo {
f(/* ... */) {}
f() /* ... */ {}
f = (/* ... */) => {};
static f(/* ... */) {};
static f = (/* ... */) => {};
static f = function(/* ... */) {};
static f = function f(/* ... */) {};
static f /* ... */() {};
}
f(/* ... */);
Expand All @@ -40,12 +40,13 @@ const obj = {
class Foo {
f(/* ... */) {}
f() /* ... */ {
}
f = (/* ... */) => {};
static f(/* ... */) {}
static f = (/* ... */) => {};
static f = function(/* ... */) {};
static f = function f(/* ... */) {};
static f(/* ... */) {}
}
f(/* ... */);
Expand Down
2 changes: 1 addition & 1 deletion tests/empty_paren_comment/empty_paren_comment.js
Expand Up @@ -11,12 +11,12 @@ const obj = {

class Foo {
f(/* ... */) {}
f() /* ... */ {}
f = (/* ... */) => {};
static f(/* ... */) {};
static f = (/* ... */) => {};
static f = function(/* ... */) {};
static f = function f(/* ... */) {};
static f /* ... */() {};
}

f(/* ... */);
Expand Down

0 comments on commit 3dc7562

Please sign in to comment.