Repository: swc-project/swc (rust)

Issue:
TypeError: Invalid property descriptor
### Describe the bug

The code run by node report an error as follows transpiled by swc
```shell
TypeError: Invalid property descriptor. Cannot both specify accessors and a value or writable attribute, #<Object>
```

### Input code

```typescript
class A {
    static b() {
    }
    static get b() {
    }
    static set b(b) {
    }
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "ecmascript",
      "jsx": false
    },
    "target": "es5",
    "loose": false,
    "minify": {
      "compress": false,
      "mangle": false
    }
  },
  "module": {
    "type": "commonjs"
  },
  "minify": false,
  "isModule": false
}
```


### Playground link

https://play.swc.rs/?version=1.2.204&code=H4sIAAAAAAAAA0vOSSwuVnBUqOZSAILiksSSzGSFJA1NqEAtsnB6agkuqWKwVBJCrhYAEcrfU1kAAAA%3D&config=H4sIAAAAAAAAA0WMSwrDMAxE76K1t93kDj2EcJXg4B8eB2KM716ZumQlMe%2FNdDphaeuUuUDK%2FNBi5Zs2EhsYtrhcyaim0c4eMgxVLofUqeClzKcEWdRQcNHtbS7ZFHIR4EEcD%2F83hw6F9Llm0Km2rHdWQoonaDxDq%2BzwXvav%2FgXU82csuwAAAA%3D%3D

### Expected behavior

Code can run without error by nodejs after transpiling.

### Actual behavior

_No response_

### Version

1.2.204

### Additional context

_No response_

Pull request description:
fix(es/compat): class has same name method and accessor
<!-- 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 #5029  

Patch:
diff --git a/crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs b/crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs
index eb95d12710..ecba3451f2 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/classes/mod.rs
@@ -965,9 +965,20 @@ where
                 method: None,
             });
             match m.kind {
-                MethodKind::Getter => data.get = Some(value),
-                MethodKind::Setter => data.set = Some(value),
-                MethodKind::Method => data.method = Some(value),
+                // https://github.com/swc-project/swc/issues/5029
+                MethodKind::Getter => {
+                    data.method = None;
+                    data.get = Some(value)
+                }
+                MethodKind::Setter => {
+                    data.method = None;
+                    data.set = Some(value)
+                }
+                MethodKind::Method => {
+                    data.get = None;
+                    data.set = None;
+                    data.method = Some(value)
+                }
             }
         }
 
diff --git a/crates/swc_ecma_transforms_compat/src/es2015/classes/prop_name.rs b/crates/swc_ecma_transforms_compat/src/es2015/classes/prop_name.rs
index 512f9653f0..af39090015 100644
--- a/crates/swc_ecma_transforms_compat/src/es2015/classes/prop_name.rs
+++ b/crates/swc_ecma_transforms_compat/src/es2015/classes/prop_name.rs
@@ -1,27 +1,23 @@
-use num_bigint::BigInt as BigIntValue;
-use ordered_float::OrderedFloat;
 use swc_atoms::JsWord;
 use swc_common::{Span, Spanned};
 use swc_ecma_ast::*;
 
 #[derive(Debug, PartialEq, Eq, Hash)]
 pub enum HashKey {
-    Ident(JsWord),
     Str(JsWord),
-    Num(OrderedFloat<f64>),
-    BigInt(BigIntValue),
     /// Not for key merging
     Computed(Span),
 }
 
 impl From<&PropName> for HashKey {
     fn from(p: &PropName) -> Self {
-        match *p {
-            PropName::Ident(Ident { ref sym, .. }) => HashKey::Ident(sym.clone()),
-            PropName::Str(Str { ref value, .. }) => HashKey::Str(value.clone()),
-            PropName::Num(Number { value, .. }) => HashKey::Num(value.into()),
-            PropName::BigInt(BigInt { ref value, .. }) => HashKey::BigInt(value.clone()),
-            PropName::Computed(ref expr) => HashKey::Computed(expr.span()),
+        match p {
+            PropName::Ident(Ident { sym: value, .. }) | PropName::Str(Str { value, .. }) => {
+                HashKey::Str(value.clone())
+            }
+            PropName::Num(Number { value, .. }) => HashKey::Str(value.to_string().into()),
+            PropName::BigInt(BigInt { value, .. }) => HashKey::Str(value.to_string().into()),
+            PropName::Computed(expr) => HashKey::Computed(expr.span()),
         }
     }
 }


Test patch:
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/input.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/input.js
new file mode 100644
index 0000000000..8dc244c8a8
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/input.js
@@ -0,0 +1,5 @@
+class A {
+    static b() {}
+    static get b() {}
+    static set b(b) {}
+}
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/output.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/output.js
new file mode 100644
index 0000000000..b25be8ea9e
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/1/output.js
@@ -0,0 +1,14 @@
+let A = /*#__PURE__*/ function() {
+    "use strict";
+    function A() {
+        _classCallCheck(this, A);
+    }
+    _createClass(A, null, [
+        {
+            key: "b",
+            get: function() {},
+            set: function(b) {}
+        }
+    ]);
+    return A;
+}();
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/input.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/input.js
new file mode 100644
index 0000000000..e8ac157dd4
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/input.js
@@ -0,0 +1,5 @@
+class A {
+    "b"() {}
+    get b() {}
+    set b(b) {}
+}
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/output.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/output.js
new file mode 100644
index 0000000000..158b7cf8a8
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/2/output.js
@@ -0,0 +1,14 @@
+let A = /*#__PURE__*/ function() {
+    "use strict";
+    function A() {
+        _classCallCheck(this, A);
+    }
+    _createClass(A, [
+        {
+            key: "b",
+            get: function() {},
+            set: function(b) {}
+        }
+    ]);
+    return A;
+}();
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/input.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/input.js
new file mode 100644
index 0000000000..39815b46a5
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/input.js
@@ -0,0 +1,5 @@
+class A {
+    get b() {}
+    set b(b) {}
+    b() {}
+}
diff --git a/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/output.js b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/output.js
new file mode 100644
index 0000000000..7ee85689b0
--- /dev/null
+++ b/crates/swc_ecma_transforms_compat/tests/classes/issue-5029/3/output.js
@@ -0,0 +1,13 @@
+let A = /*#__PURE__*/ function() {
+    "use strict";
+    function A() {
+        _classCallCheck(this, A);
+    }
+    _createClass(A, [
+        {
+            key: "b",
+            value: function b() {}
+        }
+    ]);
+    return A;
+}();
diff --git a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs
index e1b89db551..40e96af48c 100644
--- a/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs
+++ b/crates/swc_ecma_transforms_compat/tests/es2015_classes.rs
@@ -1902,9 +1902,6 @@ function Foo() {
   _createClass(Foo, [{
     key: "foo",
     value: function foo() {}
-  }, {
-    key: "foo",
-    value: function foo() {}
   }, {
     key: bar,
     value: function() {}
@@ -7231,10 +7228,6 @@ let Test = /*#__PURE__*/function (Foo) {
     return _super.apply(this, arguments);
   }
 
-  var _proto = Test.prototype;
-
-  _proto["foo"] = function foo() {};
-
   _createClass(Test, [
     {
       key: "foo",