mirror of
https://github.com/swc-project/swc.git
synced 2024-11-24 10:12:42 +03:00
fix(es/compat): Fix destructuring of an empty array (#6314)
This commit is contained in:
parent
06a664a1f4
commit
3bea6f7248
@ -160,8 +160,9 @@ impl AssignFolder {
|
||||
if is_literal(&init) {
|
||||
match *init {
|
||||
Expr::Array(arr)
|
||||
if elems.len() == arr.elems.len()
|
||||
|| (elems.len() < arr.elems.len() && has_rest_pat(&elems)) =>
|
||||
if !elems.is_empty()
|
||||
&& (elems.len() == arr.elems.len()
|
||||
|| (elems.len() < arr.elems.len() && has_rest_pat(&elems))) =>
|
||||
{
|
||||
let mut arr_elems = Some(arr.elems.into_iter());
|
||||
elems.into_iter().for_each(|p| match p {
|
||||
|
@ -2261,3 +2261,27 @@ test!(
|
||||
"let [x] = [,];",
|
||||
"let x;"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
issue_6304,
|
||||
"let [] = [];",
|
||||
"let ref = [];"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
issue_6304_1,
|
||||
"let [] = [,];",
|
||||
"let ref = [,];"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
issue_6304_2,
|
||||
"let [] = [...[1, 2, 3]];",
|
||||
"let ref = [...[1, 2, 3]];"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user