Remove Parens from SequenceExpressions in ForStatements (#1597)

* Remove Parens from SequenceExpressions in ForStatements

Closes #1594

* Add Braces around Assignment Case
This commit is contained in:
Konstantin Pschera authored and Christopher Chedeau committed 2017-05-12 10:14:58 -07:00
1 parent 54ad598acc
commit 2fc6024a20
3 files changed
+37 -2

No files matched your search

+11 -2
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":
@@ -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]);
}
`;
+7
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])
}