From d7992886dd96148248698436d5eef8d83c2e4888 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 19:05:33 -0800 Subject: [PATCH] Add parenthesis around export default assignments (#423) Fixes #413 --- src/fast-path.js | 1 + tests/export_default/__snapshots__/jsfmt.spec.js.snap | 7 +++++++ tests/export_default/body.js | 1 + 3 files changed, 9 insertions(+) create mode 100644 tests/export_default/body.js diff --git a/src/fast-path.js b/src/fast-path.js index a531a96f..15021084 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -392,6 +392,7 @@ FPp.needsParens = function(assumeExpressionContext) { case "LogicalExpression": case "LogicalExpression": case "NewExpression": + case "ExportDefaultDeclaration": return true; case "CallExpression": diff --git a/tests/export_default/__snapshots__/jsfmt.spec.js.snap b/tests/export_default/__snapshots__/jsfmt.spec.js.snap index 7a5c5da5..ac0cace2 100644 --- a/tests/export_default/__snapshots__/jsfmt.spec.js.snap +++ b/tests/export_default/__snapshots__/jsfmt.spec.js.snap @@ -5,6 +5,13 @@ module.exports = require(\"M\"); " `; +exports[`test body.js 1`] = ` +"export default (class {}[1] = 1); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +export default (class {}[1] = 1); +" +`; + exports[`test test.js 1`] = ` "var M = require(\'M\'); var N = require(\'N\'); diff --git a/tests/export_default/body.js b/tests/export_default/body.js new file mode 100644 index 00000000..7a2f3c47 --- /dev/null +++ b/tests/export_default/body.js @@ -0,0 +1 @@ +export default (class {}[1] = 1);