diff --git a/src/fast-path.js b/src/fast-path.js index 0220b0ac..36b55f3a 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -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": diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 274a6614..e0ce51b1 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -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 = {}; []; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/tests/for/in.js b/tests/for/in.js new file mode 100644 index 00000000..5fb450d1 --- /dev/null +++ b/tests/for/in.js @@ -0,0 +1 @@ +for ((x in a);;) {}