Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(es/compat): Destructuring of export class/funtion #8371

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 21 additions & 0 deletions crates/swc/tests/fixture/issues-8xxx/8366/input/.swcrc
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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