fix(es/compat): Fix destructing of const (#3545)

This commit is contained in:
magic-akari 2022-02-13 03:34:06 +08:00 committed by GitHub
parent 3fc16cdc1c
commit 342c320bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 34 additions and 0 deletions

View File

@ -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 {

View File

@ -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;"
);