mirror of
https://github.com/swc-project/swc.git
synced 2024-10-04 20:28:43 +03:00
fix(es/renamer): Fix renaming of default-exported declarations (#9135)
**Related issue:** - Closes #9129
This commit is contained in:
parent
0a919cea31
commit
45f671d8d8
28
crates/swc/tests/fixture/issues-9xxx/9129/1/input/.swcrc
Normal file
28
crates/swc/tests/fixture/issues-9xxx/9129/1/input/.swcrc
Normal 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"
|
||||
}
|
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/1.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/1.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export default function Foo() {
|
||||
}
|
||||
|
||||
Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/2.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/2.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export function Foo() {
|
||||
}
|
||||
|
||||
Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/3.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/3.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export default class Foo {
|
||||
}
|
||||
|
||||
new Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/4.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/1/input/4.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export class Foo {
|
||||
}
|
||||
|
||||
new Foo()
|
6
crates/swc/tests/fixture/issues-9xxx/9129/1/output/1.js
Normal file
6
crates/swc/tests/fixture/issues-9xxx/9129/1/output/1.js
Normal file
@ -0,0 +1,6 @@
|
||||
eval('');
|
||||
export default function Foo() {}
|
||||
_c = Foo;
|
||||
Foo();
|
||||
var _c;
|
||||
$RefreshReg$(_c, "Foo");
|
6
crates/swc/tests/fixture/issues-9xxx/9129/1/output/2.js
Normal file
6
crates/swc/tests/fixture/issues-9xxx/9129/1/output/2.js
Normal file
@ -0,0 +1,6 @@
|
||||
eval('');
|
||||
export function Foo() {}
|
||||
_c = Foo;
|
||||
Foo();
|
||||
var _c;
|
||||
$RefreshReg$(_c, "Foo");
|
4
crates/swc/tests/fixture/issues-9xxx/9129/1/output/3.js
Normal file
4
crates/swc/tests/fixture/issues-9xxx/9129/1/output/3.js
Normal file
@ -0,0 +1,4 @@
|
||||
eval('');
|
||||
export default class Foo {
|
||||
}
|
||||
new Foo();
|
4
crates/swc/tests/fixture/issues-9xxx/9129/1/output/4.js
Normal file
4
crates/swc/tests/fixture/issues-9xxx/9129/1/output/4.js
Normal file
@ -0,0 +1,4 @@
|
||||
eval('');
|
||||
export class Foo {
|
||||
}
|
||||
new Foo();
|
25
crates/swc/tests/fixture/issues-9xxx/9129/2/input/.swcrc
Normal file
25
crates/swc/tests/fixture/issues-9xxx/9129/2/input/.swcrc
Normal 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"
|
||||
}
|
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/1.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/1.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export default function Foo() {
|
||||
}
|
||||
|
||||
Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/2.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/2.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export function Foo() {
|
||||
}
|
||||
|
||||
Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/3.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/3.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export default class Foo {
|
||||
}
|
||||
|
||||
new Foo()
|
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/4.js
Normal file
5
crates/swc/tests/fixture/issues-9xxx/9129/2/input/4.js
Normal file
@ -0,0 +1,5 @@
|
||||
eval('')
|
||||
export class Foo {
|
||||
}
|
||||
|
||||
new Foo()
|
3
crates/swc/tests/fixture/issues-9xxx/9129/2/output/1.js
Normal file
3
crates/swc/tests/fixture/issues-9xxx/9129/2/output/1.js
Normal file
@ -0,0 +1,3 @@
|
||||
eval('');
|
||||
export default function Foo() {}
|
||||
Foo();
|
3
crates/swc/tests/fixture/issues-9xxx/9129/2/output/2.js
Normal file
3
crates/swc/tests/fixture/issues-9xxx/9129/2/output/2.js
Normal file
@ -0,0 +1,3 @@
|
||||
eval('');
|
||||
export function Foo() {}
|
||||
Foo();
|
4
crates/swc/tests/fixture/issues-9xxx/9129/2/output/3.js
Normal file
4
crates/swc/tests/fixture/issues-9xxx/9129/2/output/3.js
Normal file
@ -0,0 +1,4 @@
|
||||
eval('');
|
||||
export default class Foo {
|
||||
}
|
||||
new Foo();
|
4
crates/swc/tests/fixture/issues-9xxx/9129/2/output/4.js
Normal file
4
crates/swc/tests/fixture/issues-9xxx/9129/2/output/4.js
Normal file
@ -0,0 +1,4 @@
|
||||
eval('');
|
||||
export class Foo {
|
||||
}
|
||||
new Foo();
|
@ -1,6 +1,6 @@
|
||||
function x() {
|
||||
(class Baz {
|
||||
});
|
||||
let Foo = class Foo {
|
||||
};
|
||||
class Foo {
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
function foo() {
|
||||
let Bar = class Bar {
|
||||
};
|
||||
class Bar {
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
|
@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user