From 565106dd63ef363771c2ae122c81652e3c755df2 Mon Sep 17 00:00:00 2001 From: Kevin Gibbons Date: Tue, 18 Apr 2017 13:28:33 -0700 Subject: [PATCH] Add parentheses for assignment as body of arrow (#1326) --- src/fast-path.js | 2 +- tests/arrows/__snapshots__/jsfmt.spec.js.snap | 4 ++++ tests/arrows/arrow_function_expression.js | 2 ++ tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap | 2 +- 4 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/fast-path.js b/src/fast-path.js index ad009a98e8dc..530003b10389 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -440,7 +440,7 @@ FPp.needsParens = function(assumeExpressionContext) { case "AssignmentExpression": if (parent.type === "ArrowFunctionExpression" && parent.body === node) { - return node.left.type === "ObjectPattern"; + return true; } else if ( parent.type === "ForStatement" && (parent.init === node || parent.update === node) diff --git a/tests/arrows/__snapshots__/jsfmt.spec.js.snap b/tests/arrows/__snapshots__/jsfmt.spec.js.snap index 414571800b3f..823e4548d9ee 100644 --- a/tests/arrows/__snapshots__/jsfmt.spec.js.snap +++ b/tests/arrows/__snapshots__/jsfmt.spec.js.snap @@ -31,6 +31,8 @@ x => ({}().b); a::(b => c); a = b => c; a = (b?) => c; +x => (y = z); +x => (y += z); ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ (a => {}).length; typeof (() => {}); @@ -63,6 +65,8 @@ x => ({}().b); a::(b => c); a = b => c; a = (b?) => c; +x => (y = z); +x => (y += z); `; diff --git a/tests/arrows/arrow_function_expression.js b/tests/arrows/arrow_function_expression.js index 3435c4174722..64e2b67608e4 100644 --- a/tests/arrows/arrow_function_expression.js +++ b/tests/arrows/arrow_function_expression.js @@ -28,3 +28,5 @@ x => ({}().b); a::(b => c); a = b => c; a = (b?) => c; +x => (y = z); +x => (y += z); diff --git a/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap b/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap index 4412f32f6072..4f77b4e22276 100644 --- a/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap @@ -51,7 +51,7 @@ a[1] = "..."; foo(a[1]); var y; -a.forEach(x => y = x); +a.forEach(x => (y = x)); // for literals, composite element type is union of individuals // note: test both tuple and non-tuple inferred literals