From 41d92c1187e27f0832829f69ae268f1db8ea46f6 Mon Sep 17 00:00:00 2001 From: Christopher Chedeau Date: Sun, 22 Jan 2017 15:52:35 -0800 Subject: [PATCH] Fix in inside of the first group of a for (#406) Fixes #405 --- src/fast-path.js | 4 ++++ tests/for/__snapshots__/jsfmt.spec.js.snap | 8 ++++++++ tests/for/in.js | 1 + 3 files changed, 13 insertions(+) create mode 100644 tests/for/in.js diff --git a/src/fast-path.js b/src/fast-path.js index 0220b0ac2..36b55f3a8 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 274a6614a..e0ce51b1c 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 000000000..5fb450d16 --- /dev/null +++ b/tests/for/in.js @@ -0,0 +1 @@ +for ((x in a);;) {}