Repository: swc-project/swc (rust)

Issue:
Parser error for callback signature with "package" as parameter name
### Describe the bug

This code appears in a d.ts file on DefinitelyTyped, but fails to parse.

### Input code

```typescript
export interface PackageManager {
    onDidUnloadPackage(callback: (package: Package) => void): Disposable;
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "transform": {
      "useDefineForClassFields": true,
      "react": {
        "importSource": "https://esm.sh/preact",
        "runtime": "automatic"
      }
    },
    "loose": false
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.44&code=H4sIAAAAAAAAA0utKMgvKlHIzCtJLUpLTE5VCEhMzk5MT%2FVNzAOSRQrVvFwKQJCf55KZEpqXk5%2BYAlWgkZyYk5MEZFspaBRAhKxgmjUVbO0UyvIzUzStFFwyiwvyixOTclKteblqebkAVmHrhHEAAAA%3D&config=H4sIAAAAAAAAA1WQvW7DMAyE9z6FoTmoCw8ZsrbIlilPQCh0w0J%2FICkgRuB3jyTHcbqJ3%2FF04N0%2Fus78iTWH7l6eZUjAgvyaC5EpKNwKMTolFMuU1OxWVaVKyhkbmRfBKPAvajWhDF%2FDYFbOEGSM7N8TsuAPjhTwGPnbgciR0F3k%2Be8rihGsvvkKIp8i6zlmtljDrqpJDn2P4j%2Fl2qfFstsMnIOSb7uQNXpQsuYpz%2F8ucDFK3RvBSb2tcePjJTvc6qqVLFfuzbZEgcZp9TZEclqdrav5AeQIxLB6AQAA

### Expected behavior

Parses.

### Actual behavior

Fails to parse!

### Version

1.3.44

### Additional context

_No response_

Pull request:
fix(es/parser): Allow using `package` as a parameter name in TS interface
**Description:**


**Related issue:**

 - Closes #7186.

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs
index fb68d4db64..ca6ad2dbcf 100644
--- a/crates/swc_ecma_parser/src/parser/typescript.rs
+++ b/crates/swc_ecma_parser/src/parser/typescript.rs
@@ -185,6 +185,7 @@ impl<I: Tokens> Parser<I> {
     /// `tsParseEntityName`
     fn parse_ts_entity_name(&mut self, allow_reserved_words: bool) -> PResult<TsEntityName> {
         debug_assert!(self.input.syntax().typescript());
+        trace_cur!(self, parse_ts_entity_name);
 
         let init = self.parse_ident_name()?;
         if let Ident {
@@ -1253,7 +1254,7 @@ impl<I: Tokens> Parser<I> {
 
         let _ = self.eat_any_ts_modifier()?;
 
-        if is_one_of!(self, IdentRef, "this") {
+        if is_one_of!(self, IdentName, "this") {
             bump!(self);
             return Ok(true);
         }
@@ -1808,6 +1809,7 @@ impl<I: Tokens> Parser<I> {
     /// `tsParseParenthesizedType`
     fn parse_ts_parenthesized_type(&mut self) -> PResult<TsParenthesizedType> {
         debug_assert!(self.input.syntax().typescript());
+        trace_cur!(self, parse_ts_parenthesized_type);
 
         let start = cur_pos!(self);
         expect!(self, '(');


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts b/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts
new file mode 100644
index 0000000000..a4ef879c13
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts
@@ -0,0 +1,3 @@
+export interface PackageManager {
+    onDidUnloadPackage(callback: (package: Package) => void): Disposable;
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts.json
new file mode 100644
index 0000000000..3054d88283
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7186/1/input.ts.json
@@ -0,0 +1,184 @@
+{
+  "type": "Module",
+  "span": {
+    "start": 1,
+    "end": 110,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "ExportDeclaration",
+      "span": {
+        "start": 1,
+        "end": 110,
+        "ctxt": 0
+      },
+      "declaration": {
+        "type": "TsInterfaceDeclaration",
+        "span": {
+          "start": 8,
+          "end": 110,
+          "ctxt": 0
+        },
+        "id": {
+          "type": "Identifier",
+          "span": {
+            "start": 18,
+            "end": 32,
+            "ctxt": 0
+          },
+          "value": "PackageManager",
+          "optional": false
+        },
+        "declare": false,
+        "typeParams": null,
+        "extends": [],
+        "body": {
+          "type": "TsInterfaceBody",
+          "span": {
+            "start": 33,
+            "end": 110,
+            "ctxt": 0
+          },
+          "body": [
+            {
+              "type": "TsMethodSignature",
+              "span": {
+                "start": 39,
+                "end": 108,
+                "ctxt": 0
+              },
+              "readonly": false,
+              "key": {
+                "type": "Identifier",
+                "span": {
+                  "start": 39,
+                  "end": 57,
+                  "ctxt": 0
+                },
+                "value": "onDidUnloadPackage",
+                "optional": false
+              },
+              "computed": false,
+              "optional": false,
+              "params": [
+                {
+                  "type": "Identifier",
+                  "span": {
+                    "start": 58,
+                    "end": 94,
+                    "ctxt": 0
+                  },
+                  "value": "callback",
+                  "optional": false,
+                  "typeAnnotation": {
+                    "type": "TsTypeAnnotation",
+                    "span": {
+                      "start": 66,
+                      "end": 94,
+                      "ctxt": 0
+                    },
+                    "typeAnnotation": {
+                      "type": "TsFunctionType",
+                      "span": {
+                        "start": 68,
+                        "end": 94,
+                        "ctxt": 0
+                      },
+                      "params": [
+                        {
+                          "type": "Identifier",
+                          "span": {
+                            "start": 69,
+                            "end": 85,
+                            "ctxt": 0
+                          },
+                          "value": "package",
+                          "optional": false,
+                          "typeAnnotation": {
+                            "type": "TsTypeAnnotation",
+                            "span": {
+                              "start": 76,
+                              "end": 85,
+                              "ctxt": 0
+                            },
+                            "typeAnnotation": {
+                              "type": "TsTypeReference",
+                              "span": {
+                                "start": 78,
+                                "end": 85,
+                                "ctxt": 0
+                              },
+                              "typeName": {
+                                "type": "Identifier",
+                                "span": {
+                                  "start": 78,
+                                  "end": 85,
+                                  "ctxt": 0
+                                },
+                                "value": "Package",
+                                "optional": false
+                              },
+                              "typeParams": null
+                            }
+                          }
+                        }
+                      ],
+                      "typeParams": null,
+                      "typeAnnotation": {
+                        "type": "TsTypeAnnotation",
+                        "span": {
+                          "start": 87,
+                          "end": 94,
+                          "ctxt": 0
+                        },
+                        "typeAnnotation": {
+                          "type": "TsKeywordType",
+                          "span": {
+                            "start": 90,
+                            "end": 94,
+                            "ctxt": 0
+                          },
+                          "kind": "void"
+                        }
+                      }
+                    }
+                  }
+                }
+              ],
+              "typeAnn": {
+                "type": "TsTypeAnnotation",
+                "span": {
+                  "start": 95,
+                  "end": 107,
+                  "ctxt": 0
+                },
+                "typeAnnotation": {
+                  "type": "TsTypeReference",
+                  "span": {
+                    "start": 97,
+                    "end": 107,
+                    "ctxt": 0
+                  },
+                  "typeName": {
+                    "type": "Identifier",
+                    "span": {
+                      "start": 97,
+                      "end": 107,
+                      "ctxt": 0
+                    },
+                    "value": "Disposable",
+                    "optional": false
+                  },
+                  "typeParams": null
+                }
+              },
+              "typeParams": null
+            }
+          ]
+        }
+      }
+    }
+  ],
+  "interpreter": null
+}
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx b/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx
new file mode 100644
index 0000000000..a4ef879c13
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx
@@ -0,0 +1,3 @@
+export interface PackageManager {
+    onDidUnloadPackage(callback: (package: Package) => void): Disposable;
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx.json
new file mode 100644
index 0000000000..3054d88283
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7186/2/input.tsx.json
@@ -0,0 +1,184 @@
+{
+  "type": "Module",
+  "span": {
+    "start": 1,
+    "end": 110,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "ExportDeclaration",
+      "span": {
+        "start": 1,
+        "end": 110,
+        "ctxt": 0
+      },
+      "declaration": {
+        "type": "TsInterfaceDeclaration",
+        "span": {
+          "start": 8,
+          "end": 110,
+          "ctxt": 0
+        },
+        "id": {
+          "type": "Identifier",
+          "span": {
+            "start": 18,
+            "end": 32,
+            "ctxt": 0
+          },
+          "value": "PackageManager",
+          "optional": false
+        },
+        "declare": false,
+        "typeParams": null,
+        "extends": [],
+        "body": {
+          "type": "TsInterfaceBody",
+          "span": {
+            "start": 33,
+            "end": 110,
+            "ctxt": 0
+          },
+          "body": [
+            {
+              "type": "TsMethodSignature",
+              "span": {
+                "start": 39,
+                "end": 108,
+                "ctxt": 0
+              },
+              "readonly": false,
+              "key": {
+                "type": "Identifier",
+                "span": {
+                  "start": 39,
+                  "end": 57,
+                  "ctxt": 0
+                },
+                "value": "onDidUnloadPackage",
+                "optional": false
+              },
+              "computed": false,
+              "optional": false,
+              "params": [
+                {
+                  "type": "Identifier",
+                  "span": {
+                    "start": 58,
+                    "end": 94,
+                    "ctxt": 0
+                  },
+                  "value": "callback",
+                  "optional": false,
+                  "typeAnnotation": {
+                    "type": "TsTypeAnnotation",
+                    "span": {
+                      "start": 66,
+                      "end": 94,
+                      "ctxt": 0
+                    },
+                    "typeAnnotation": {
+                      "type": "TsFunctionType",
+                      "span": {
+                        "start": 68,
+                        "end": 94,
+                        "ctxt": 0
+                      },
+                      "params": [
+                        {
+                          "type": "Identifier",
+                          "span": {
+                            "start": 69,
+                            "end": 85,
+                            "ctxt": 0
+                          },
+                          "value": "package",
+                          "optional": false,
+                          "typeAnnotation": {
+                            "type": "TsTypeAnnotation",
+                            "span": {
+                              "start": 76,
+                              "end": 85,
+                              "ctxt": 0
+                            },
+                            "typeAnnotation": {
+                              "type": "TsTypeReference",
+                              "span": {
+                                "start": 78,
+                                "end": 85,
+                                "ctxt": 0
+                              },
+                              "typeName": {
+                                "type": "Identifier",
+                                "span": {
+                                  "start": 78,
+                                  "end": 85,
+                                  "ctxt": 0
+                                },
+                                "value": "Package",
+                                "optional": false
+                              },
+                              "typeParams": null
+                            }
+                          }
+                        }
+                      ],
+                      "typeParams": null,
+                      "typeAnnotation": {
+                        "type": "TsTypeAnnotation",
+                        "span": {
+                          "start": 87,
+                          "end": 94,
+                          "ctxt": 0
+                        },
+                        "typeAnnotation": {
+                          "type": "TsKeywordType",
+                          "span": {
+                            "start": 90,
+                            "end": 94,
+                            "ctxt": 0
+                          },
+                          "kind": "void"
+                        }
+                      }
+                    }
+                  }
+                }
+              ],
+              "typeAnn": {
+                "type": "TsTypeAnnotation",
+                "span": {
+                  "start": 95,
+                  "end": 107,
+                  "ctxt": 0
+                },
+                "typeAnnotation": {
+                  "type": "TsTypeReference",
+                  "span": {
+                    "start": 97,
+                    "end": 107,
+                    "ctxt": 0
+                  },
+                  "typeName": {
+                    "type": "Identifier",
+                    "span": {
+                      "start": 97,
+                      "end": 107,
+                      "ctxt": 0
+                    },
+                    "value": "Disposable",
+                    "optional": false
+                  },
+                  "typeParams": null
+                }
+              },
+              "typeParams": null
+            }
+          ]
+        }
+      }
+    }
+  ],
+  "interpreter": null
+}