Repository: swc-project/swc (rust)

Issue:
`new.target` in object literals are not transpiled
### Describe the bug

'new.target' is only available in ES6. SWC does not convert the syntax.

### Input code

```typescript
const v0 = Symbol("Context#bar");
module.exports = {
    get bar() {
        if (new.target === "foo") {
            return;
        }
        return new Proxy(this, v0);
    }
};
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false,
      "dynamicImport": false,
      "privateMethod": false,
      "functionBind": false,
      "exportDefaultFrom": false,
      "exportNamespaceFrom": false,
      "decorators": false,
      "decoratorsBeforeExport": false,
      "topLevelAwait": false,
      "importMeta": false
    },
    "transform": null,
    "target": "es5",
    "loose": false,
    "externalHelpers": false
  },
  "module": {
    "type": "commonjs",
    "strict": false,
    "strictMode": false,
    "lazy": false,
    "noInterop": false
  }
}
```


### Playground link

https://play.swc.rs/?version=1.2.161&code=H4sIAAAAAAAAA1WOQQrCMBBF9znFEDcJSHEfsvICgido7VQLbUYmU02R3L0Jiujb%2FfmPz1woRIHHATyc17mjyegjBcEku65lbZ2aqV8mbDDdiSUW76WgcEWBYhj7yZVxABPw2UjLtfbegx6I9K9TYZSFg%2FvesvpvoIzAiSmtRm5j3Jf%2F7NvOKju1AfVjwuC0AAAA&config=H4sIAAAAAAAAA0WNwQ6DQAhE%2F4Wz1178gvbgR5AtNmtY2AAmWuO%2Fd01tPcFMZt5sMHmCfoOK5mTH56sELtADpYKeLNeArsWaNSI77R2EofioVqCXmbkZaC%2BKo%2BO3FmZVpzPeAS1BJsh34krmF6boc2Y6NmOt7ULSUlQmbwgPyyn%2BjK8c9HlhGd%2FrX4g%2BpK1ovejZh5N%2FZkqWPP4q%2Bwfiymdk%2BgAAAA%3D%3D

### Expected behavior

```js
var v0 = Symbol("Context#bar");
module.exports = {
  get bar() {
    if (void 0 === "foo") {
      return;
    }

    return new Proxy(this, v0);
  }

};
```

### Actual behavior

_No response_

### Version

1.2.161

### Additional context

_No response_

Pull request description:
fix(es/compat): handle `new.target` in getter/setter prop
<!-- Note: CI script will automatically rebase your PR so please do not rebase unless required -->

<!-- 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):**
closes #4193 

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 2c8b188787..9ddf821190 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/new_target.rs
@@ -26,6 +26,18 @@ struct NewTarget {
     var: Option<VarDeclarator>,
 }
 
+impl NewTarget {
+    fn visit_mut_method<T: VisitMutWith<Self>>(&mut self, c: &mut T) {
+        let old = self.in_method;
+
+        self.in_method = true;
+
+        c.visit_mut_with(self);
+
+        self.in_method = old;
+    }
+}
+
 #[swc_trace]
 impl VisitMut for NewTarget {
     noop_visit_mut_type!();
@@ -75,13 +87,9 @@ impl VisitMut for NewTarget {
     }
 
     fn visit_mut_class_method(&mut self, c: &mut ClassMethod) {
-        let old = self.in_method;
+        c.key.visit_mut_with(self);
 
-        self.in_method = true;
-
-        c.visit_mut_children_with(self);
-
-        self.in_method = old;
+        self.visit_mut_method(&mut c.function)
     }
 
     fn visit_mut_constructor(&mut self, c: &mut Constructor) {
@@ -168,13 +176,18 @@ impl VisitMut for NewTarget {
     }
 
     fn visit_mut_method_prop(&mut self, m: &mut MethodProp) {
-        let old = self.in_method;
-
-        self.in_method = true;
+        m.key.visit_mut_with(self);
+        self.visit_mut_method(&mut m.function)
+    }
 
-        m.visit_mut_children_with(self);
+    fn visit_mut_getter_prop(&mut self, m: &mut GetterProp) {
+        m.key.visit_mut_with(self);
+        self.visit_mut_method(&mut m.body)
+    }
 
-        self.in_method = old;
+    fn visit_mut_setter_prop(&mut self, m: &mut SetterProp) {
+        m.key.visit_mut_with(self);
+        self.visit_mut_method(&mut m.body)
     }
 
     fn visit_mut_module_items(&mut self, stmts: &mut Vec<ModuleItem>) {


Test patch:
diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs
index ae96b0d256..c551b5ef24 100644
--- a/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs
+++ b/crates/swc_ecma_transforms_compat/tests/es2015_new_target.rs
@@ -110,3 +110,27 @@ test!(
         const a = () => _newtarget
     }"#
 );
+
+test!(
+    ::swc_ecma_parser::Syntax::default(),
+    |_| new_target(),
+    issue_4193,
+    r#"const v0 = Symbol("Context#bar");
+    module.exports = {
+        get bar() {
+            if (new.target === "foo") {
+                return;
+            }
+            return new Proxy(this, v0);
+        }
+    };"#,
+    r#"const v0 = Symbol("Context#bar");
+    module.exports = {
+        get bar() {
+            if (void 0 === "foo") {
+                return;
+            }
+            return new Proxy(this, v0);
+        }
+    };"#
+);