From bf32905c3f40e6aecf28b4ff59c8b43ef2d9cad7 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 14:33:34 -0800 Subject: [PATCH] Fix parenthesis in object as left-hand-side of template (#398) Fixes #392 --- src/fast-path.js | 3 +++ tests/objects/__snapshots__/jsfmt.spec.js.snap | 9 +++++++++ tests/objects/expression.js | 2 ++ 3 files changed, 14 insertions(+) create mode 100644 tests/objects/expression.js diff --git a/src/fast-path.js b/src/fast-path.js index 990d7ed0..1d34e742 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -417,6 +417,9 @@ FPp.needsParens = function(assumeExpressionContext) { if (parent.type === "ArrowFunctionExpression" && name === "body") { return true; } + if (parent.type === "TaggedTemplateExpression") { + return true; + } default: if ( diff --git a/tests/objects/__snapshots__/jsfmt.spec.js.snap b/tests/objects/__snapshots__/jsfmt.spec.js.snap index 74d07ce1..c3fa28eb 100644 --- a/tests/objects/__snapshots__/jsfmt.spec.js.snap +++ b/tests/objects/__snapshots__/jsfmt.spec.js.snap @@ -43,6 +43,15 @@ var z = Object(123); " `; +exports[`test expression.js 1`] = ` +"() => ({}\`\`); +({})\`\`; +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(() => ({})\`\`); +({})\`\`; +" +`; + exports[`test objects.js 1`] = ` "/* @flow */ diff --git a/tests/objects/expression.js b/tests/objects/expression.js new file mode 100644 index 00000000..fd92a69b --- /dev/null +++ b/tests/objects/expression.js @@ -0,0 +1,2 @@ +() => ({}``); +({})``;