fix(es/parser): Report an error if LeftHandSideExpression is invalid (#4001)

This commit is contained in:
Sahil mobaidin 2022-03-15 08:24:19 +03:00 committed by GitHub
parent 9d6a57c6e5
commit f8d6127dd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions

View File

@ -1901,6 +1901,10 @@ impl<'a, I: Tokens> Parser<I> {
}
pub(super) fn check_assign_target(&mut self, expr: &Expr, deny_call: bool) {
if !expr.is_valid_simple_assignment_target(self.ctx().strict) {
self.emit_err(expr.span(), SyntaxError::TS2406);
}
// We follow behavior of tsc
if self.input.syntax().typescript() && self.syntax().early_errors() {
let is_eval_or_arguments = match *expr {
@ -1932,8 +1936,6 @@ impl<'a, I: Tokens> Parser<I> {
{
self.emit_err(expr.span(), SyntaxError::TS2406);
}
} else if !expr.is_valid_simple_assignment_target(self.ctx().strict) {
self.emit_err(expr.span(), SyntaxError::TS2406);
}
}
}

View File

@ -0,0 +1 @@
1++;

View File

@ -0,0 +1,6 @@
x The left-hand side of an assignment expression must be a variable or a property access.
,-[$DIR/tests/typescript-errors/issue-3885/input.ts:2:1]
2 | 1++;
: ^
`----