From 0a22f5ec151af64e88b07ada2ad42a077d8c57bd Mon Sep 17 00:00:00 2001 From: Zach Gawlik Date: Sat, 14 Apr 2018 15:27:18 -0400 Subject: [PATCH] Wrap awaits in unary expressions (#4315) --- src/language-js/needs-parens.js | 1 + tests/async/__snapshots__/jsfmt.spec.js.snap | 4 ++-- tests/async/await_parse.js | 2 +- tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap | 6 +++--- 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/language-js/needs-parens.js b/src/language-js/needs-parens.js index 3c1b912f..9aef0fde 100644 --- a/src/language-js/needs-parens.js +++ b/src/language-js/needs-parens.js @@ -317,6 +317,7 @@ function needsParens(path, options) { case "AwaitExpression": switch (parent.type) { case "TaggedTemplateExpression": + case "UnaryExpression": case "BinaryExpression": case "LogicalExpression": case "SpreadElement": diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 25434bdd..25b6481d 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -35,7 +35,7 @@ function *f(){ !(yield a); } async function f() { - a = !(await f()); + a = !await f(); } async () => { new A(await x); @@ -52,7 +52,7 @@ function* f() { !(yield a); } async function f() { - a = !await f(); + a = !(await f()); } async () => { new A(await x); diff --git a/tests/async/await_parse.js b/tests/async/await_parse.js index 223b643d..8c88bbc0 100644 --- a/tests/async/await_parse.js +++ b/tests/async/await_parse.js @@ -8,7 +8,7 @@ function *f(){ !(yield a); } async function f() { - a = !(await f()); + a = !await f(); } async () => { new A(await x); diff --git a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap index 252ca4cf..e968e058 100644 --- a/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap +++ b/tests/typescript/compiler/__snapshots__/jsfmt.spec.js.snap @@ -53,9 +53,9 @@ async function f() { // @target: es6 async function f() { await 0; - typeof await 0; - void await 0; - await void (typeof (void await 0)); + typeof (await 0); + void (await 0); + await void (typeof (void (await 0))); await await 0; }