fix(es/compat): Fix destructuring of export class/function (#8371)

**Related issue:**
 - Closes #8366
This commit is contained in:
magic-akari 2023-12-03 07:23:06 +08:00 committed by GitHub
parent c77f987b9b
commit 630f9d342f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 41 additions and 1 deletions

View File

@ -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"
}
}

View File

@ -0,0 +1,5 @@
export class F {
a({ b, c } = undefined) { }
}
export function f({ b, c } = undefined) { }

View File

@ -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;
}

View File

@ -1,4 +1,4 @@
use std::iter; use std::{iter, mem};
use serde::Deserialize; use serde::Deserialize;
use swc_common::{util::take::Take, Spanned, SyntaxContext, DUMMY_SP}; use swc_common::{util::take::Take, Spanned, SyntaxContext, DUMMY_SP};
@ -559,6 +559,12 @@ impl VisitMut for AssignFolder {
self.exporting = old; 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) { fn visit_mut_expr(&mut self, expr: &mut Expr) {
let ignore_return_value = self.ignore_return_value.take().is_some(); let ignore_return_value = self.ignore_return_value.take().is_some();