From 3649835ce085b89f97db72b39dc146e28dd62aeb Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Thu, 2 Mar 2017 19:39:22 -0800 Subject: [PATCH] Keep parenthesis on export default function (#844) It turns out that my fix was not correct. We should not add parenthesis for FunctionDeclaration instead of checking if the function expression is named. Fixes #819 --- src/fast-path.js | 8 ++++---- tests/es6modules/__snapshots__/jsfmt.spec.js.snap | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/fast-path.js b/src/fast-path.js index b2decbe9..c3b6068e 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -454,10 +454,10 @@ FPp.needsParens = function(assumeExpressionContext) { return false; case "ExportDefaultDeclaration": - if (node.type === "ArrowFunctionExpression") { - return false; - } - if (node.type === "FunctionExpression" && !node.id) { + if ( + node.type === "ArrowFunctionExpression" || + node.type === "FunctionDeclaration" + ) { return false; } return true; diff --git a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap index 6178a366..d656f12e 100644 --- a/tests/es6modules/__snapshots__/jsfmt.spec.js.snap +++ b/tests/es6modules/__snapshots__/jsfmt.spec.js.snap @@ -101,14 +101,14 @@ export default function f() {} exports[`export_default_function_expression.js 1`] = ` "export default (function() {}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export default function() {}; +export default (function() {}); " `; exports[`export_default_function_expression.js 2`] = ` "export default (function() {}); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -export default function() {}; +export default (function() {}); " `;