Remove Parens from SequenceExpressions in ForStatements (#1597)

* Remove Parens from SequenceExpressions in ForStatements

Closes #1594

* Add Braces around Assignment Case
master
Konstantin Pschera 2017-05-12 19:14:58 +02:00 committed by Christopher Chedeau
parent 54ad598acc
commit 2fc6024a20
3 changed files with 37 additions and 2 deletions

View File

@ -448,7 +448,9 @@ FPp.needsParens = function() {
parent.object === node
);
case "AssignmentExpression":
case "AssignmentExpression": {
const grandParent = this.getParentNode(1)
if (parent.type === "ArrowFunctionExpression" && parent.body === node) {
return true;
} else if (
@ -468,9 +470,16 @@ FPp.needsParens = function() {
return node.left.type === "ObjectPattern";
} else if (parent.type === "AssignmentExpression") {
return false;
} else if (
parent.type === "SequenceExpression" &&
grandParent &&
grandParent.type === "ForStatement" &&
(grandParent.init === parent || grandParent.update === parent)
) {
return false;
}
return true;
}
case "ConditionalExpression":
switch (parent.type) {
case "TaggedTemplateExpression":

View File

@ -20,3 +20,22 @@ computedDescriptionLines =
(focused && !loading && descriptionLinesFocused) || descriptionLines;
`;
exports[`sequence.js 1`] = `
for ((i = 0), (len = arr.length); i < len; i++) {
console.log(arr[i])
}
for (i = 0, len = arr.length; i < len; i++) {
console.log(arr[i])
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for (i = 0, len = arr.length; i < len; i++) {
console.log(arr[i]);
}
for (i = 0, len = arr.length; i < len; i++) {
console.log(arr[i]);
}
`;

View File

@ -0,0 +1,7 @@
for ((i = 0), (len = arr.length); i < len; i++) {
console.log(arr[i])
}
for (i = 0, len = arr.length; i < len; i++) {
console.log(arr[i])
}