Repository: swc-project/swc (rust)

Issue:
Class with readonly property named `accessor` results in incorrect code
### Describe the bug

When you have a readonly property named `accessor` in a class it is not correctly transpiled causing an error.

### Input code

```typescript
class SomeClass {
    readonly accessor: string;

    constructor() {
        this.accessor = '';
    }
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": true
    },
    "transform": {
      "legacyDecorator": true,
      "decoratorMetadata": true
    },
    "target": "es2020",
    "loose": false
  }
}
```


### Playground link (or link to the minimal reproduction)

https://play.swc.rs/?version=1.3.104&code=H4sIAAAAAAAAA0vOSSwuVgjOz011BrOquRSAoCg1MSU%2FL6dSITE5ObW4OL%2FISqG4pCgzL92aCyyfnJ8H5Jcml%2BQXaWhC9YBASUZmsR5Mj4Ktgrq6NViulqsWAO9kwxJpAAAA&config=H4sIAAAAAAAAA1VPQQ6DMAy78wqU8w6Iww77wx5RlYA6lbZKgrQK8fe1tHTbLbEdO967vocXa3j0exrTEhQxUtsTwtGJeicEJAZkTSYI3C5WOFNCGzZoQu1JiSeuzEkchQdRtKBkO%2BRxGIdqBdZ7xgTPynL1gtU4M8ffZ7RfAyHzvzBLlVtsuy%2BJXU2F1U%2FbSdaSuUj54A5f0RXWjMHw87o8exwfeZfRZDABAAA%3D

### SWC Info output

    Operating System:
        Platform: linux
        Arch: x64
        Machine Type: x86_64
        Version: #1 SMP Fri Jan 27 02:56:13 UTC 2023
        CPU: (16 cores)
            Models: AMD Ryzen 7 3700X 8-Core Processor

    Binaries:
        Node: 20.10.0
        npm: 10.2.3
        Yarn: N/A
        pnpm: N/A

    Relevant Packages:
        @swc/core: 1.3.104
        @swc/helpers: 0.5.3
        @swc/types: 0.1.5
        typescript: 5.3.2

    SWC Config:
        output: N/A
        .swcrc path: N/A

    Next.js info:
        output: N/A


### Expected behavior

The readonly property `accessor` should be correctly transpiled.

### Actual behavior

`Error: failed to handle: internal error: entered unreachable code: auto_accessor pass should remove this`

### Version

1.3.104

### Additional context

By playing around in the editor i noticed that when setting `transform.decoratorVersion` to `2022-03` it does actually transpile but it seems to create a getter and setter with the name `readonly`.

https://play.swc.rs/?version=1.3.104&code=H4sIAAAAAAAAA0vOSSwuVgjOz011BrOquRSAoCg1MSU%2FL6dSITE5ObW4OL%2FISqG4pCgzL92aCyyfnJ8H5Jcml%2BQXaWhC9YBASUZmsR5Mj4Ktgrq6NViulqsWAO9kwxJpAAAA&config=H4sIAAAAAAAAA1VQuw6DMAzc%2BQrkuZUQlTr0H7p2j4JBqchDtpGKEP%2FeBEJKt%2FjufL7cUtU1vFnDo17iMw5BESOVOSI8O1GfiIDMAVmTCQKXgxVOlNCEBepQe1LiiTOzEevOgygaUJIdctu0TbaC0XvGCPdq5OwF1jjTz%2Bcw2ttAyPwvTFLlhrHsny%2FGk6Qc957s2amkfCGx8S4linnaa3ODfb3KFmB9N23euaPUw%2F6BO%2FxER9aSCww%2Fj82thvULwwptKG8BAAA%3D

Pull request description:
fix(es/parser): Check for existence of modifiers while parsing `accessor` token
**Description:**


