mirror of
https://github.com/swc-project/swc.git
synced 2024-11-26 09:54:22 +03:00
fix(es/decorators): Use correct class name reference (#9375)
- Closes #9350
This commit is contained in:
parent
a3a30403c1
commit
badd6a9ede
5
.changeset/flat-geese-care.md
Normal file
5
.changeset/flat-geese-care.md
Normal file
@ -0,0 +1,5 @@
|
||||
---
|
||||
swc_ecma_transforms_proposal: patch
|
||||
---
|
||||
|
||||
fix(es/decorator): Use correct class name reference
|
13
crates/swc/tests/fixture/issues-9xxx/9350/input/.swcrc
Normal file
13
crates/swc/tests/fixture/issues-9xxx/9350/input/.swcrc
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"jsc": {
|
||||
"parser": {
|
||||
"syntax": "typescript",
|
||||
"decorators": true
|
||||
},
|
||||
"target": "es2016"
|
||||
},
|
||||
"module": {
|
||||
"type": "es6"
|
||||
},
|
||||
"isModule": true
|
||||
}
|
18
crates/swc/tests/fixture/issues-9xxx/9350/input/index.ts
Normal file
18
crates/swc/tests/fixture/issues-9xxx/9350/input/index.ts
Normal file
@ -0,0 +1,18 @@
|
||||
function registerHook(key) {
|
||||
return (...args) => console.log(args);
|
||||
}
|
||||
|
||||
export default function design(base: typeof Component) {
|
||||
return class Design extends base {
|
||||
copy() {
|
||||
console.log("copy");
|
||||
}
|
||||
|
||||
@registerHook("beforeRender")
|
||||
@registerHook("afterRender")
|
||||
render() {
|
||||
super.render();
|
||||
console.log("design render");
|
||||
}
|
||||
};
|
||||
}
|
19
crates/swc/tests/fixture/issues-9xxx/9350/input/test.ts
Normal file
19
crates/swc/tests/fixture/issues-9xxx/9350/input/test.ts
Normal file
@ -0,0 +1,19 @@
|
||||
function registerHook(key) {
|
||||
return (...args) => console.log(args);
|
||||
}
|
||||
|
||||
export default function design(base: typeof Component) {
|
||||
const Design = "test name conflict";
|
||||
return class Design extends base {
|
||||
copy() {
|
||||
console.log("copy");
|
||||
}
|
||||
|
||||
@registerHook("beforeRender")
|
||||
@registerHook("afterRender")
|
||||
render() {
|
||||
super.render();
|
||||
console.log("design render");
|
||||
}
|
||||
};
|
||||
}
|
19
crates/swc/tests/fixture/issues-9xxx/9350/output/index.ts
Normal file
19
crates/swc/tests/fixture/issues-9xxx/9350/output/index.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
||||
function registerHook(key) {
|
||||
return (...args)=>console.log(args);
|
||||
}
|
||||
export default function design(base) {
|
||||
var Design;
|
||||
return Design = class Design extends base {
|
||||
copy() {
|
||||
console.log("copy");
|
||||
}
|
||||
render() {
|
||||
super.render();
|
||||
console.log("design render");
|
||||
}
|
||||
}, _ts_decorate([
|
||||
registerHook("beforeRender"),
|
||||
registerHook("afterRender")
|
||||
], Design.prototype, "render", null), Design;
|
||||
}
|
20
crates/swc/tests/fixture/issues-9xxx/9350/output/test.ts
Normal file
20
crates/swc/tests/fixture/issues-9xxx/9350/output/test.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { _ as _ts_decorate } from "@swc/helpers/_/_ts_decorate";
|
||||
function registerHook(key) {
|
||||
return (...args)=>console.log(args);
|
||||
}
|
||||
export default function design(base) {
|
||||
const Design = "test name conflict";
|
||||
var Design1;
|
||||
return Design1 = class Design1 extends base {
|
||||
copy() {
|
||||
console.log("copy");
|
||||
}
|
||||
render() {
|
||||
super.render();
|
||||
console.log("design render");
|
||||
}
|
||||
}, _ts_decorate([
|
||||
registerHook("beforeRender"),
|
||||
registerHook("afterRender")
|
||||
], Design1.prototype, "render", null), Design1;
|
||||
}
|
@ -332,14 +332,16 @@ impl VisitMut for TscDecorator {
|
||||
return;
|
||||
}
|
||||
|
||||
let var_name = private_ident!("_class");
|
||||
let ident = n.ident.get_or_insert_with(|| var_name.clone());
|
||||
let ident = n
|
||||
.ident
|
||||
.get_or_insert_with(|| private_ident!("_class"))
|
||||
.clone();
|
||||
|
||||
let old = mem::replace(&mut self.class_name, Some(ident.clone()));
|
||||
|
||||
n.visit_mut_children_with(self);
|
||||
|
||||
self.assign_class_expr_to = Some(var_name);
|
||||
self.assign_class_expr_to = Some(ident);
|
||||
|
||||
self.class_name = old;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user