From a02e3b3464246dc10add6e805769d3a6f84a8426 Mon Sep 17 00:00:00 2001 From: Jacky Ho Date: Tue, 28 Nov 2017 02:58:39 -0800 Subject: [PATCH] Fix format of comment in paren of call expression in arrow expression (#3334) --- src/comments.js | 4 +++- tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap | 6 ++++++ tests/empty_paren_comment/empty_paren_comment.js | 3 +++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/comments.js b/src/comments.js index a3da1b02..bd1cbf83 100644 --- a/src/comments.js +++ b/src/comments.js @@ -683,7 +683,9 @@ function handleCommentInEmptyParens(text, enclosingNode, comment) { enclosingNode && (((enclosingNode.type === "FunctionDeclaration" || enclosingNode.type === "FunctionExpression" || - enclosingNode.type === "ArrowFunctionExpression" || + (enclosingNode.type === "ArrowFunctionExpression" && + (enclosingNode.body.type !== "CallExpression" || + enclosingNode.body.arguments.length === 0)) || enclosingNode.type === "ClassMethod" || enclosingNode.type === "ObjectMethod") && enclosingNode.params.length === 0) || diff --git a/tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap b/tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap index 9e81219d..f5ec778a 100644 --- a/tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap +++ b/tests/empty_paren_comment/__snapshots__/jsfmt.spec.js.snap @@ -44,6 +44,9 @@ f(/* ... */); f(a, /* ... */); f(a, /* ... */ b); f(/* ... */ a, b); + +let f = () => import(a /* ... */); +let f = () => doThing(a, /* ... */ b); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ let f = (/* ... */) => {}; (function(/* ... */) {})(/* ... */); @@ -72,4 +75,7 @@ f(a /* ... */); f(a, /* ... */ b); f(/* ... */ a, b); +let f = () => import(a /* ... */); +let f = () => doThing(a, /* ... */ b); + `; diff --git a/tests/empty_paren_comment/empty_paren_comment.js b/tests/empty_paren_comment/empty_paren_comment.js index 72859b21..71576218 100644 --- a/tests/empty_paren_comment/empty_paren_comment.js +++ b/tests/empty_paren_comment/empty_paren_comment.js @@ -23,3 +23,6 @@ f(/* ... */); f(a, /* ... */); f(a, /* ... */ b); f(/* ... */ a, b); + +let f = () => import(a /* ... */); +let f = () => doThing(a, /* ... */ b);