Skip to content

Commit

Permalink
Add parentheses for assignment as body of arrow (#1326)
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkot authored and vjeux committed Apr 18, 2017
1 parent 652e2f9 commit 565106d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fast-path.js
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions tests/arrows/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -31,6 +31,8 @@ x => ({}().b);
a::(b => c);
a = b => c;
a = (b?) => c;
x => (y = z);
x => (y += z);
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(a => {}).length;
typeof (() => {});
Expand Down Expand Up @@ -63,6 +65,8 @@ x => ({}().b);
a::(b => c);
a = b => c;
a = (b?) => c;
x => (y = z);
x => (y += z);
`;

Expand Down
2 changes: 2 additions & 0 deletions tests/arrows/arrow_function_expression.js
Expand Up @@ -28,3 +28,5 @@ x => ({}().b);
a::(b => c);
a = b => c;
a = (b?) => c;
x => (y = z);
x => (y += z);
2 changes: 1 addition & 1 deletion tests/flow/arrays/__snapshots__/jsfmt.spec.js.snap
Expand Up @@ -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
Expand Down

0 comments on commit 565106d

Please sign in to comment.