From 105a164423d66ac14e0cd686fe4a7d2154bd66bb Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 16:22:49 -0800 Subject: [PATCH] Add parenthesis around class expression when left side of call expression (#409) Fixes #402 --- src/fast-path.js | 4 ++++ tests/classes/__snapshots__/jsfmt.spec.js.snap | 7 +++++++ tests/classes/call.js | 1 + 3 files changed, 12 insertions(+) create mode 100644 tests/classes/call.js diff --git a/src/fast-path.js b/src/fast-path.js index d95a1c8c7..da77d6ee2 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -434,6 +434,10 @@ FPp.needsParens = function(assumeExpressionContext) { case "ExportDefaultDeclaration": case "ExpressionStatement": return true; + case "CallExpression": + if (parent.callee === node) { + return true; + } } return false; diff --git a/tests/classes/__snapshots__/jsfmt.spec.js.snap b/tests/classes/__snapshots__/jsfmt.spec.js.snap index d2de13bf1..0a7f5ef2d 100644 --- a/tests/classes/__snapshots__/jsfmt.spec.js.snap +++ b/tests/classes/__snapshots__/jsfmt.spec.js.snap @@ -87,6 +87,13 @@ exports[`test binary.js 1`] = ` " `; +exports[`test call.js 1`] = ` +"(class {})(class {}); +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +(class {})(class {}); +" +`; + exports[`test class_shapes.js 1`] = ` "/* @flow */ diff --git a/tests/classes/call.js b/tests/classes/call.js new file mode 100644 index 000000000..d530fa291 --- /dev/null +++ b/tests/classes/call.js @@ -0,0 +1 @@ +(class {})(class {});