**Related issue:**

 - Closes #8526

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/class_and_fn.rs b/crates/swc_ecma_parser/src/parser/class_and_fn.rs
index e0edb1ebc3..9962b6ac77 100644
--- a/crates/swc_ecma_parser/src/parser/class_and_fn.rs
+++ b/crates/swc_ecma_parser/src/parser/class_and_fn.rs
@@ -669,7 +669,7 @@ impl<I: Tokens> Parser<I> {
         }
 
         let accessor_token = accessor_token.or_else(|| {
-            if self.syntax().auto_accessors() {
+            if self.syntax().auto_accessors() && readonly.is_none() {
                 let start = cur_pos!(self);
                 if eat!(self, "accessor") {
                     Some(span!(self, start))


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts b/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts
new file mode 100644
index 0000000000..30bd8c1728
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts
@@ -0,0 +1,7 @@
+class SomeClass {
+    readonly accessor: string;
+
+    constructor() {
+        this.accessor = '';
+    }
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts.json
new file mode 100644
index 0000000000..28285d1946
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-8526/input.ts.json
@@ -0,0 +1,167 @@
+{
+  "type": "Script",
+  "span": {
+    "start": 1,
+    "end": 106,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "ClassDeclaration",
+      "identifier": {
+        "type": "Identifier",
+        "span": {
+          "start": 7,
+          "end": 16,
+          "ctxt": 0
+        },
+        "value": "SomeClass",
+        "optional": false
+      },
+      "declare": false,
+      "span": {
+        "start": 1,
+        "end": 106,
+        "ctxt": 0
+      },
+      "decorators": [],
+      "body": [
+        {
+          "type": "ClassProperty",
+          "span": {
+            "start": 23,
+            "end": 49,
+            "ctxt": 0
+          },
+          "key": {
+            "type": "Identifier",
+            "span": {
+              "start": 32,
+              "end": 40,
+              "ctxt": 0
+            },
+            "value": "accessor",
+            "optional": false
+          },
+          "value": null,
+          "typeAnnotation": {
+            "type": "TsTypeAnnotation",
+            "span": {
+              "start": 40,
+              "end": 48,
+              "ctxt": 0
+            },
+            "typeAnnotation": {
+              "type": "TsKeywordType",
+              "span": {
+                "start": 42,
+                "end": 48,
+                "ctxt": 0
+              },
+              "kind": "string"
+            }
+          },
+          "isStatic": false,
+          "decorators": [],
+          "accessibility": null,
+          "isAbstract": false,
+          "isOptional": false,
+          "isOverride": false,
+          "readonly": true,
+          "declare": false,
+          "definite": false
+        },
+        {
+          "type": "Constructor",
+          "span": {
+            "start": 55,
+            "end": 104,
+            "ctxt": 0
+          },
+          "key": {
+            "type": "Identifier",
+            "span": {
+              "start": 55,
+              "end": 66,
+              "ctxt": 0
+            },
+            "value": "constructor",
+            "optional": false
+          },
+          "params": [],
+          "body": {
+            "type": "BlockStatement",
+            "span": {
+              "start": 69,
+              "end": 104,
+              "ctxt": 0
+            },
+            "stmts": [
+              {
+                "type": "ExpressionStatement",
+                "span": {
+                  "start": 79,
+                  "end": 98,
+                  "ctxt": 0
+                },
+                "expression": {
+                  "type": "AssignmentExpression",
+                  "span": {
+                    "start": 79,
+                    "end": 97,
+                    "ctxt": 0
+                  },
+                  "operator": "=",
+                  "left": {
+                    "type": "MemberExpression",
+                    "span": {
+                      "start": 79,
+                      "end": 92,
+                      "ctxt": 0
+                    },
+                    "object": {
+                      "type": "ThisExpression",
+                      "span": {
+                        "start": 79,
+                        "end": 83,
+                        "ctxt": 0
+                      }
+                    },
+                    "property": {
+                      "type": "Identifier",
+                      "span": {
+                        "start": 84,
+                        "end": 92,
+                        "ctxt": 0
+                      },
+                      "value": "accessor",
+                      "optional": false
+                    }
+                  },
+                  "right": {
+                    "type": "StringLiteral",
+                    "span": {
+                      "start": 95,
+                      "end": 97,
+                      "ctxt": 0
+                    },
+                    "value": "",
+                    "raw": "''"
+                  }
+                }
+              }
+            ]
+          },
+          "accessibility": null,
+          "isOptional": false
+        }
+      ],
+      "superClass": null,
+      "isAbstract": false,
+      "typeParams": null,
+      "superTypeParams": null,
+      "implements": []
+    }
+  ],
+  "interpreter": null
+}