Skip to content

Commit

Permalink
fix(es/compat): Fix destructuring of export class/function (#8371)
Browse files Browse the repository at this point in the history
**Related issue:**
 - Closes #8366
  • Loading branch information
magic-akari committed Dec 2, 2023
1 parent c77f987 commit 630f9d3
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 1 deletion.
21 changes: 21 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8366/input/.swcrc
@@ -0,0 +1,21 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": false
},
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": true,
"env": {
"targets": "Chrome >= 50"
}
}
5 changes: 5 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8366/input/index.js
@@ -0,0 +1,5 @@
export class F {
a({ b, c } = undefined) { }
}

export function f({ b, c } = undefined) { }
8 changes: 8 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8366/output/index.js
@@ -0,0 +1,8 @@
export class F {
a(ref) {
let _ref = ref === void 0 ? undefined : ref, b = _ref.b, c = _ref.c;
}
}
export function f(ref) {
let _ref = ref === void 0 ? undefined : ref, b = _ref.b, c = _ref.c;
}
8 changes: 7 additions & 1 deletion crates/swc_ecma_compat_es2015/src/destructuring.rs
@@ -1,4 +1,4 @@
use std::iter;
use std::{iter, mem};

use serde::Deserialize;
use swc_common::{util::take::Take, Spanned, SyntaxContext, DUMMY_SP};
Expand Down Expand Up @@ -559,6 +559,12 @@ impl VisitMut for AssignFolder {
self.exporting = old;
}

fn visit_mut_function(&mut self, f: &mut Function) {
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();

Expand Down

0 comments on commit 630f9d3

Please sign in to comment.