diff --git a/src/fast-path.js b/src/fast-path.js index 10259133e..660830188 100644 --- a/src/fast-path.js +++ b/src/fast-path.js @@ -388,7 +388,10 @@ FPp.needsParens = function() { } case "YieldExpression": - if (parent.type === "UnaryExpression") { + if ( + parent.type === "UnaryExpression" || + parent.type === "AwaitExpression" + ) { return true; } // else fall through @@ -524,6 +527,7 @@ FPp.needsParens = function() { case "UnaryExpression": case "LogicalExpression": case "BinaryExpression": + case "AwaitExpression": return true; case "ConditionalExpression": diff --git a/tests/async/__snapshots__/jsfmt.spec.js.snap b/tests/async/__snapshots__/jsfmt.spec.js.snap index 0885e8461..c3ffa44fc 100644 --- a/tests/async/__snapshots__/jsfmt.spec.js.snap +++ b/tests/async/__snapshots__/jsfmt.spec.js.snap @@ -67,3 +67,18 @@ async function f() { } `; + +exports[`parens.js 1`] = ` +async function *f(){ await (yield x); } + +async function f(){ await (() => {}); } +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +async function* f() { + await (yield x); +} + +async function f() { + await (() => {}); +} + +`; diff --git a/tests/async/parens.js b/tests/async/parens.js new file mode 100644 index 000000000..d29e195ef --- /dev/null +++ b/tests/async/parens.js @@ -0,0 +1,3 @@ +async function *f(){ await (yield x); } + +async function f(){ await (() => {}); }