From 2ef9896567260930157df0c73691232149ca98d1 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Sun, 5 Mar 2017 22:04:50 +0100 Subject: [PATCH] Fix object expression in arrow function expression (#897) * Add new case for keeping parens around ObjectExpression in ArrowFunctionExpression. * Add new test. --- src/fast-path.js | 9 +++++++++ tests/arrows/__snapshots__/jsfmt.spec.js.snap | 2 ++ tests/arrows/arrow_function_expression.js | 1 + 3 files changed, 12 insertions(+) diff --git a/src/fast-path.js b/src/fast-path.js index 785d8403..5d473686 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -246,6 +246,15 @@ FPp.needsParens = function(assumeExpressionContext) { } switch (node.type) { + case "CallExpression": + if ( + node.callee.type === "ObjectExpression" && + parent.type === "ArrowFunctionExpression" + ) { + return true; + } + return false; + case "SpreadElement": case "SpreadProperty": return parent.type === "MemberExpression" && diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 3874d7eb..525a6078 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -8,6 +8,7 @@ export default (() => {})(); (() => {})\`\`; new (() => {}); if ((() => {}) ? 1 : 0) {} +let f = () => ({}()) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a => {}).length; typeof (() => {}); @@ -17,6 +18,7 @@ export default (() => {})(); new (() => {})(); if ((() => {}) ? 1 : 0) { } +let f = () => ({}()); " `; diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js index 968072fb..0b6e3bac 100644 --- a/tests/arrows/arrow_function_expression.js +++ b/tests/arrows/arrow_function_expression.js @@ -5,3 +5,4 @@ export default (() => {})(); (() => {})``; new (() => {}); if ((() => {}) ? 1 : 0) {} +let f = () => ({}())