mirror of
https://github.com/swc-project/swc.git
synced 2024-12-24 22:22:34 +03:00
fix(es/compat): Fix destructing of const
(#3545)
This commit is contained in:
parent
3fc16cdc1c
commit
342c320bfa
@ -960,6 +960,18 @@ impl VisitMut for AssignFolder {
|
||||
|
||||
*declarators = decls;
|
||||
}
|
||||
|
||||
fn visit_mut_var_decl(&mut self, var_decl: &mut VarDecl) {
|
||||
var_decl.decls.visit_mut_with(self);
|
||||
|
||||
if var_decl.kind == VarDeclKind::Const {
|
||||
var_decl.decls.iter_mut().for_each(|v| {
|
||||
if v.init.is_none() {
|
||||
v.init = Some(undefined(DUMMY_SP));
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Destructuring {
|
||||
|
@ -2103,3 +2103,25 @@ test!(
|
||||
assert.sameValue(iterCount, 1, 'Iteration occurred as expected');
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
statements_const_id_init_hole,
|
||||
"\
|
||||
const [x] = [,];
|
||||
const [y] = [,], [z] = [,]
|
||||
",
|
||||
"\
|
||||
const x = void 0;
|
||||
const y = void 0, z = void 0;
|
||||
"
|
||||
);
|
||||
|
||||
test!(
|
||||
syntax(),
|
||||
|_| tr(),
|
||||
statements_let_id_init_hole,
|
||||
"let [x] = [,];",
|
||||
"let x;"
|
||||
);
|
||||
|
Loading…
Reference in New Issue
Block a user