Repository: swc-project/swc (Rust)

Issue:
Arrow Function Syntax is still Exist After Converting to ES5 Syntax
### Describe the bug

When I convert an arrow function syntax, it fails to convert, there is still an arrow function in the result code.
At the seventh line of the output code.

### Input code

```typescript
function f0() {
}
f0.prototype = {
    name: 'Nicholas',
    age: 29,
    job: 'Software Engineer',
    sayName() {
        v0[args](1, {
            v9: v7 => super.v3(v27),
            foo: a,
            done: 'a'
        });
    }
};
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "es6",
    "strict": false,
    "strictMode": false,
    "lazy": false,
    "noInterop": false
  },
  "minify": false
}
```


### Playground link

https://play.swc.rs/?version=1.2.158&code=H4sIAAAAAAAAA1WOwQ6CMAyG7zxFb0BCCOKBAMGbVy4ejYeKG2J0JduYIWbv7pzEyH9qv35pyyfR6YEE8CyK4RXYgGfpKEmTnkcGjUPgIvDBKgjbobvSHVWYeIq9g3n5bW50dsaBuH6iZLAX%2FSAYk4uqcG7dDn8DlpjsiLJXp2iT%2FFE%2FKSswBTQ7UNPIZGq2kcmLOFlJnKgCXLMLic%2BfGP6ojWtf28DWb7HJBRDtAAAA&config=H4sIAAAAAAAAA22QwU7DMAyG3yXnXbnsxgQTkyjvYKUuZErsyHZHy8S7z2VTwxAnx5%2Ft3398DkeNYXsOFURRlpfOZDCFbcBYQKOkamHjbY4GyIqb0M8EJcVDqSy20irpBIYd2gf3Kx1GipaYdokaxGmZfMIBxmx74fKn8gYFtULEu1qPkQWMRf9BOxxY8Hm6s2RcX%2FGE%2BfETUqPpx7f7hBv69k4BUlfwbTTm7ADkHW25gj749zOz4i%2BXhkKQXzBXXO24TOF%2BzLhc0ebqMUQuhemoLqEmKTYX17Tjvslm%2BJrXhPhAvoVrU0%2Fa3fSv5AIhCjW1vQEAAA%3D%3D

### Expected behavior

Arrow function syntax can be converted successfully in my code.

### Actual behavior

_No response_

### Version

1.2.158

### Additional context

_No response_


Discussion:
Seems like a regression?

The fix is incorrect: an arrow containing a super cannot be trivally transformed into a normal function, see [babel](https://babeljs.io/repl#?browsers=chrome%2045&build=&builtIns=false&corejs=3.6&spec=false&loose=false&code_lz=GYVwdgxgLglg9mABMADACgJSIN4CgC-uqAdAA4BOcUVAnqQKaIC8Oui7iYAhgLb0BciAOQA5GBAAWcADZcAzkIA0bDlwDmAxACYAnMo6IAVnABGgoQGU4wKAHcu5RgFEwamGHr1ySlezlcaEV56TFYDAwA3FABtBzU5AF00AEZFMPCMiJ1BCIB2ZgA-RDkQBnJiCIBmNAitXIx9DPDgODhBLkamjgATBE0hLiFfcPwMAG5hwnwxoA&debug=false&forceAllTransforms=false&shippedProposals=false&circleciRepo=&evaluate=false&fileSize=false&timeTravel=false&sourceType=module&lineWrap=true&presets=env&prettier=false&targets=&version=7.17.8&externalPlugins=&assumptions=%7B%22noClassCalls%22%3Atrue%7D)
Oh, I see. Thank you and reopening ...
I'll revert the wrong fix with https://github.com/swc-project/swc/pull/4093
This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.



Patch:
diff --git a/crates/swc_ecma_preset_env/src/lib.rs b/crates/swc_ecma_preset_env/src/lib.rs
index 1495e4e5481a..ebceac33015f 100644
--- a/crates/swc_ecma_preset_env/src/lib.rs
+++ b/crates/swc_ecma_preset_env/src/lib.rs
@@ -193,6 +193,7 @@ where
         es2015::spread(es2015::spread::Config { loose }),
         true
     );
+    let pass = add!(pass, ObjectSuper, es2015::object_super());
     let pass = add!(pass, FunctionName, es2015::function_name());
     let pass = add!(pass, ArrowFunctions, es2015::arrow());
     let pass = add!(pass, DuplicateKeys, es2015::duplicate_keys());
diff --git a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs
index 646f1b922755..e8589534bb45 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/object_super.rs
@@ -135,8 +135,17 @@ impl VisitMut for SuperReplacer {
     fn visit_mut_object_lit(&mut self, obj: &mut ObjectLit) {
         for prop_or_spread in obj.props.iter_mut() {
             if let PropOrSpread::Prop(prop) = prop_or_spread {
-                if let Prop::Method(MethodProp { key, function: _ }) = &mut **prop {
-                    key.visit_mut_with(self);
+                match &mut **prop {
+                    Prop::Method(MethodProp { key, .. })
+                    | Prop::Getter(GetterProp { key, .. })
+                    | Prop::Setter(SetterProp { key, .. }) => key.visit_mut_with(self),
+                    Prop::KeyValue(KeyValueProp { key, value }) => {
+                        key.visit_mut_with(self);
+                        if !(value.is_fn_expr() || value.is_class()) {
+                            value.visit_mut_with(self)
+                        }
+                    }
+                    Prop::Shorthand(_) | Prop::Assign(_) => (),
                 }
             }
         }


Test patch:
diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs
index 31fb28f1d421..0ca9be72e6d8 100644
--- a/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs
+++ b/crates/swc_ecma_transforms_compat/tests/es2015_object_super.rs
@@ -30,7 +30,7 @@ test!(
       
     const obj = {
         test: 2,
-      
+
         get() {
             return super.test;
         },
@@ -202,3 +202,41 @@ test!(
     };
     Object.setPrototypeOf(obj, Base);"#
 );
+
+test!(
+    syntax(),
+    |_| tr(),
+    nested_object,
+    r#"
+function f0() {
+}
+f0.prototype = {
+    name: 'Nicholas',
+    age: 29,
+    job: 'Software Engineer',
+    sayName() {
+        v0[args](1, {
+            v9: v7 => super.v3(v27),
+            foo: a,
+            done: 'a'
+        });
+    }
+};
+"#,
+    r#"
+var _obj;
+function f0() {}
+f0.prototype = _obj = {
+    name: "Nicholas",
+    age: 29,
+    job: "Software Engineer",
+    sayName: function sayName() {
+        v0[args](1, {
+            v9: (v7)=>_get(_getPrototypeOf(_obj), "v3", this).call(this, v27),
+            foo: a,
+            done: "a"
+        });
+    }
+};    
+"#
+);