fix: raise SyntaxError for unparenthesized assert and assign (#13099)

* fix: raise `SyntaxError` for unparenthesized assert and assign

* chore
This commit is contained in:
Federico Ciardi
2021-04-06 16:07:13 +02:00
committed by GitHub
parent 7bc72bb451
commit 7fe3ebf4db
9 changed files with 254 additions and 17 deletions

View File

@@ -2589,7 +2589,7 @@ export default (superClass: Class<Parser>): Class<Parser> =>
if (
expr.type !== "ArrowFunctionExpression" ||
(expr.extra && expr.extra.parenthesized)
expr.extra?.parenthesized
) {
abort();
}
@@ -2743,8 +2743,18 @@ export default (superClass: Class<Parser>): Class<Parser> =>
this.checkLVal(expr.parameter, "parameter property", ...args);
return;
case "TSAsExpression":
case "TSNonNullExpression":
case "TSTypeAssertion":
if (
/*bindingType*/ !args[0] &&
contextDescription !== "parenthesized expression" &&
!expr.extra?.parenthesized
) {
this.raise(expr.start, Errors.InvalidLhs, contextDescription);
break;
}
this.checkLVal(expr.expression, "parenthesized expression", ...args);
return;
case "TSNonNullExpression":
this.checkLVal(expr.expression, contextDescription, ...args);
return;
default: