diff --git a/src/printer.js b/src/printer.js index 56c6ec1b..79f83e76 100644 --- a/src/printer.js +++ b/src/printer.js @@ -672,6 +672,9 @@ function genericPrintNoParens(path, options, print, args) { parent.type === "FunctionDeclaration" || parent.type === "ObjectMethod" || parent.type === "ClassMethod" || + parent.type === "ForStatement" || + parent.type === "WhileStatement" || + parent.type === "DoWhileStatement" || (parent.type === "CatchClause" && !parentParent.finalizer)) ) { return "{}"; diff --git a/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap b/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap index 5770f352..f719f7b0 100644 --- a/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/binding/__snapshots__/jsfmt.spec.js.snap @@ -629,14 +629,12 @@ function try_scope() { function for_scope_let() { let a: number = 0; - for (let a = "" /* ok: local to init */; ; ) { - } + for (let a = "" /* ok: local to init */; ; ) {} } function for_scope_var() { var a: number = 0; - for (var a = "" /* error: string ~> number */; ; ) { - } + for (var a = "" /* error: string ~> number */; ; ) {} } function for_in_scope_let(o: Object) { diff --git a/tests/flow/refi/__snapshots__/jsfmt.spec.js.snap b/tests/flow/refi/__snapshots__/jsfmt.spec.js.snap index 3e40c2f0..0b79b0f0 100644 --- a/tests/flow/refi/__snapshots__/jsfmt.spec.js.snap +++ b/tests/flow/refi/__snapshots__/jsfmt.spec.js.snap @@ -591,8 +591,7 @@ var tests = [ function() { let x: { foo: ?string } = { foo: null }; if (!x.foo) { - while (false) { - } + while (false) {} x.foo = "foo"; } (x.foo: string); @@ -601,8 +600,7 @@ var tests = [ function() { let x: { foo: ?string } = { foo: null }; if (!x.foo) { - for (var i = 0; i < 0; i++) { - } + for (var i = 0; i < 0; i++) {} x.foo = "foo"; } (x.foo: string); diff --git a/tests/for/__snapshots__/jsfmt.spec.js.snap b/tests/for/__snapshots__/jsfmt.spec.js.snap index 4197dedb..24959ca8 100644 --- a/tests/for/__snapshots__/jsfmt.spec.js.snap +++ b/tests/for/__snapshots__/jsfmt.spec.js.snap @@ -74,10 +74,8 @@ for (var i = 0; i < 10; ++i) {} for (;;) 0; for (var i = 0; i < 10; ++i) 0; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -for (;;) { -} -for (var i = 0; i < 10; ++i) { -} +for (;;) {} +for (var i = 0; i < 10; ++i) {} for (;;) 0; for (var i = 0; i < 10; ++i) 0; @@ -98,10 +96,8 @@ async function f() { } for (a in b) 0; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -for ((x in a); ; ) { -} -for (a = (a in b); ; ) { -} +for ((x in a); ; ) {} +for (a = (a in b); ; ) {} for (let a = (b in c); ; ); for (a && (b in c); ; ); for (a => (b in c); ; ); diff --git a/tests/label/__snapshots__/jsfmt.spec.js.snap b/tests/label/__snapshots__/jsfmt.spec.js.snap index 479ba764..a9805a66 100644 --- a/tests/label/__snapshots__/jsfmt.spec.js.snap +++ b/tests/label/__snapshots__/jsfmt.spec.js.snap @@ -8,8 +8,7 @@ exports[`comment.js 1`] = ` ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ { // goto emulation - inf_leave: for (;;) { - } + inf_leave: for (;;) {} } `; diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap index 1b37a7c6..43533aa7 100644 --- a/tests/while/__snapshots__/jsfmt.spec.js.snap +++ b/tests/while/__snapshots__/jsfmt.spec.js.snap @@ -23,10 +23,8 @@ while ( someVeryLongStringB && someVeryLongStringC && someVeryLongStringD -) { -} -do { -} while ( +) {} +do {} while ( someVeryLongStringA && someVeryLongStringB && someVeryLongStringC &&