Repository: jlongster/prettier (js)

Issue:
Extra parenthesis around function and binary operation
```js
a = function f() {} || b
```

outputs

```js
a = (function f() {
}) || b;
```

but the parenthesis is not needed.

https://jlongster.github.io/prettier/#%7B%22content%22%3A%22a%20%3D%20function%20f()%20%7B%7D%20%7C%7C%20b%5Cn%22%2C%22options%22%3A%7B%22printWidth%22%3A80%2C%22tabWidth%22%3A2%2C%22singleQuote%22%3Afalse%2C%22trailingComma%22%3Afalse%2C%22bracketSpacing%22%3Atrue%2C%22doc%22%3Afalse%7D%7D

Pull request description:
Remove unneeded parens for FunctionExpression inside LogicalExpression
Fixes #374 

Patch:
diff --git a/src/fast-path.js b/src/fast-path.js
index 1d34e7421..733500b64 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);
       }


Test patch:
diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap
index 93ef91369..36eca4ff1 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 aa9c6c35f..76a685044 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;