Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion crates/swc_ecma_lexer/src/common/parser/pat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ fn reparse_expr_as_pat_inner<'a>(
| Expr::Class(..)
| Expr::Paren(..)
| Expr::Tpl(..)
| Expr::TsAs(..) => {
| Expr::TsAs(..)
| Expr::TsNonNull(..)
| Expr::TsTypeAssertion(..)
| Expr::TsInstantiation(..)
| Expr::TsSatisfies(..) => {
if !expr.is_valid_simple_assignment_target(p.ctx().contains(Context::Strict)) {
p.emit_err(span, SyntaxError::NotSimpleAssign)
}
Expand Down
23 changes: 23 additions & 0 deletions crates/swc_ecma_parser/tests/typescript/issue-11142/input.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Test case for issue #11142: Non-null assertion in destructuring assignment

// Original issue case: array element swapping with non-null assertions
let arrayCopy = [1, 2, 3];
let currentIndex = 0;
let randomIndex = 1;
[arrayCopy[currentIndex]!, arrayCopy[randomIndex]!] = [arrayCopy[randomIndex]!, arrayCopy[currentIndex]!];

// Simple non-null assertion in array destructuring
let a: number | null = 1;
let b: number | null = 2;
[a!, b!] = [b!, a!];

// Non-null assertion with member expressions
let obj: { x?: number; y?: number } = { x: 1, y: 2 };
[obj.x!, obj.y!] = [obj.y!, obj.x!];

// Non-null assertion in object destructuring
({ x: obj.x! } = { x: 5 });

// Complex nested case
let arr: (number | null)[][] = [[1, 2], [3, 4]];
[arr[0]![0]!, arr[1]![1]!] = [arr[1]![1]!, arr[0]![0]!];
Loading
Loading