diff --git a/crates/swc_ecma_compat_es2015/src/destructuring.rs b/crates/swc_ecma_compat_es2015/src/destructuring.rs index 6580f70dba3..053dc811c70 100644 --- a/crates/swc_ecma_compat_es2015/src/destructuring.rs +++ b/crates/swc_ecma_compat_es2015/src/destructuring.rs @@ -565,6 +565,24 @@ impl VisitMut for AssignFolder { self.exporting = exporting; } + fn visit_mut_class(&mut self, f: &mut Class) { + let exporting = mem::replace(&mut self.exporting, false); + f.visit_mut_children_with(self); + self.exporting = exporting; + } + + fn visit_mut_object_lit(&mut self, f: &mut ObjectLit) { + let exporting = mem::replace(&mut self.exporting, false); + f.visit_mut_children_with(self); + self.exporting = exporting; + } + + fn visit_mut_arrow_expr(&mut self, f: &mut ArrowExpr) { + let exporting = mem::replace(&mut self.exporting, false); + f.visit_mut_children_with(self); + self.exporting = exporting; + } + fn visit_mut_expr(&mut self, expr: &mut Expr) { let ignore_return_value = self.ignore_return_value.take().is_some(); diff --git a/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/input.js b/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/input.js new file mode 100644 index 00000000000..668bc000d7c --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/input.js @@ -0,0 +1,3 @@ +export class A { + constructor(t, { a, b = 6, c } = {}) {} +} diff --git a/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/output.js b/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/output.js new file mode 100644 index 00000000000..3dca18f7cf2 --- /dev/null +++ b/crates/swc_ecma_transforms_compat/tests/destructuring/pr-8470/output.js @@ -0,0 +1,5 @@ +export class A { + constructor(t, ref){ + let _ref = ref === void 0 ? {} : ref, a = _ref.a, _ref_b = _ref.b, b = _ref_b === void 0 ? 6 : _ref_b, c = _ref.c; + } +}