@@ -364,14 +364,15 @@ protected BindingProperty parseBindingProperty() throws JsError {
364364
365365 if ((token .type == TokenType .IDENTIFIER || token .type == TokenType .LET || token .type == TokenType .YIELD ) && name instanceof StaticPropertyName ) {
366366 if (!this .match (TokenType .COLON )) {
367+ if (token .type == TokenType .YIELD && this .allowYieldExpression ) {
368+ throw this .createUnexpected (token );
369+ }
367370 Maybe <Expression > defaultValue = Maybe .empty ();
368371 if (this .eat (TokenType .ASSIGN )) {
369372 boolean previousAllowYieldExpression = this .allowYieldExpression ;
370373 Either <Expression , AssignmentTarget > expr = this .parseAssignmentExpression ();
371374 defaultValue = expr .left ();
372375 this .allowYieldExpression = previousAllowYieldExpression ;
373- } else if (token .type == TokenType .YIELD && this .allowYieldExpression ) {
374- throw this .createUnexpected (token );
375376 }
376377 return this .finishNode (startState , new BindingPropertyIdentifier ((BindingIdentifier ) binding .fromJust (), defaultValue ));
377378 }
@@ -551,6 +552,11 @@ protected FormalParameters parseParams() throws JsError {
551552 while (!this .eof ()) {
552553 if (this .eat (TokenType .ELLIPSIS )) {
553554 rest = parseBindingTarget ();
555+ if (this .match (TokenType .ASSIGN )) {
556+ throw this .createError (ErrorMessages .UNEXPECTED_REST_PARAMETERS_INITIALIZATION );
557+ } else if (this .match (TokenType .COMMA )) {
558+ throw this .createUnexpected (this .lookahead );
559+ }
554560 break ;
555561 }
556562 items .add (this .parseParam ());
@@ -1589,7 +1595,11 @@ protected Either3<ExpressionSuper, Pair<FormalParameters, Boolean>, AssignmentTa
15891595 Maybe <Binding > rest = Maybe .empty ();
15901596 Maybe <SpreadElementExpression > lastArgument = arguments .maybeLast ();
15911597 if (lastArgument .isJust () && lastArgument .fromJust () instanceof SpreadElement ) {
1592- rest = Maybe .of (this .targetToBinding (this .transformDestructuring (((SpreadElement ) lastArgument .fromJust ()).expression )));
1598+ BindingBindingWithDefault binding = this .targetToBindingPossiblyWithDefault (this .transformDestructuringWithDefault (((SpreadElement ) lastArgument .fromJust ()).expression ));
1599+ if (binding instanceof BindingWithDefault ) {
1600+ throw this .createError (ErrorMessages .UNEXPECTED_REST_PARAMETERS_INITIALIZATION );
1601+ }
1602+ rest = Maybe .of ((Binding ) binding );
15931603 arguments = arguments .take (arguments .length - 1 );
15941604 }
15951605 // evil java hack
@@ -2191,16 +2201,31 @@ protected Either<ObjectProperty, AssignmentTargetProperty> parsePropertyDefiniti
21912201 this .isBindingElement = this .isAssignmentTarget = false ;
21922202 return Either .left (keyOrMethod .right ().fromJust ());
21932203 } else if (keyOrMethod .isLeft ()) {
2204+ if (token .type == TokenType .AWAIT && this .firstAwaitLocation == null ) {
2205+ this .firstAwaitLocation = this .getLocation ();
2206+ }
21942207 PropertyName propName = keyOrMethod .left ().fromJust ();
21952208 if (propName instanceof StaticPropertyName ) {
21962209 StaticPropertyName staticPropertyName = (StaticPropertyName ) propName ;
21972210 if (this .eat (TokenType .ASSIGN )) {
2211+ if (this .allowYieldExpression && token .type == TokenType .YIELD ) {
2212+ throw this .createError (ErrorMessages .INVALID_TOKEN_CONTEXT , "yield" );
2213+ }
2214+ if (this .allowAwaitExpression && token .type == TokenType .AWAIT ) {
2215+ throw this .createError (ErrorMessages .INVALID_TOKEN_CONTEXT , "await" );
2216+ }
21982217 Expression init = this .isolateCoverGrammar (this ::parseAssignmentExpression ).left ().fromJust ();
21992218 this .firstExprError = this .createErrorWithLocation (startLocation , ErrorMessages .ILLEGAL_PROPERTY );
22002219 AssignmentTargetPropertyIdentifier toReturn = new AssignmentTargetPropertyIdentifier (this .transformDestructuring (staticPropertyName ), Maybe .of (init ));
22012220 return Either .right (this .finishNode (startState , toReturn ));
22022221 }
22032222 if (!this .match (TokenType .COLON )) {
2223+ if (this .allowYieldExpression && token .type == TokenType .YIELD ) {
2224+ throw this .createError (ErrorMessages .INVALID_TOKEN_CONTEXT , "yield" );
2225+ }
2226+ if (this .allowAwaitExpression && token .type == TokenType .AWAIT ) {
2227+ throw this .createError (ErrorMessages .INVALID_TOKEN_CONTEXT , "await" );
2228+ }
22042229 if (token .type != TokenType .IDENTIFIER && token .type != TokenType .YIELD && token .type != TokenType .LET && token .type != TokenType .ASYNC && token .type != TokenType .AWAIT ) {
22052230 throw this .createUnexpected (token );
22062231 }
@@ -2302,7 +2327,6 @@ protected Either<PropertyName, MethodDefinition> parseMethodDefinition() throws
23022327 if (isGenerator && this .match (TokenType .COLON )) {
23032328 throw this .createUnexpected (this .lookahead );
23042329 }
2305-
23062330 return Either .left (name );
23072331 }
23082332
0 commit comments