Fix in inside of the first group of a for (#406)

Fixes #405
master
Christopher Chedeau 2017-01-22 15:52:35 -08:00 committed by GitHub
parent 2f220de204
commit 41d92c1187
3 changed files with 13 additions and 0 deletions

View File

@ -267,6 +267,10 @@ FPp.needsParens = function(assumeExpressionContext) {
}
case "BinaryExpression":
if (node.operator === "in" && parent.type === "ForStatement" && parent.init === node) {
return true;
}
case "LogicalExpression":
switch (parent.type) {
case "CallExpression":

View File

@ -292,6 +292,14 @@ for (var i = 0; i < 10; ++i) {
"
`;
exports[`test in.js 1`] = `
"for ((x in a);;) {}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
for ((x in a); ; ) {
}
"
`;
exports[`test var.js 1`] = `
"for (a in b) var c = {}; [];
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

1
tests/for/in.js Normal file
View File

@ -0,0 +1 @@
for ((x in a);;) {}