From f0d2ad45081012e286c35483aa5e96d49fff5863 Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Mon, 16 Jan 2017 21:47:13 -0600 Subject: [PATCH] Fix parens for functions inside TaggedTemplateExpression (#259) --- src/fast-path.js | 1 + tests/arrows/__snapshots__/jsfmt.spec.js.snap | 3 +++ tests/arrows/arrow_function_expression.js | 1 + tests/function/__snapshots__/jsfmt.spec.js.snap | 3 +++ tests/function/function_expression.js | 1 + 5 files changed, 9 insertions(+) diff --git a/src/fast-path.js b/src/fast-path.js index cc195dc92..94b2fcf44 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -374,6 +374,7 @@ FPp.needsParens = function(assumeExpressionContext) { switch (parent.type) { case "MemberExpression": + case "TaggedTemplateExpression": case "UnaryExpression": return true; diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 3e6449a4b..9e447683e 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -30,6 +30,7 @@ exports[`test arrow_function_expression.js 1`] = ` typeof (() => {}); export default (() => {})(); (() => {})()\`\`; +(() => {})\`\`; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a => { }).length; @@ -39,6 +40,8 @@ export default (() => { })() (() => { })()\`\`; +(() => { +})\`\`; " `; diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js index f0309346f..dac425060 100644 --- a/tests/arrows/arrow_function_expression.js +++ b/tests/arrows/arrow_function_expression.js @@ -2,3 +2,4 @@ typeof (() => {}); export default (() => {})(); (() => {})()``; +(() => {})``; diff --git a/tests/function/__snapshots__/jsfmt.spec.js.snap b/tests/function/__snapshots__/jsfmt.spec.js.snap index a776342cc..cb2af2b51 100644 --- a/tests/function/__snapshots__/jsfmt.spec.js.snap +++ b/tests/function/__snapshots__/jsfmt.spec.js.snap @@ -356,6 +356,7 @@ exports[`test function_expression.js 1`] = ` typeof (function() {}); export default (function() {})(); (function() {})()\`\`; +(function() {})\`\`; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (function() { }).length; @@ -365,6 +366,8 @@ export default (function() { })() (function() { })()\`\`; +(function() { +})\`\`; " `; diff --git a/tests/function/function_expression.js b/tests/function/function_expression.js index 786e8bdb5..93c6da8ec 100644 --- a/tests/function/function_expression.js +++ b/tests/function/function_expression.js @@ -2,3 +2,4 @@ typeof (function() {}); export default (function() {})(); (function() {})()``; +(function() {})``;