diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.1.normal.js index 2ee297f1662..9f5a82215c0 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.1.normal.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.2.minified.js index 2ee297f1662..9f5a82215c0 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es2015.2.minified.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.1.normal.js index 2ee297f1662..9f5a82215c0 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.1.normal.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.2.minified.js index 2ee297f1662..9f5a82215c0 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity11_es5.2.minified.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.1.normal.js index 2ee297f1662..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.1.normal.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.2.minified.js index 2ee297f1662..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es2015.2.minified.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.1.normal.js index 2ee297f1662..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.1.normal.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.2.minified.js index 2ee297f1662..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity15_es5.2.minified.js @@ -1 +1,12 @@ -1 >>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.1.normal.js index 9aa6b1ce836..a2218e071dc 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.1.normal.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.2.minified.js index 9aa6b1ce836..a2218e071dc 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es2015.2.minified.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.1.normal.js index 9aa6b1ce836..a2218e071dc 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.1.normal.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.2.minified.js index 9aa6b1ce836..a2218e071dc 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity16_es5.2.minified.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 >>>= 2; +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.1.normal.js index 9aa6b1ce836..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.1.normal.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.2.minified.js index 9aa6b1ce836..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es2015.2.minified.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.1.normal.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.1.normal.js index 9aa6b1ce836..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.1.normal.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.1.normal.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.2.minified.js b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.2.minified.js index 9aa6b1ce836..fdaf92df13e 100644 --- a/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.2.minified.js +++ b/crates/swc/tests/tsc-references/parserGreaterThanTokenAmbiguity20_es5.2.minified.js @@ -1 +1,12 @@ -1 >>>= 2; +//! +//! x The left-hand side of an assignment expression must be a variable or a property access. +//! ,---- +//! 1 | 1 +//! : ^ +//! `---- +//! +//! +//!Caused by: +//! 0: failed to process input file +//! 1: error was recoverable, but proceeding would result in wrong codegen +//! 2: Syntax Error diff --git a/crates/swc_ecma_parser/src/parser/expr.rs b/crates/swc_ecma_parser/src/parser/expr.rs index f5584f97c6d..282dfe35eb3 100644 --- a/crates/swc_ecma_parser/src/parser/expr.rs +++ b/crates/swc_ecma_parser/src/parser/expr.rs @@ -158,12 +158,14 @@ impl Parser { .map(Box::new) .map(PatOrExpr::Pat)? } else { - //It is an early Reference Error if IsValidSimpleAssignmentTarget of + // It is an early Reference Error if IsValidSimpleAssignmentTarget of // LeftHandSideExpression is false. - if !self.input.syntax().typescript() - && !cond.is_valid_simple_assignment_target(self.ctx().strict) - { - self.emit_err(cond.span(), SyntaxError::NotSimpleAssign) + if !cond.is_valid_simple_assignment_target(self.ctx().strict) { + if self.input.syntax().typescript() { + self.emit_err(cond.span(), SyntaxError::TS2406); + } else { + self.emit_err(cond.span(), SyntaxError::NotSimpleAssign) + } } if self.input.syntax().typescript() && cond