Don't force line break in empty loop bodies (#1815)

This makes them consistent with empty function bodies.

Fixes https://github.com/prettier/prettier/issues/1356
master
Joseph Frazier 2017-05-30 12:39:10 -04:00 committed by Christopher Chedeau
parent eeb8616e3c
commit ea27846d1f
6 changed files with 14 additions and 22 deletions

View File

@ -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 "{}";

View File

@ -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) {

View File

@ -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);

View File

@ -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); ; );

View File

@ -8,8 +8,7 @@ exports[`comment.js 1`] = `
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
{
// goto emulation
inf_leave: for (;;) {
}
inf_leave: for (;;) {}
}
`;

View File

@ -23,10 +23,8 @@ while (
someVeryLongStringB &&
someVeryLongStringC &&
someVeryLongStringD
) {
}
do {
} while (
) {}
do {} while (
someVeryLongStringA &&
someVeryLongStringB &&
someVeryLongStringC &&