diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index c5755a7214b..410e16583d7 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -1901,6 +1901,10 @@ impl<'a, I: Tokens> Parser { } 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 { { 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); } } } diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts b/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts new file mode 100644 index 00000000000..f85efba66e6 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts @@ -0,0 +1 @@ +1++; diff --git a/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts.stderr b/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts.stderr new file mode 100644 index 00000000000..2cf6270cd61 --- /dev/null +++ b/crates/swc_ecma_parser/tests/typescript-errors/issue-3885/input.ts.stderr @@ -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++; + : ^ + `----