diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs index 64235b4f0b32..8dc03de6ea73 100644 --- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs +++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs @@ -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(); @@ -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)); } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js index 21a4d803d1e4..67e9fda7ae25 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/private/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js index 715a41222e22..1cfbdda9167c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors--to-es2015/public/output.js @@ -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, @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js index 83f084173968..95fdef765565 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/private/output.js @@ -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); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js index 190af7b02435..92a30c909bc0 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-accessors/public/output.js @@ -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; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/.method-and-field/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/.method-and-field/output.js index 5641c211c805..02997df0793f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/.method-and-field/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys--to-es2015/.method-and-field/output.js @@ -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; diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys/method-and-field/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys/method-and-field/output.js index 7c5f45ec7e36..924e5d1fdf86 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys/method-and-field/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-duplicated-keys/method-and-field/output.js @@ -15,7 +15,10 @@ class Foo { ] ], [])); } - a = (_initProto(this), _init_a(this, 123)); + constructor(){ + _initProto(this); + } + a = _init_a(this, 123); a() { return 1; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js index 2f6115b272b6..445f7caf78f9 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields--to-es2015/private/output.js @@ -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 { @@ -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, diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields/private/output.js index 14a46595a464..f27d491d8c25 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-fields/private/output.js @@ -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, @@ -27,6 +27,9 @@ class Foo { ] ], [])); } + constructor(){ + _initProto(this); + } #a = _init_a(this); #b = _init_b(this, 123); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js index f3ceafa4db98..676763b985bb 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/private/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js index 784fba5644f8..2e5140f683ef 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters--to-es2015/public/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js index 18a0d5dd0550..a4058bb38f0d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/private/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js index b70764d6f90c..6087418acd63 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters--to-es2015/public/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/private/output.js index b4b55534ad67..bf868142d4fe 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/private/output.js @@ -21,7 +21,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; get #a() { return _call_a(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/public/output.js index f36175396d1c..353aff9a71e6 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters-and-setters/public/output.js @@ -26,7 +26,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; get a() { return this.value; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/private/output.js index d6c081b17186..ca71bcf4369a 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/private/output.js @@ -13,7 +13,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; get #a() { return _call_a(this); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/public/output.js index 6465c1017e7b..bf3cc308df66 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-getters/public/output.js @@ -16,7 +16,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; get a() { return this.value; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js index 6d64f8737fea..8015fce99f82 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/private/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js index e71667b3a948..ae9b5f0f3373 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods--to-es2015/public/output.js @@ -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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/private/output.js index e0ea231af691..6b13fc8df81a 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/private/output.js @@ -13,7 +13,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; get #a() { return _call_a; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/public/output.js index 3de6c5a04a21..36d3d0e6289b 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-methods/public/output.js @@ -16,7 +16,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; a() { return this.value; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js index db3dbf8a9f99..45b22d3f9013 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-misc/all-decorators/output.js @@ -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) {} diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-initializers-fields/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-initializers-fields/exec.js index a59b51cc2314..487f444a00fa 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-initializers-fields/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-initializers-fields/exec.js @@ -1,61 +1,64 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logFieldDecoratorRun(a, b) { - push(a); - return function (el) { push(b); return el; }; + push(a); + return function (el) { + push(b); + return el; + }; } @logClassDecoratorRun(0, 19, 21) @logClassDecoratorRun(1, 18, 20) class A { - @logAccessorDecoratorRun(2, 11, 23, 27) - @logAccessorDecoratorRun(3, 10, 22, 26) - accessor a; + @logAccessorDecoratorRun(2, 11, 23, 27) + @logAccessorDecoratorRun(3, 10, 22, 26) + accessor a; - @logFieldDecoratorRun(4, 15) - @logFieldDecoratorRun(5, 14) - b; + @logFieldDecoratorRun(4, 15) + @logFieldDecoratorRun(5, 14) + b; - @logFieldDecoratorRun(6, 17) - @logFieldDecoratorRun(7, 16) - #c; + @logFieldDecoratorRun(6, 17) + @logFieldDecoratorRun(7, 16) + #c; - @logAccessorDecoratorRun(8, 13, 25, 29) - @logAccessorDecoratorRun(9, 12, 24, 28) - accessor #d; + @logAccessorDecoratorRun(8, 13, 25, 29) + @logAccessorDecoratorRun(9, 12, 24, 28) + accessor #d; - constructor() { - this.a = this.#d = null; - } + constructor() { + this.a = this.#d = null; + } } var nums = Array.from({ length: 22 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-method-initializers/exec.js index a3efd8e40a6d..8221d337fd2f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-method-initializers/exec.js @@ -1,69 +1,69 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 21) @logClassDecoratorRun(1, 18, 20) class A { - @logAccessorDecoratorRun(2, 11, 23, 31) - @logAccessorDecoratorRun(3, 10, 22, 30) - accessor a; + @logAccessorDecoratorRun(2, 11, 23, 27) + @logAccessorDecoratorRun(3, 10, 22, 26) + accessor a; - @logMethodDecoratorRun(4, 13, 25, 35) - @logMethodDecoratorRun(5, 12, 24, 34) - b() {}; + @logMethodDecoratorRun(4, 13, 35, 29) + @logMethodDecoratorRun(5, 12, 34, 28) + b() {} - @logMethodDecoratorRun(6, 15, 27, 37) - @logMethodDecoratorRun(7, 14, 26, 36) - #c() {}; + @logMethodDecoratorRun(6, 15, 37, 31) + @logMethodDecoratorRun(7, 14, 36, 30) + #c() {} - @logAccessorDecoratorRun(8, 17, 29, 33) - @logAccessorDecoratorRun(9, 16, 28, 32) - accessor #d; + @logAccessorDecoratorRun(8, 17, 25, 33) + @logAccessorDecoratorRun(9, 16, 24, 32) + accessor #d; - constructor() { - this.b(); - this.#c(); - this.a = this.#d = null; - } + constructor() { + this.b(); + this.#c(); + this.a = this.#d = null; + } } var nums = Array.from({ length: 22 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-accessor-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-accessor-initializers/exec.js index 448854862950..b1eef7b0704d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-accessor-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-accessor-initializers/exec.js @@ -1,45 +1,52 @@ var log = []; -function push(x) { log.push(x); return x; } +function push(x) { + log.push(x); + return x; +} function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { push(c); }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { push(c); }); - return { - init: () => push(d) + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - @logAccessorDecoratorRun(2, 15, 31, 35) - @logAccessorDecoratorRun(3, 14, 30, 34) - accessor a; + @logAccessorDecoratorRun(2, 15, 31, 35) + @logAccessorDecoratorRun(3, 14, 30, 34) + accessor a; - @logAccessorDecoratorRun(4, 11, 21, 25) - @logAccessorDecoratorRun(5, 10, 20, 24) - static accessor b; + @logAccessorDecoratorRun(4, 11, 25, 21) + @logAccessorDecoratorRun(5, 10, 24, 20) + static accessor b; - @logAccessorDecoratorRun(6, 13, 23, 27) - @logAccessorDecoratorRun(7, 12, 22, 26) - static accessor #c; + @logAccessorDecoratorRun(6, 13, 27, 23) + @logAccessorDecoratorRun(7, 12, 26, 22) + static accessor #c; - @logAccessorDecoratorRun(8, 17, 33, 37) - @logAccessorDecoratorRun(9, 16, 32, 36) - accessor #d; + @logAccessorDecoratorRun(8, 17, 33, 37) + @logAccessorDecoratorRun(9, 16, 32, 36) + accessor #d; } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-method-initializers/exec.js index d940e8c8f379..23601efaf8df 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/accessor-static-method-initializers/exec.js @@ -1,71 +1,71 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - static { - A.b(), A.#c(); - } + static { + A.b(), A.#c(); + } - @logAccessorDecoratorRun(2, 15, 31, 35) - @logAccessorDecoratorRun(3, 14, 30, 34) - accessor a; + @logAccessorDecoratorRun(2, 15, 31, 35) + @logAccessorDecoratorRun(3, 14, 30, 34) + accessor a; - @logMethodDecoratorRun(4, 11, 21, 25) - @logMethodDecoratorRun(5, 10, 20, 24) - static b() {}; + @logMethodDecoratorRun(4, 11, 25, 21) + @logMethodDecoratorRun(5, 10, 24, 20) + static b() {} - @logMethodDecoratorRun(6, 13, 23, 27) - @logMethodDecoratorRun(7, 12, 22, 26) - static #c() {}; + @logMethodDecoratorRun(6, 13, 27, 23) + @logMethodDecoratorRun(7, 12, 26, 22) + static #c() {} - @logAccessorDecoratorRun(8, 17, 33, 37) - @logAccessorDecoratorRun(9, 16, 32, 36) - accessor #d; + @logAccessorDecoratorRun(8, 17, 33, 37) + @logAccessorDecoratorRun(9, 16, 32, 36) + accessor #d; - constructor() { - this.a = this.#d = null; - } + constructor() { + this.a = this.#d = null; + } } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/static-accessor-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/static-accessor-method-initializers/exec.js index e1ec45be3190..4b876907ea7c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/static-accessor-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering--to-es2015/static-accessor-method-initializers/exec.js @@ -1,68 +1,68 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - @logMethodDecoratorRun(2, 15, 31, 35) - @logMethodDecoratorRun(3, 14, 30, 34) - a() {} + @logMethodDecoratorRun(2, 15, 35, 31) + @logMethodDecoratorRun(3, 14, 34, 30) + a() {} - @logAccessorDecoratorRun(4, 11, 21, 25) - @logAccessorDecoratorRun(5, 10, 20, 24) - static accessor b; + @logAccessorDecoratorRun(4, 11, 25, 21) + @logAccessorDecoratorRun(5, 10, 24, 20) + static accessor b; - @logAccessorDecoratorRun(6, 13, 23, 27) - @logAccessorDecoratorRun(7, 12, 22, 26) - static accessor #c; + @logAccessorDecoratorRun(6, 13, 27, 23) + @logAccessorDecoratorRun(7, 12, 26, 22) + static accessor #c; - @logMethodDecoratorRun(8, 17, 33, 37) - @logMethodDecoratorRun(9, 16, 32, 36) - #d() {} + @logMethodDecoratorRun(8, 17, 37, 33) + @logMethodDecoratorRun(9, 16, 36, 32) + #d() {} - constructor() { - this.a(); - this.#d(); - } + constructor() { + this.a(); + this.#d(); + } } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-initializers-fields/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-initializers-fields/exec.js index a59b51cc2314..487f444a00fa 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-initializers-fields/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-initializers-fields/exec.js @@ -1,61 +1,64 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logFieldDecoratorRun(a, b) { - push(a); - return function (el) { push(b); return el; }; + push(a); + return function (el) { + push(b); + return el; + }; } @logClassDecoratorRun(0, 19, 21) @logClassDecoratorRun(1, 18, 20) class A { - @logAccessorDecoratorRun(2, 11, 23, 27) - @logAccessorDecoratorRun(3, 10, 22, 26) - accessor a; + @logAccessorDecoratorRun(2, 11, 23, 27) + @logAccessorDecoratorRun(3, 10, 22, 26) + accessor a; - @logFieldDecoratorRun(4, 15) - @logFieldDecoratorRun(5, 14) - b; + @logFieldDecoratorRun(4, 15) + @logFieldDecoratorRun(5, 14) + b; - @logFieldDecoratorRun(6, 17) - @logFieldDecoratorRun(7, 16) - #c; + @logFieldDecoratorRun(6, 17) + @logFieldDecoratorRun(7, 16) + #c; - @logAccessorDecoratorRun(8, 13, 25, 29) - @logAccessorDecoratorRun(9, 12, 24, 28) - accessor #d; + @logAccessorDecoratorRun(8, 13, 25, 29) + @logAccessorDecoratorRun(9, 12, 24, 28) + accessor #d; - constructor() { - this.a = this.#d = null; - } + constructor() { + this.a = this.#d = null; + } } var nums = Array.from({ length: 22 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-method-initializers/exec.js index a3efd8e40a6d..8221d337fd2f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-method-initializers/exec.js @@ -1,69 +1,69 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 21) @logClassDecoratorRun(1, 18, 20) class A { - @logAccessorDecoratorRun(2, 11, 23, 31) - @logAccessorDecoratorRun(3, 10, 22, 30) - accessor a; + @logAccessorDecoratorRun(2, 11, 23, 27) + @logAccessorDecoratorRun(3, 10, 22, 26) + accessor a; - @logMethodDecoratorRun(4, 13, 25, 35) - @logMethodDecoratorRun(5, 12, 24, 34) - b() {}; + @logMethodDecoratorRun(4, 13, 35, 29) + @logMethodDecoratorRun(5, 12, 34, 28) + b() {} - @logMethodDecoratorRun(6, 15, 27, 37) - @logMethodDecoratorRun(7, 14, 26, 36) - #c() {}; + @logMethodDecoratorRun(6, 15, 37, 31) + @logMethodDecoratorRun(7, 14, 36, 30) + #c() {} - @logAccessorDecoratorRun(8, 17, 29, 33) - @logAccessorDecoratorRun(9, 16, 28, 32) - accessor #d; + @logAccessorDecoratorRun(8, 17, 25, 33) + @logAccessorDecoratorRun(9, 16, 24, 32) + accessor #d; - constructor() { - this.b(); - this.#c(); - this.a = this.#d = null; - } + constructor() { + this.b(); + this.#c(); + this.a = this.#d = null; + } } var nums = Array.from({ length: 22 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-accessor-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-accessor-initializers/exec.js index 448854862950..b1eef7b0704d 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-accessor-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-accessor-initializers/exec.js @@ -1,45 +1,52 @@ var log = []; -function push(x) { log.push(x); return x; } +function push(x) { + log.push(x); + return x; +} function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { push(c); }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { push(c); }); - return { - init: () => push(d) + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - @logAccessorDecoratorRun(2, 15, 31, 35) - @logAccessorDecoratorRun(3, 14, 30, 34) - accessor a; + @logAccessorDecoratorRun(2, 15, 31, 35) + @logAccessorDecoratorRun(3, 14, 30, 34) + accessor a; - @logAccessorDecoratorRun(4, 11, 21, 25) - @logAccessorDecoratorRun(5, 10, 20, 24) - static accessor b; + @logAccessorDecoratorRun(4, 11, 25, 21) + @logAccessorDecoratorRun(5, 10, 24, 20) + static accessor b; - @logAccessorDecoratorRun(6, 13, 23, 27) - @logAccessorDecoratorRun(7, 12, 22, 26) - static accessor #c; + @logAccessorDecoratorRun(6, 13, 27, 23) + @logAccessorDecoratorRun(7, 12, 26, 22) + static accessor #c; - @logAccessorDecoratorRun(8, 17, 33, 37) - @logAccessorDecoratorRun(9, 16, 32, 36) - accessor #d; + @logAccessorDecoratorRun(8, 17, 33, 37) + @logAccessorDecoratorRun(9, 16, 32, 36) + accessor #d; } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/exec.js index d940e8c8f379..23601efaf8df 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/exec.js @@ -1,71 +1,71 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - static { - A.b(), A.#c(); - } + static { + A.b(), A.#c(); + } - @logAccessorDecoratorRun(2, 15, 31, 35) - @logAccessorDecoratorRun(3, 14, 30, 34) - accessor a; + @logAccessorDecoratorRun(2, 15, 31, 35) + @logAccessorDecoratorRun(3, 14, 30, 34) + accessor a; - @logMethodDecoratorRun(4, 11, 21, 25) - @logMethodDecoratorRun(5, 10, 20, 24) - static b() {}; + @logMethodDecoratorRun(4, 11, 25, 21) + @logMethodDecoratorRun(5, 10, 24, 20) + static b() {} - @logMethodDecoratorRun(6, 13, 23, 27) - @logMethodDecoratorRun(7, 12, 22, 26) - static #c() {}; + @logMethodDecoratorRun(6, 13, 27, 23) + @logMethodDecoratorRun(7, 12, 26, 22) + static #c() {} - @logAccessorDecoratorRun(8, 17, 33, 37) - @logAccessorDecoratorRun(9, 16, 32, 36) - accessor #d; + @logAccessorDecoratorRun(8, 17, 33, 37) + @logAccessorDecoratorRun(9, 16, 32, 36) + accessor #d; - constructor() { - this.a = this.#d = null; - } + constructor() { + this.a = this.#d = null; + } } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js index 82568d548199..553b7e43c700 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/accessor-static-method-initializers/output.js @@ -56,7 +56,7 @@ new class extends _identity { ])); _initStatic(this); } - #___private_a_1 = (_initProto(this), _init_a(this)); + #___private_a_1 = _init_a(this); get a() { return this.#___private_a_1; } @@ -72,6 +72,7 @@ new class extends _identity { _set___d(this, _v); } constructor(){ + _initProto(this); this.a = this.#d = null; } } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js index 239618fc796d..ba79e4b15a71 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/initializers/output.js @@ -93,12 +93,15 @@ new class extends _identity { ])); _initStatic(this); } + constructor(){ + _initProto(this); + } a() {} static b() {} get #d() { return _call_d; } - #___private_e_1 = (_initProto(this), _init_e(this)); + #___private_e_1 = _init_e(this); get e() { return this.#___private_e_1; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/static-accessor-method-initializers/exec.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/static-accessor-method-initializers/exec.js index e1ec45be3190..4b876907ea7c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/static-accessor-method-initializers/exec.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-ordering/static-accessor-method-initializers/exec.js @@ -1,68 +1,68 @@ var log = []; function push(x) { - log.push(x); - return x; + log.push(x); + return x; } function logClassDecoratorRun(a, b, c) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return el; - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(c); + }); + return el; + }; } function logAccessorDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return { - init: () => push(d), + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return { + init: () => push(c), + }; }; - }; } function logMethodDecoratorRun(a, b, c, d) { - push(a); - return function (el, { addInitializer }) { - push(b); - addInitializer(function () { - push(c); - }); - return () => (el(), push(d)) - }; + push(a); + return function (el, { addInitializer }) { + push(b); + addInitializer(function () { + push(d); + }); + return () => (el(), push(c)); + }; } @logClassDecoratorRun(0, 19, 29) @logClassDecoratorRun(1, 18, 28) class A { - @logMethodDecoratorRun(2, 15, 31, 35) - @logMethodDecoratorRun(3, 14, 30, 34) - a() {} + @logMethodDecoratorRun(2, 15, 35, 31) + @logMethodDecoratorRun(3, 14, 34, 30) + a() {} - @logAccessorDecoratorRun(4, 11, 21, 25) - @logAccessorDecoratorRun(5, 10, 20, 24) - static accessor b; + @logAccessorDecoratorRun(4, 11, 25, 21) + @logAccessorDecoratorRun(5, 10, 24, 20) + static accessor b; - @logAccessorDecoratorRun(6, 13, 23, 27) - @logAccessorDecoratorRun(7, 12, 22, 26) - static accessor #c; + @logAccessorDecoratorRun(6, 13, 27, 23) + @logAccessorDecoratorRun(7, 12, 26, 22) + static accessor #c; - @logMethodDecoratorRun(8, 17, 33, 37) - @logMethodDecoratorRun(9, 16, 32, 36) - #d() {} + @logMethodDecoratorRun(8, 17, 37, 33) + @logMethodDecoratorRun(9, 16, 36, 32) + #d() {} - constructor() { - this.a(); - this.#d(); - } + constructor() { + this.a(); + this.#d(); + } } var nums = Array.from({ length: 30 }, (_, i) => i); diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js index a8fa7f9adad4..5a8ca1bb289f 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/private/output.js @@ -10,7 +10,8 @@ class Foo { get: void 0, set: set_a }); - _define_property(this, "value", (_initProto(this), 1)); + _define_property(this, "value", 1); + _initProto(this); } } ({ e: [_call_a, _initProto] } = _apply_decs_2203_r(Foo, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js index 3b6acbdb1f58..c5fdd8e6788c 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters--to-es2015/public/output.js @@ -10,7 +10,8 @@ class Foo { return 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, [ diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/private/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/private/output.js index fb0608802bc7..de3ab531e1ab 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/private/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/private/output.js @@ -13,7 +13,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; set #a(v) { return _call_a(this, v); } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/public/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/public/output.js index c365616ec45b..9c10125016d5 100644 --- a/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/public/output.js +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/2022-03-setters/public/output.js @@ -16,7 +16,10 @@ class Foo { ] ], [])); } - value = (_initProto(this), 1); + constructor(){ + _initProto(this); + } + value = 1; set a(v) { return this.value = v; } diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/input.js b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/input.js new file mode 100644 index 000000000000..abc6e69de66c --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/input.js @@ -0,0 +1,10 @@ +function effect(getDep) { + return function (_, context) {}; +} + +class A { + @effect(() => [1, 2]) + #effect = () => { + console.log(123); + }; +} diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/output.js b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/output.js new file mode 100644 index 000000000000..11d2c861e56e --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/1/output.js @@ -0,0 +1,31 @@ +var _dec, _init_effect, _initProto; +function effect(getDep) { + return function(_, context) {}; +} +_dec = effect(()=>[ + 1, + 2 + ]); +class A { + static{ + ({ e: [_init_effect, _initProto] } = _apply_decs_2203_r(this, [ + [ + _dec, + 0, + "effect", + function() { + return this.#effect; + }, + function(value) { + this.#effect = value; + } + ] + ], [])); + } + constructor(){ + _initProto(this); + } + #effect = _init_effect(this, ()=>{ + console.log(123); + }); +} \ No newline at end of file diff --git a/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/options.json b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/options.json new file mode 100644 index 000000000000..4ad37b6e477c --- /dev/null +++ b/crates/swc_ecma_transforms_proposal/tests/decorators/issue-9565/options.json @@ -0,0 +1,3 @@ +{ + "plugins": [["proposal-decorators", { "version": "2022-03" }]] +} diff --git a/crates/swc_ecma_transforms_testing/src/lib.rs b/crates/swc_ecma_transforms_testing/src/lib.rs index 2fe92d21d663..98967191ed12 100644 --- a/crates/swc_ecma_transforms_testing/src/lib.rs +++ b/crates/swc_ecma_transforms_testing/src/lib.rs @@ -672,8 +672,8 @@ fn exec_with_node_test_runner(src: &str) -> Result<(), ()> { let test_runner_path = find_executable("mocha").expect("failed to find `mocha` from path"); let mut base_cmd = if cfg!(target_os = "windows") { - let mut c = Command::new("cmd"); - c.arg("/C").arg(&test_runner_path); + let mut c = Command::new("node"); + c.arg(&test_runner_path); c } else { Command::new(&test_runner_path) diff --git a/crates/testing/src/lib.rs b/crates/testing/src/lib.rs index db41e1dcc5be..e66abd373205 100644 --- a/crates/testing/src/lib.rs +++ b/crates/testing/src/lib.rs @@ -77,7 +77,14 @@ pub fn find_executable(name: &str) -> Option { if path.is_none() { // Run yarn bin $name - path = Command::new("yarn") + let mut base_cmd = if cfg!(target_os = "windows") { + let mut c = Command::new("cmd"); + c.args(["/C", "yarn"]); + c + } else { + Command::new("yarn") + }; + path = base_cmd .arg("bin") .arg(name) .output()