Added parens around in operator in for loops 🚀. (#468)

master
Davy Duperron 2017-01-25 23:24:25 +01:00 committed by Christopher Chedeau
parent 620cb7be19
commit 03b4ed2fcf
3 changed files with 11 additions and 0 deletions

View File

@ -276,6 +276,13 @@ FPp.needsParens = function(assumeExpressionContext) {
return true;
}
if (
node.operator === 'in' &&
parent.type === 'AssignmentExpression'
) {
return true;
}
case "LogicalExpression":
switch (parent.type) {
case "CallExpression":

View File

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

View File

@ -1 +1,2 @@
for ((x in a);;) {}
for (a=(a in b);;) {}