Repository: jlongster/prettier (js)

Issue:
Incorrectly removing parenthesis around await expression
Before:

```js
    assert.equal(
      (await driver.browser.activeWindow.navigator.getUrl()).substr(-7),
      '?q=1357',
    );
```

After:

```js
assert.equal(await driver.browser.activeWindow.navigator.getUrl().substr(-7), '?q=1357');
```

Before this change, the expression being awaited was:

```js
driver.browser.activeWindow.navigator.getUrl()
```

but after it is:

```js
driver.browser.activeWindow.navigator.getUrl().substr(-7)
```

Pull request:
Fix await parenthesis
This is the first time I'm adding something inside of fast-path so I'm not sure if it's correct, but it seems more correct than before!

Fixes #164

Patch:
diff --git a/src/fast-path.js b/src/fast-path.js
index 5299ebc1c..4bda096aa 100644
--- a/src/fast-path.js
+++ b/src/fast-path.js
@@ -289,6 +289,7 @@ FPp.needsParens = function(assumeExpressionContext) {
           return true;
       }
 
+    case "AwaitExpression":
     case "YieldExpression":
       switch (parent.type) {
         case "BinaryExpression":
@@ -296,13 +297,14 @@ FPp.needsParens = function(assumeExpressionContext) {
         case "UnaryExpression":
         case "SpreadElement":
         case "SpreadProperty":
-        case "CallExpression":
-        case "MemberExpression":
         case "NewExpression":
         case "ConditionalExpression":
-        case "YieldExpression":
+        case "MemberExpression":
           return true;
 
+        case "CallExpression":
+          return parent.callee === node;
+
         default:
           return false;
       }


Test patch:
diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap
index 53f85d5cb..d0b6434b0 100644
--- a/tests/async/__snapshots__/jsfmt.spec.js.snap
+++ b/tests/async/__snapshots__/jsfmt.spec.js.snap
@@ -459,6 +459,13 @@ console.log(x.await);
 
 var await = 3;
 var y = { await };
+
+async function f() { (await f()).length }
+async function g() {
+  invariant(
+    (await driver.navigator.getUrl()).substr(-7)
+  );
+}
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 async function f() {
   await 1;
@@ -514,5 +521,12 @@ console.log(x.await);
 
 var await = 3;
 var y = { await };
+
+async function f() {
+  (await f()).length;
+}
+async function g() {
+  invariant((await driver.navigator.getUrl()).substr(-7));
+}
 "
 `;
diff --git a/tests/async/await_parse.js b/tests/async/await_parse.js
index 10149204e..042e679b0 100644
--- a/tests/async/await_parse.js
+++ b/tests/async/await_parse.js
@@ -22,3 +22,10 @@ console.log(x.await);
 
 var await = 3;
 var y = { await };
+
+async function f() { (await f()).length }
+async function g() {
+  invariant(
+    (await driver.navigator.getUrl()).substr(-7)
+  );
+}