fix(es/renamer): Fix renaming of default-exported declarations (#9135)

**Related issue:**

 - Closes #9129
This commit is contained in:
Donny/강동윤 2024-07-04 21:08:45 +09:00 committed by GitHub
parent 0a919cea31
commit 45f671d8d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
22 changed files with 159 additions and 10 deletions

View File

@ -0,0 +1,28 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"target": "es2022",
"transform": {
"decoratorMetadata": true,
"react": {
"refresh": true,
"development": true
}
},
"externalHelpers": true,
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": "unknown"
}

View File

@ -0,0 +1,5 @@
eval('')
export default function Foo() {
}
Foo()

View File

@ -0,0 +1,5 @@
eval('')
export function Foo() {
}
Foo()

View File

@ -0,0 +1,5 @@
eval('')
export default class Foo {
}
new Foo()

View File

@ -0,0 +1,5 @@
eval('')
export class Foo {
}
new Foo()

View File

@ -0,0 +1,6 @@
eval('');
export default function Foo() {}
_c = Foo;
Foo();
var _c;
$RefreshReg$(_c, "Foo");

View File

@ -0,0 +1,6 @@
eval('');
export function Foo() {}
_c = Foo;
Foo();
var _c;
$RefreshReg$(_c, "Foo");

View File

@ -0,0 +1,4 @@
eval('');
export default class Foo {
}
new Foo();

View File

@ -0,0 +1,4 @@
eval('');
export class Foo {
}
new Foo();

View File

@ -0,0 +1,25 @@
{
"jsc": {
"parser": {
"syntax": "typescript",
"tsx": true,
"decorators": true
},
"target": "es2022",
"transform": {
"decoratorMetadata": true,
"react": {}
},
"externalHelpers": true,
"loose": false,
"minify": {
"compress": false,
"mangle": false
}
},
"module": {
"type": "es6"
},
"minify": false,
"isModule": "unknown"
}

View File

@ -0,0 +1,5 @@
eval('')
export default function Foo() {
}
Foo()

View File

@ -0,0 +1,5 @@
eval('')
export function Foo() {
}
Foo()

View File

@ -0,0 +1,5 @@
eval('')
export default class Foo {
}
new Foo()

View File

@ -0,0 +1,5 @@
eval('')
export class Foo {
}
new Foo()

View File

@ -0,0 +1,3 @@
eval('');
export default function Foo() {}
Foo();

View File

@ -0,0 +1,3 @@
eval('');
export function Foo() {}
Foo();

View File

@ -0,0 +1,4 @@
eval('');
export default class Foo {
}
new Foo();

View File

@ -0,0 +1,4 @@
eval('');
export class Foo {
}
new Foo();

View File

@ -1,6 +1,6 @@
function x() {
(class Baz {
});
let Foo = class Foo {
};
class Foo {
}
}

View File

@ -1,4 +1,4 @@
function foo() {
let Bar = class Bar {
};
class Bar {
}
}

View File

@ -218,7 +218,7 @@ impl Visit for Analyzer {
self.add_decl(id.to_id(), true);
}
f.function.visit_with(self)
f.visit_with(self);
}
DefaultDecl::TsInterfaceDecl(_) => {}
}
@ -240,7 +240,7 @@ impl Visit for Analyzer {
maybe_grow_default(|| e.visit_children_with(self));
if let Expr::Ident(i) = e {
self.add_usage(i.to_id())
self.add_usage(i.to_id());
}
self.is_pat_decl = old_is_pat_decl;

View File

@ -202,7 +202,9 @@ macro_rules! unit {
} else {
let map = self.get_map(n, false, false, false);
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
if !map.is_empty() {
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
}
}
};
@ -214,7 +216,9 @@ macro_rules! unit {
} else {
let map = self.get_map(n, true, false, false);
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
if !map.is_empty() {
n.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
}
}
};
@ -246,6 +250,20 @@ where
unit!(visit_mut_class_decl, ClassDecl, true);
fn visit_mut_default_decl(&mut self, n: &mut DefaultDecl) {
match n {
DefaultDecl::Class(n) => {
n.visit_mut_children_with(self);
}
DefaultDecl::Fn(n) => {
n.visit_mut_children_with(self);
}
DefaultDecl::TsInterfaceDecl(n) => {
n.visit_mut_children_with(self);
}
}
}
fn visit_mut_expr(&mut self, n: &mut Expr) {
maybe_grow_default(|| n.visit_mut_children_with(self));
}
@ -284,7 +302,9 @@ where
m.visit_mut_children_with(self);
}
m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
if !map.is_empty() {
m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
}
fn visit_mut_script(&mut self, m: &mut Script) {
@ -300,7 +320,9 @@ where
m.visit_mut_children_with(self);
}
m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
if !map.is_empty() {
m.visit_mut_with(&mut rename_with_config(&map, self.config.clone()));
}
}
}