From b8a7e5166bc3767d3740704e9cc1429b4eb4ffcc Mon Sep 17 00:00:00 2001 From: Brian Ng Date: Wed, 15 Mar 2017 20:52:31 -0500 Subject: [PATCH] Add parens for ConditionalExpression inside JSXSpreadAttribute (#1015) --- src/fast-path.js | 1 + tests/jsx/__snapshots__/jsfmt.spec.js.snap | 8 ++++++++ tests/jsx/parens.js | 2 ++ 3 files changed, 11 insertions(+) diff --git a/src/fast-path.js b/src/fast-path.js index 8bbc490f..7106ebff 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -440,6 +440,7 @@ FPp.needsParens = function(assumeExpressionContext) { case "LogicalExpression": case "ExportDefaultDeclaration": case "AwaitExpression": + case "JSXSpreadAttribute": return true; case "NewExpression": diff --git a/tests/jsx/__snapshots__/jsfmt.spec.js.snap b/tests/jsx/__snapshots__/jsfmt.spec.js.snap index 03f6a439..3b06f8f7 100644 --- a/tests/jsx/__snapshots__/jsfmt.spec.js.snap +++ b/tests/jsx/__snapshots__/jsfmt.spec.js.snap @@ -551,6 +551,8 @@ exports[`parens.js 1`] = ` d='M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,' />, ]; + +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = [ ]; + +
; " `; @@ -576,6 +580,8 @@ exports[`parens.js 2`] = ` d='M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,' />, ]; + +
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ a = [ ]; + +
; " `; diff --git a/tests/jsx/parens.js b/tests/jsx/parens.js index be145cc3..36d0e71a 100644 --- a/tests/jsx/parens.js +++ b/tests/jsx/parens.js @@ -8,3 +8,5 @@ a = [ d='M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,M13.6,10.6l,4-2.8L9.5,' />, ]; + +