fix(es/compat): Handle a nullish coalescing in a switch case (#6363)

This commit is contained in:
Austaras 2022-11-06 02:31:02 +08:00 committed by GitHub
parent 0f09f82db3
commit 2de45fb0f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -74,8 +74,10 @@ impl VisitMut for NullishCoalescing {
/// Prevents #1123 /// Prevents #1123
fn visit_mut_switch_case(&mut self, s: &mut SwitchCase) { fn visit_mut_switch_case(&mut self, s: &mut SwitchCase) {
// Prevents #6328
s.test.visit_mut_with(self);
let old_vars = self.vars.take(); let old_vars = self.vars.take();
s.visit_mut_children_with(self); s.cons.visit_mut_with(self);
self.vars = old_vars; self.vars = old_vars;
} }

View File

@ -166,3 +166,14 @@ function foo(opts) {
} }
"# "#
); );
test!(
syntax(),
|_| tr(Default::default()),
issue_6328,
"switch ( 0 ) { case 0 ?? 0 : }",
r#"
var ref;
switch ( 0 ) { case (ref = 0) !== null && ref !== void 0 ? ref : 0: }
"#
);