Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 5 additions & 35 deletions crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -820,42 +820,9 @@ impl VisitMut for DecoratorPass {
args: vec![ThisExpr { span: DUMMY_SP }.as_arg()],
..Default::default()
};
let mut proto_inited = false;
for member in n.body.iter_mut() {
if let ClassMember::ClassProp(prop) = member {
if prop.is_static {
continue;
}
if let Some(value) = prop.value.clone() {
prop.value = Some(Expr::from_exprs(vec![
init_proto_expr.clone().into(),
value,
]));

proto_inited = true;
break;
}
} else if let ClassMember::PrivateProp(prop) = member {
if prop.is_static {
continue;
}
if let Some(value) = prop.value.clone() {
prop.value = Some(Expr::from_exprs(vec![
init_proto_expr.clone().into(),
value,
]));

proto_inited = true;
break;
}
}
}
let c = self.ensure_constructor(n);

if !proto_inited {
let c = self.ensure_constructor(n);

inject_after_super(c, vec![Box::new(init_proto_expr.into())])
}
inject_after_super(c, vec![Box::new(init_proto_expr.into())])
}

self.consume_inits();
Expand Down Expand Up @@ -1780,6 +1747,9 @@ impl VisitMut for DecoratorPass {
self.state.init_static_args.push(Some(initialize_init));
} else {
self.state.proto_lhs.push(init);
self.state
.init_proto
.get_or_insert_with(|| private_ident!("_initProto"));
self.state.init_proto_args.push(Some(initialize_init));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,13 @@ class Foo {
});
_class_private_field_init(this, ___a_1, {
writable: true,
value: (_initProto(this), _init_a(this))
value: _init_a(this)
});
_class_private_field_init(this, ___b_2, {
writable: true,
value: _init_b(this, 123)
});
_initProto(this);
}
}
({ e: [_init_a, _get___a, _set___a, _init_b, _get___b, _set___b, _initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Foo {
constructor(){
_class_private_field_init(this, ____private_a_1, {
writable: true,
value: (_initProto(this), _init_a(this))
value: _init_a(this)
});
_class_private_field_init(this, ____private_b_2, {
writable: true,
Expand All @@ -35,6 +35,7 @@ class Foo {
writable: true,
value: _init_computedKey(this, 456)
});
_initProto(this);
}
}
({ e: [_init_a, _init_b, _init_computedKey, _initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ class Foo {
]
], []));
}
#__a_1 = (_initProto(this), _init_a(this));
constructor(){
_initProto(this);
}
#__a_1 = _init_a(this);
get #a() {
return _get___a(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Foo {
]
], []));
}
#___private_a_1 = (_initProto(this), _init_a(this));
constructor(){
_initProto(this);
}
#___private_a_1 = _init_a(this);
get a() {
return this.#___private_a_1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ var _init_a, _initProto;
const dec = () => { };
class Foo {
constructor() {
defineProperty(this, "a", (_initProto(this), _init_a(this, 123)));
defineProperty(this, "a", _init_a(this, 123));
_initProto(this);
}
a() {
return 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ class Foo {
]
], []));
}
a = (_initProto(this), _init_a(this, 123));
constructor(){
_initProto(this);
}
a = _init_a(this, 123);
a() {
return 1;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var _init_a, _init_b;
var _init_a, _init_b, _initProto;
const dec = ()=>{};
var _a = /*#__PURE__*/ new WeakMap(), _b = /*#__PURE__*/ new WeakMap();
class Foo {
Expand All @@ -11,9 +11,10 @@ class Foo {
writable: true,
value: _init_b(this, 123)
});
_initProto(this);
}
}
({ e: [_init_a, _init_b] } = _apply_decs_2203_r(Foo, [
({ e: [_init_a, _init_b, _initProto] } = _apply_decs_2203_r(Foo, [
[
dec,
0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
var _init_a, _init_b;
var _init_a, _init_b, _initProto;
const dec = ()=>{};
class Foo {
static{
({ e: [_init_a, _init_b] } = _apply_decs_2203_r(this, [
({ e: [_init_a, _init_b, _initProto] } = _apply_decs_2203_r(this, [
[
dec,
0,
Expand All @@ -27,6 +27,9 @@ class Foo {
]
], []));
}
constructor(){
_initProto(this);
}
#a = _init_a(this);
#b = _init_b(this, 123);
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Foo {
get: get_a,
set: void 0
});
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Foo {
return this.value;
}
constructor(){
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Foo {
get: get_a,
set: set_a
});
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_call_a, _call_a1, _initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ class Foo {
this.value = v;
}
constructor(){
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
get #a() {
return _call_a(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
get a() {
return this.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
get #a() {
return _call_a(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
get a() {
return this.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Foo {
get: get_a,
set: void 0
});
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ class Foo {
return this.value;
}
constructor(){
_define_property(this, "value", (_initProto(this), 1));
_define_property(this, "value", 1);
_initProto(this);
}
}
({ e: [_initProto] } = _apply_decs_2203_r(Foo, [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
get #a() {
return _call_a;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ class Foo {
]
], []));
}
value = (_initProto(this), 1);
constructor(){
_initProto(this);
}
value = 1;
a() {
return this.value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,10 @@ new class extends _identity {
]));
_initStatic(this);
}
a = (_initProto(this), _init_a(this));
constructor(){
_initProto(this);
}
a = _init_a(this);
b() {}
get c() {}
set c(v) {}
Expand Down
Loading
Loading