Repository: swc-project/swc (rust)

Issue:
`new.target` should be `undefined` in class field initializer
### Describe the bug

per [spec](https://github.com/tc39/proposal-class-static-block/pull/38)

### Input code

```typescript
class A {
    a = new.target
}
```


### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.124&code=H4sIAAAAAAAAA0vOSSwuVnBUqOZSAIJEBVuFvNRyvZLEovTUEq5aLgB3eimPHwAAAA%3D%3D&config=H4sIAAAAAAAAA0WOSwrDMAxE76K1t9142X0PIVwlOPUPjwI1JnevXdJmJTF6b1CnDY5sp8IVUueGlpTfZElcZLjqi5IZ2IgWDhBDUFbv7iG7F8hq3eUwpFxX0anhNviQM%2BRvRJ%2F80ma7y7FUAa4TpzX8yGMUxfzcZ9BJWxlzKjGnDXRcRafs8Tjp7xcfCPSbEc4AAAA%3D

### Expected behavior

Do as spec do 

### Actual behavior

return `this.constructor` because it's already transpiled by previous pass

### Version

1.2.123

### Additional context

_No response_

Pull request:
fix(es/transforms): `new.target` should return undefined from `class_prop`
<!-- Thanks for submitting a pull request! Please provide enough information so that others can review your pull request. -->

**Description:**

<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**
<!--
If this PR introduces a breaking change, it must contain a notice for it to be included in the CHANGELOG. Add description or remove entirely if not breaking.

You may need to update `MIGRATION.md` for the breaking changes.
-->

**Related issue (if exists):**
- fix #3143 

Patch:
diff --git a/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs b/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs
index 68f6ee20c9..e300ea114a 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs
@@ -20,6 +20,7 @@ struct NewTarget {
     in_constructor: bool,
     in_method: bool,
     in_arrow_expr: bool,
+    in_class_prop: bool,
 
     var: Option<VarDeclarator>,
 }
@@ -81,6 +82,16 @@ impl VisitMut for NewTarget {
         self.in_method = old;
     }
 
+    fn visit_mut_class_prop(&mut self, c: &mut ClassProp) {
+        let old = self.in_method;
+
+        self.in_class_prop = true;
+
+        c.visit_mut_children_with(self);
+
+        self.in_method = old;
+    }
+
     fn visit_mut_constructor(&mut self, c: &mut Constructor) {
         let old = self.in_constructor;
 
@@ -111,7 +122,7 @@ impl VisitMut for NewTarget {
             }) => {
                 if self.in_arrow_expr {
                     *e = Expr::Ident(self.var.as_ref().unwrap().name.clone().ident().unwrap().id);
-                } else if self.in_method {
+                } else if self.in_method || self.in_class_prop {
                     *e = *undefined(DUMMY_SP)
                 } else {
                     if let Some(cur) = self.cur.clone() {


Test patch:
diff --git a/crates/swc_ecma_transforms_compat/tests/fixture/new-target/exec/class-property/exec.js b/crates/swc_ecma_transforms_compat/tests/fixture/new-target/exec/class-property/exec.js
new file mode 100644
index 0000000000..aca6afd36a
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/fixture/new-target/exec/class-property/exec.js
@@ -0,0 +1,11 @@
+"use strict";
+
+class Foo {
+    bar = new.target;
+    ["baz"] = new.target;
+}
+
+const foo = new Foo();
+
+expect(foo.bar).toBe(undefined);
+expect(foo.baz).toBe(undefined);