From badab37dd1360a50a1fbdbeb778af9857decee96 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Sun, 22 Jan 2017 17:00:13 -0600 Subject: [PATCH] Remove unneeded parens for FunctionExpression inside LogicalExpression (#399) --- src/fast-path.js | 3 +++ tests/function/__snapshots__/jsfmt.spec.js.snap | 5 ++++- tests/function/function_expression.js | 3 ++- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/fast-path.js b/src/fast-path.js index 1d34e742..733500b6 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -399,6 +399,9 @@ FPp.needsParens = function(assumeExpressionContext) { case "NewExpression": return name === "callee"; + case "LogicalExpression": + return node.type === "ArrowFunctionExpression"; + default: return isBinary(parent); } diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index 93ef9136..36eca4ff 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -370,7 +370,8 @@ export default (function() {})(); (function() {})()\`\`; (function() {})\`\`; new (function() {}); -(function() {}) +(function() {}); +a = function f() {} || b; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (function() { }).length; @@ -386,6 +387,8 @@ new (function() { })(); (function() { }); +a = function f() { +} || b; " `; diff --git a/tests/function/function_expression.js b/tests/function/function_expression.js index aa9c6c35..76a68504 100644 --- a/tests/function/function_expression.js +++ b/tests/function/function_expression.js @@ -4,4 +4,5 @@ export default (function() {})(); (function() {})()``; (function() {})``; new (function() {}); -(function() {}) +(function() {}); +a = function f() {} || b;