Repository: swc-project/swc (language: rust)

Issue:
[Bug] 2022-03 decorator initialise class instance in wrong order
### Describe the bug

As per tc39/proposal-decorators [[Adding initialization logic with addInitializer](https://github.com/tc39/proposal-decorators?tab=readme-ov-file#adding-initialization-logic-with-addinitializer)]
Method and Getter/Setter decorators should be initialised before any class fields are initialised

### Input code

```typescript
const myDecorator = (value, context) => {
  context.addInitializer(() => {
    console.log("init")
  })
  return value
}

class A {
  value = this.getNumber();
  value2 = this.getNumber();
  
  @myDecorator
  getNumber() {
    console.log("getNumber")
    return 1
  }
}

const a = new A()
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "decorators": true,
      "tsx": true
    },
    "transform": {
      "decoratorVersion": "2022-03"
    },
    "target": "es2021",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.7.39&code=H4sIAAAAAAAAA3WQzwrCMAzG732KsFMLMtCrTBx48eI71C7MQtdCm%2FmXvbtdYGUHhRBIvi%2FJj5jgE8HwOqEJUVOI0IC8azfiBkzwhE9S0BzgI2Cpa911Z2%2FJamffGKUsBrak4LB2oZeVzaZK5f40p4g0Rg%2B8W0xCGKdTgpYHuZkv082muke6jMM1b1b7Rdv9EXMcV%2FC5XBl%2BMRWZwQrVdqZkKv6Hzuc8PqCV6gsyc1fOIQEAAA%3D%3D&config=H4sIAAAAAAAAA1VQQQ6DMAy78wqU8yYxJu2wP%2By6ewUBdaJNlRRpCPH3tVA6uCW2E1uei7KEjzTwLOcwhsUpFuS8B0Qm69U3IOAnh9Kwdh4uO9tiQ6w8sQSF5xEz4%2BWboBVZNgI8KysdsTl65C9vZNFko1td1fW1usP5WnGPPtIoQXBLQWAgEgxwpwZJEcBoq7vpaNOQcYwiZ2GUKtsP%2BX5zLJIrGGrHlUwVxRq2BA%2F4i3az%2FBi0vPbLtYXlByFGoz9uAQAA

### SWC Info output

_No response_

### Expected behavior
When I run output code, I should see console log
```
init
getNumber
getNumber
```

This is [tsc playground link](https://www.typescriptlang.org/play/?target=8#code/MYewdgzgLgBAtgTwCIFNQCcCGUTpgXhgAoA3TAGwFcUAaGUMKFADygEoCA+GAbwCgY9cE1YA6TABMJASTABLKHIpyAXinREiHfN36DBDCCHIpR5EAHMiAIjnyo1tgJgBfJ4PQooldGBhkqFD4XPj5gckwICBgAQV5nAOoCGCgACzkIUQsvADlKOAAjdS0AbgSKagAmZLSMrNz8oo02MsFnAAFEVAxsXGdsqDzC4o49fUNjU3MrawGhpsdnDy8fPwBGZxCQsPBoGExksBQAd1itIA), and if I run the output code, it's as expected
![image](https://github.com/user-attachments/assets/bec4c820-7983-48bc-a65c-8c8665801b27)


### Actual behavior
Wehn I run output code, I see console log
```
getNumber
getNumber
init
```
![image](https://github.com/user-attachments/assets/0116550e-9fa6-4a5b-9455-c1c9775e7a33)


### Version

1.7.39

### Additional context

_No response_


Discussion / hints:
### Investigating

The current implementation of the constructor is as follows:

```TypeScript
constructor() {
    _define_property(this, "value", this.getNumber());
    _define_property(this, "value2", this.getNumber());
    _initProto(this);
}
```

**Problem**: The order of operations is incorrect. The `_initProto` function should be called at the top of the constructor to ensure proper prototype initialization before any instance properties are assigned.

Our `inject_after_super` functionality is working as intended. However, the decorator pass executes first, leading to the following transformation:

```TypeScript
constructor() {
    _initProto(this);
}
value = this.getNumber();
value2 = this.getNumber();
```

And during the ES2022 pass, class fields are inserted into the constructor before the `_initProto` call, resulting in the undesired behavior.

### Possible Solution

Insert `initProto` in the class field instead.

```TypeScript
class A {
  #_ = _initProto(this);
  value = this.getNumber();
  value2 = this.getNumber();
}
```
have a solution
check if `this` is used in any filed initialisation, find the first one, for example `value = this.getNumber()`
if found: replace `this` with `_initProto(this)` (make sure _initProto returns `this`), so the code will become `value =(_initProto(this)).getNumber()`
if not found: use `inject_after_super`

then run es2022 pass as usual

I will try create a pr

Fix patch:
diff --git a/.changeset/tame-hairs-applaud.md b/.changeset/tame-hairs-applaud.md
new file mode 100644
index 000000000000..121f9897da2e
--- /dev/null
+++ b/.changeset/tame-hairs-applaud.md
@@ -0,0 +1,6 @@
+---
+swc_ecma_transforms_proposal: patch
+swc_core: patch
+---
+
+Fix 2022-03 decorators initialization order
diff --git a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
index 0b5221b1f4c6..eb3a6b0dceb4 100644
--- a/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
+++ b/crates/swc_ecma_transforms_proposal/src/decorator_impl.rs
@@ -51,7 +51,6 @@ struct ClassState {
     /// If not empty, `initProto` should be injected to the constructor.
     init_proto: Option<Ident>,
     init_proto_args: Vec<Option<ExprOrSpread>>,
-    is_init_proto_called: bool,
 
     init_static: Option<Ident>,
     init_static_args: Vec<Option<ExprOrSpread>>,
@@ -718,10 +717,10 @@ impl DecoratorPass {
             }
         }
         body.visit_mut_with(self);
-        c.visit_mut_with(self);
         c.ident = preserved_class_name.clone();
         replace_ident(&mut c.class, c.ident.to_id(), &preserved_class_name);
         c.class.body.extend(body);
+        c.visit_mut_with(self);
         c.class.body.push(ClassMember::StaticBlock(StaticBlock {
             span: DUMMY_SP,
             body: BlockStmt {
@@ -814,19 +813,48 @@ impl VisitMut for DecoratorPass {
 
         n.visit_mut_children_with(self);
 
-        if !self.state.is_init_proto_called {
-            if let Some(init_proto) = self.state.init_proto.clone() {
+        if let Some(init_proto) = self.state.init_proto.clone() {
+            let init_proto_expr = CallExpr {
+                span: DUMMY_SP,
+                callee: init_proto.clone().as_callee(),
+                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;
+                    }
+                }
+            }
+
+            if !proto_inited {
                 let c = self.ensure_constructor(n);
 
-                inject_after_super(
-                    c,
-                    vec![Box::new(Expr::Call(CallExpr {
-                        span: DUMMY_SP,
-                        callee: init_proto.as_callee(),
-                        args: vec![ThisExpr { span: DUMMY_SP }.as_arg()],
-                        ..Default::default()
-                    }))],
-                )
+                inject_after_super(c, vec![Box::new(init_proto_expr.into())])
             }
         }
 
@@ -847,7 +875,6 @@ impl VisitMut for DecoratorPass {
         }
 
         self.state.init_proto = None;
-        self.state.is_init_proto_called = false;
 
         self.state.extra_stmts = old_stmts;
     }
@@ -1045,29 +1072,6 @@ impl VisitMut for DecoratorPass {
                         value: if accessor.decorators.is_empty() {
                             accessor.value
                         } else {
-                            let init_proto =
-                                if self.state.is_init_proto_called || accessor.is_static {
-                                    None
-                                } else {
-                                    self.state.is_init_proto_called = true;
-
-                                    let init_proto = self
-                                        .state
-                                        .init_proto
-                                        .get_or_insert_with(|| private_ident!("_initProto"))
-                                        .clone();
-
-                                    Some(
-                                        CallExpr {
-                                            span: DUMMY_SP,
-                                            callee: init_proto.clone().as_callee(),
-                                            args: vec![ThisExpr { span: DUMMY_SP }.as_arg()],
-                                            ..Default::default()
-                                        }
-                                        .into(),
-                                    )
-                                };
-
                             let init_call = CallExpr {
                                 span: DUMMY_SP,
                                 callee: init.clone().as_callee(),
@@ -1078,9 +1082,7 @@ impl VisitMut for DecoratorPass {
                             }
                             .into();
 
-                            Some(Expr::from_exprs(
-                                init_proto.into_iter().chain(once(init_call)).collect(),
-                            ))
+                            Some(init_call)
                         },
                         type_ann: None,
                         is_static: accessor.is_static,


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js b/crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js
index 2aed3ac071de..316c10d336a8 100644
--- a/crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js
+++ b/crates/swc/tests/fixture/issues-7xxx/7220/1/output/index.js
@@ -14,8 +14,7 @@ var TestClass = /*#__PURE__*/ function() {
     "use strict";
     function TestClass() {
         _class_call_check(this, TestClass);
-        _define_property(this, "calls", []);
-        _initProto(this);
+        _define_property(this, "calls", (_initProto(this), []));
     }
     _create_class(TestClass, [
         {
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 97e1546d73e6..7c5f45ec7e36 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
@@ -2,7 +2,7 @@ var _init_a, _initProto;
 const dec = ()=>{};
 class Foo {
     static{
-        ({ e: [_init_a, _initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_init_a, _initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 2,
@@ -15,10 +15,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    a = _init_a(this, 123);
+    a = (_initProto(this), _init_a(this, 123));
     a() {
         return 1;
     }
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 676763b985bb..f3ceafa4db98 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,8 +10,7 @@ class Foo {
             get: get_a,
             set: void 0
         });
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 2e5140f683ef..784fba5644f8 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,8 +10,7 @@ class Foo {
         return this.value;
     }
     constructor(){
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 a4058bb38f0d..18a0d5dd0550 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,8 +13,7 @@ class Foo {
             get: get_a,
             set: set_a
         });
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 6087418acd63..b70764d6f90c 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,8 +16,7 @@ class Foo {
         this.value = v;
     }
     constructor(){
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 bf868142d4fe..b4b55534ad67 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,10 +21,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 e1f56c6c39b2..f36175396d1c 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
@@ -3,7 +3,7 @@ const dec = ()=>{};
 _computedKey = 'b', _computedKey1 = 'b';
 class Foo {
     static{
-        ({ e: [_initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 3,
@@ -26,10 +26,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 03c3c990fad6..d6c081b17186 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
@@ -2,7 +2,7 @@ var _call_a, _initProto;
 const dec = ()=>{};
 class Foo {
     static{
-        ({ e: [_call_a, _initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_call_a, _initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 3,
@@ -13,10 +13,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 6dc21675b736..6465c1017e7b 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
@@ -3,7 +3,7 @@ const dec = ()=>{};
 _computedKey = 'b';
 class Foo {
     static{
-        ({ e: [_initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 3,
@@ -16,10 +16,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 8015fce99f82..6d64f8737fea 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,8 +10,7 @@ class Foo {
             get: get_a,
             set: void 0
         });
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 ae9b5f0f3373..e71667b3a948 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,8 +10,7 @@ class Foo {
         return this.value;
     }
     constructor(){
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 6b13fc8df81a..e0ea231af691 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,10 +13,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 846e860e53e6..3de6c5a04a21 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
@@ -3,7 +3,7 @@ const dec = ()=>{};
 _computedKey = 'b';
 class Foo {
     static{
-        ({ e: [_initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 2,
@@ -16,10 +16,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 18826e02d768..db3dbf8a9f99 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,11 +144,11 @@ new class extends _identity {
                 ]));
                 _initStatic(this);
             }
-            a = _init_a(this);
+            a = (_initProto(this), _init_a(this));
             b() {}
             get c() {}
             set c(v) {}
-            #___private_d_1 = (_initProto(this), _init_d(this));
+            #___private_d_1 = _init_d(this);
             get d() {
                 return this.#___private_d_1;
             }
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 5a8ca1bb289f..a8fa7f9adad4 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,8 +10,7 @@ class Foo {
             get: void 0,
             set: set_a
         });
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 c5fdd8e6788c..3b6acbdb1f58 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,8 +10,7 @@ class Foo {
         return this.value = v;
     }
     constructor(){
-        _define_property(this, "value", 1);
-        _initProto(this);
+        _define_property(this, "value", (_initProto(this), 1));
     }
 }
 ({ 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 de3ab531e1ab..fb0608802bc7 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,10 +13,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 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 5c8fea71f6e0..c365616ec45b 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
@@ -3,7 +3,7 @@ const dec = ()=>{};
 _computedKey = 'b';
 class Foo {
     static{
-        ({ e: [_initProto]  } = _apply_decs_2203_r(this, [
+        ({ e: [_initProto] } = _apply_decs_2203_r(this, [
             [
                 dec,
                 4,
@@ -16,10 +16,7 @@ class Foo {
             ]
         ], []));
     }
-    constructor(){
-        _initProto(this);
-    }
-    value = 1;
+    value = (_initProto(this), 1);
     set a(v) {
         return this.value = v;
     }