Skip to content

Commit 5a74b97

Browse files
authored
Prevent await expression from being treated as an assignment target, fixes #240 (#241)
1 parent a34dc7c commit 5a74b97

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/main/java/com/shapesecurity/shift/es2017/parser/GenericParser.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,6 +1442,7 @@ protected Either3<Expression, Pair<FormalParameters, Boolean>, AssignmentTarget>
14421442
AdditionalStateT startState = this.startNode();
14431443

14441444
if (this.allowAwaitExpression && this.eat(TokenType.AWAIT)) {
1445+
this.isBindingElement = this.isAssignmentTarget = false;
14451446
Either3<Expression, Pair<FormalParameters, Boolean>, AssignmentTarget> expression = this.isolateCoverGrammar(this::parseUnaryExpression);
14461447
return Either3.left(this.finishNode(startState, new AwaitExpression(expression.left().fromJust())));
14471448
}

src/test/java/com/shapesecurity/shift/es2017/parser/miscellaneous/AsyncAwaitTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public void testAsyncMisc() throws JsError {
102102
testScript("async ((a))", new CallExpression(new IdentifierExpression("async"), ImmutableList.of(new IdentifierExpression("a"))));
103103
testScript("async function a(){}(0)", new Script(ImmutableList.empty(), ImmutableList.of(new FunctionDeclaration(true, false, new BindingIdentifier("a"), new FormalParameters(ImmutableList.empty(), Maybe.empty()), new FunctionBody(ImmutableList.empty(), ImmutableList.empty())), new ExpressionStatement(new LiteralNumericExpression(0.0)))));
104104
testScript("(async function a(){}(0))", new CallExpression(new FunctionExpression(true, false, Maybe.of(new BindingIdentifier("a")), new FormalParameters(ImmutableList.empty(), Maybe.empty()), new FunctionBody(ImmutableList.empty(), ImmutableList.empty())), ImmutableList.of(new LiteralNumericExpression(0.0))));
105+
testScript("(async function() { (await y); })", new FunctionExpression(true, false, Maybe.empty(), new FormalParameters(ImmutableList.empty(), Maybe.empty()), new FunctionBody(ImmutableList.empty(), ImmutableList.of(new ExpressionStatement(new AwaitExpression(new IdentifierExpression("y")))))));
105106
}
106107

107108
@Test

0 commit comments

Comments
 (0)