Repository: jlongster/prettier (js)

Issue:
While doesn't indent expressions
```js
if (a && b && c) {}
while(a && b && c) {}
```

outputs

```js
if (
  a &&
    b &&
    c
) {
}
while (a &&
  b &&
  c) {
}
```

It is weird that `if` puts the condition in a new line but not `while`. `while` is incorrect here.

Pull request description:
Indent while test the same way as if test
Fixes #312

Patch:
diff --git a/src/printer.js b/src/printer.js
index 176cbd1f7..f9307bf45 100644
--- a/src/printer.js
+++ b/src/printer.js
@@ -848,7 +848,15 @@ function genericPrintNoParens(path, options, print) {
     case "WhileStatement":
       return concat([
         "while (",
-        path.call(print, "test"),
+        group(
+          concat([
+            indent(
+              options.tabWidth,
+              concat([ softline, path.call(print, "test") ])
+            ),
+            softline
+          ])
+        ),
         ")",
         adjustClause(path.call(print, "body"), options)
       ]);


Test patch:
diff --git a/tests/while/__snapshots__/jsfmt.spec.js.snap b/tests/while/__snapshots__/jsfmt.spec.js.snap
index 61d584b89..b599239cd 100644
--- a/tests/while/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/while/__snapshots__/jsfmt.spec.js.snap
@@ -43,6 +43,27 @@ function bar(x: boolean) {
 "
 `;
 
+exports[`test indent.js 1`] = `
+"if (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {}
+while (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+if (
+  someVeryLongStringA &&
+    someVeryLongStringB &&
+    someVeryLongStringC &&
+    someVeryLongStringD
+) {
+}
+while (
+  someVeryLongStringA &&
+    someVeryLongStringB &&
+    someVeryLongStringC &&
+    someVeryLongStringD
+) {
+}
+"
+`;
+
 exports[`test test.js 1`] = `
 "class C {
     m() { return new C; }
diff --git a/tests/while/indent.js b/tests/while/indent.js
new file mode 100644
index 000000000..8f7d05400
--- /dev/null
+++ b/tests/while/indent.js
@@ -0,0 +1,2 @@
+if (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {}
+while (someVeryLongStringA && someVeryLongStringB && someVeryLongStringC && someVeryLongStringD) {}