Remove extra parenthesis around await inside of unary expression (#745)

Big props to @bakkot for mentioning that yield shouldn't be applied the same treatment.

Fixes #728
master
Christopher Chedeau 2017-02-20 06:14:33 -08:00 committed by James Long
parent 0f34fb91eb
commit 135a3dd0a7
3 changed files with 24 additions and 3 deletions

View File

@ -354,12 +354,14 @@ FPp.needsParens = function(assumeExpressionContext) {
}
case "YieldExpression":
if (parent.type === "UnaryExpression") {
return true;
}
case "AwaitExpression":
switch (parent.type) {
case "TaggedTemplateExpression":
case "BinaryExpression":
case "LogicalExpression":
case "UnaryExpression":
case "SpreadElement":
case "SpreadProperty":
case "NewExpression":

View File

@ -4,13 +4,26 @@ async function g() {
invariant(
(await driver.navigator.getUrl()).substr(-7)
);
}~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
}
function *f(){
!(yield a);
}
async function f() {
a = !(await f());
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
async function f() {
(await f()).length;
}
async function g() {
invariant((await driver.navigator.getUrl()).substr(-7));
}
function* f() {
!(yield a);
}
async function f() {
a = !await f();
}
"
`;

View File

@ -3,4 +3,10 @@ async function g() {
invariant(
(await driver.navigator.getUrl()).substr(-7)
);
}
}
function *f(){
!(yield a);
}
async function f() {
a = !(await f());
}