mirror of
https://github.com/swc-project/swc.git
synced 2024-12-25 14:43:33 +03:00
fix(es/compat): Transform default-exported class decorators correctly (#8050)
**Description:** Process decorators on the class expression on `export default` declaration and ensure to execute tests for the feature. **Related issue:** - Closes #8049
This commit is contained in:
parent
c53a655154
commit
a751f1cfaf
@ -1446,6 +1446,13 @@ impl VisitMut for Decorator202203 {
|
||||
|
||||
s.visit_mut_children_with(self);
|
||||
}
|
||||
ModuleItem::ModuleDecl(ModuleDecl::ExportDefaultDecl(ExportDefaultDecl {
|
||||
span: _,
|
||||
decl: DefaultDecl::Class(c),
|
||||
})) => {
|
||||
self.handle_class_expr(&mut c.class, c.ident.as_ref());
|
||||
s.visit_mut_children_with(self);
|
||||
}
|
||||
_ => {
|
||||
s.visit_mut_children_with(self);
|
||||
}
|
||||
|
@ -43,6 +43,7 @@ fn exec_inner(input: PathBuf) {
|
||||
}
|
||||
|
||||
#[testing::fixture("tests/decorators/**/input.js")]
|
||||
#[testing::fixture("tests/decorators/**/input.mjs")]
|
||||
fn fixture(input: PathBuf) {
|
||||
fixture_inner(input)
|
||||
}
|
||||
@ -50,7 +51,10 @@ fn fixture(input: PathBuf) {
|
||||
fn fixture_inner(input: PathBuf) {
|
||||
let src = std::fs::read_to_string(&input).unwrap();
|
||||
|
||||
let output = input.with_file_name("output.js");
|
||||
let output = input.with_file_name(format!(
|
||||
"output.{}",
|
||||
input.extension().unwrap().to_string_lossy()
|
||||
));
|
||||
|
||||
test_fixture(
|
||||
syntax_default(),
|
||||
|
@ -1,12 +1,11 @@
|
||||
var _initClass, _dec;
|
||||
let _A;
|
||||
_dec = dec;
|
||||
class A {
|
||||
static {
|
||||
[_A, _initClass] = _applyDecs2203R(this, [], [_dec]).c;
|
||||
}
|
||||
static {
|
||||
_initClass();
|
||||
}
|
||||
var _initClass, _A;
|
||||
export default class A {
|
||||
static{
|
||||
({ c: [_A, _initClass] } = _apply_decs_2203_r(this, [], [
|
||||
dec
|
||||
]));
|
||||
}
|
||||
static{
|
||||
_initClass();
|
||||
}
|
||||
}
|
||||
export { _A as default };
|
||||
|
@ -1,12 +1,11 @@
|
||||
var _initClass, _dec;
|
||||
let _default2;
|
||||
_dec = dec;
|
||||
class _default {
|
||||
static {
|
||||
[_default2, _initClass] = _applyDecs2203R(this, [], [_dec]).c;
|
||||
}
|
||||
static {
|
||||
_initClass();
|
||||
}
|
||||
var _initClass, _class;
|
||||
export default class {
|
||||
static{
|
||||
({ c: [_class, _initClass] } = _apply_decs_2203_r(this, [], [
|
||||
dec
|
||||
]));
|
||||
}
|
||||
static{
|
||||
_initClass();
|
||||
}
|
||||
}
|
||||
export { _default2 as default };
|
||||
|
@ -1,8 +1,13 @@
|
||||
var _dec, _init_x;
|
||||
_dec = dec;
|
||||
var _init_x;
|
||||
export class A {
|
||||
static {
|
||||
[_init_x] = _applyDecs2203R(this, [[_dec, 0, "x"]], []).e;
|
||||
static{
|
||||
({ e: [_init_x] } = _apply_decs_2203_r(this, [
|
||||
[
|
||||
dec,
|
||||
0,
|
||||
"x"
|
||||
]
|
||||
], []));
|
||||
}
|
||||
x = _init_x(this);
|
||||
}
|
||||
|
@ -1,12 +1,13 @@
|
||||
var _initClass, _dec;
|
||||
var _initClass;
|
||||
let _A;
|
||||
_dec = dec;
|
||||
class A {
|
||||
static {
|
||||
[_A, _initClass] = _applyDecs2203R(this, [], [_dec]).c;
|
||||
}
|
||||
static {
|
||||
_initClass();
|
||||
}
|
||||
static {
|
||||
({ c: [_A, _initClass] } = _apply_decs_2203_r(this, [], [
|
||||
dec
|
||||
]));
|
||||
}
|
||||
static {
|
||||
_initClass();
|
||||
}
|
||||
}
|
||||
export { _A as A };
|
||||
|
Loading…
Reference in New Issue
Block a user