Repository: swc-project/swc (rust)

Issue:
Fails to parse negative bigint literal in type
### Describe the bug

Negative bigint literals don't seem to be parsed in a type.

### Input code

```typescript
type Test = -1n | 1n;
```


### Config

_No response_

### Playground link

https://play.swc.rs/?version=1.2.197&code=H4sIAAAAAAAAAyupLEhVCEktLlGwVdA1zFOoUTDMs%2Bbl4uVKzkksLobIVPNyKQBBcWZ6noamFVwZTLyWl6sWADPztl5HAAAA&config=H4sIAAAAAAAAA0WOSw7DMAhE78I623bhO%2BQQlkMiV%2F4JiFTLyt2LHSvdzTDDgwYfdmAaFEuM1BXXJPYLBqQWZEe%2BCCwgrCOhEy%2FVlg4UbSC%2FNAo5M97hAtEnv9fOcTkWQmYwuw3cI5uOgNNeyol5O%2FugjVOD91YeC3knz9pt17w9q%2F8rs%2BJ5najx4Q%2BHHCMs1QAAAA%3D%3D

### Expected behavior

Parses.

### Actual behavior

  x Unexpected token `bigint literal (1, 1n)`. Expected a numeric literal
   ,-[input.tsx:1:1]
 1 | type Test = -1n | 1n;
   :              ^^
   `----

### Version

1.2.197

### Additional context

_No response_

Pull request:
fix(es/parser): negative bigint literal in type
<!-- 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):**
- fix #4937 

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs
index 1b9b636c5a..60ef607034 100644
--- a/crates/swc_ecma_parser/src/parser/typescript.rs
+++ b/crates/swc_ecma_parser/src/parser/typescript.rs
@@ -2058,8 +2058,8 @@ impl<I: Tokens> Parser<I> {
 
                 bump!(self);
 
-                if !matches!(*cur!(self, true)?, Token::Num { .. }) {
-                    unexpected!(self, "a numeric literal")
+                if !matches!(*cur!(self, true)?, Token::Num { .. } | Token::BigInt { .. }) {
+                    unexpected!(self, "numeric literal or bigint literal")
                 }
 
                 let lit = self.parse_lit()?;
@@ -2082,6 +2082,24 @@ impl<I: Tokens> Parser<I> {
                             raw: Some(new_raw.into()),
                         })
                     }
+                    Lit::BigInt(BigInt { span, value, raw }) => {
+                        let mut new_raw = String::from("-");
+
+                        match raw {
+                            Some(raw) => {
+                                new_raw.push_str(&raw);
+                            }
+                            _ => {
+                                write!(new_raw, "{}", value).unwrap();
+                            }
+                        };
+
+                        TsLit::BigInt(BigInt {
+                            span,
+                            value: -value,
+                            raw: Some(new_raw.into()),
+                        })
+                    }
                     _ => unreachable!(),
                 };
 


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts b/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts
new file mode 100644
index 0000000000..8c3f5ff6da
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts
@@ -0,0 +1,6 @@
+type Test = -1n | 1n;
+
+class Test {
+    sign(): -1n | 1n {
+    }
+}
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts.json b/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts.json
new file mode 100644
index 0000000000..48d1f99623
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-4937/index.ts.json
@@ -0,0 +1,223 @@
+{
+  "type": "Script",
+  "span": {
+    "start": 1,
+    "end": 67,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "TsTypeAliasDeclaration",
+      "span": {
+        "start": 1,
+        "end": 22,
+        "ctxt": 0
+      },
+      "declare": false,
+      "id": {
+        "type": "Identifier",
+        "span": {
+          "start": 6,
+          "end": 10,
+          "ctxt": 0
+        },
+        "value": "Test",
+        "optional": false
+      },
+      "typeParams": null,
+      "typeAnnotation": {
+        "type": "TsUnionType",
+        "span": {
+          "start": 13,
+          "end": 21,
+          "ctxt": 0
+        },
+        "types": [
+          {
+            "type": "TsLiteralType",
+            "span": {
+              "start": 13,
+              "end": 16,
+              "ctxt": 0
+            },
+            "literal": {
+              "type": "BigIntLiteral",
+              "span": {
+                "start": 14,
+                "end": 16,
+                "ctxt": 0
+              },
+              "value": [
+                -1,
+                [
+                  1
+                ]
+              ],
+              "raw": "-1n"
+            }
+          },
+          {
+            "type": "TsLiteralType",
+            "span": {
+              "start": 19,
+              "end": 21,
+              "ctxt": 0
+            },
+            "literal": {
+              "type": "BigIntLiteral",
+              "span": {
+                "start": 19,
+                "end": 21,
+                "ctxt": 0
+              },
+              "value": [
+                1,
+                [
+                  1
+                ]
+              ],
+              "raw": "1n"
+            }
+          }
+        ]
+      }
+    },
+    {
+      "type": "ClassDeclaration",
+      "identifier": {
+        "type": "Identifier",
+        "span": {
+          "start": 30,
+          "end": 34,
+          "ctxt": 0
+        },
+        "value": "Test",
+        "optional": false
+      },
+      "declare": false,
+      "span": {
+        "start": 24,
+        "end": 67,
+        "ctxt": 0
+      },
+      "decorators": [],
+      "body": [
+        {
+          "type": "ClassMethod",
+          "span": {
+            "start": 41,
+            "end": 65,
+            "ctxt": 0
+          },
+          "key": {
+            "type": "Identifier",
+            "span": {
+              "start": 41,
+              "end": 45,
+              "ctxt": 0
+            },
+            "value": "sign",
+            "optional": false
+          },
+          "function": {
+            "params": [],
+            "decorators": [],
+            "span": {
+              "start": 41,
+              "end": 65,
+              "ctxt": 0
+            },
+            "body": {
+              "type": "BlockStatement",
+              "span": {
+                "start": 58,
+                "end": 65,
+                "ctxt": 0
+              },
+              "stmts": []
+            },
+            "generator": false,
+            "async": false,
+            "typeParameters": null,
+            "returnType": {
+              "type": "TsTypeAnnotation",
+              "span": {
+                "start": 47,
+                "end": 57,
+                "ctxt": 0
+              },
+              "typeAnnotation": {
+                "type": "TsUnionType",
+                "span": {
+                  "start": 49,
+                  "end": 57,
+                  "ctxt": 0
+                },
+                "types": [
+                  {
+                    "type": "TsLiteralType",
+                    "span": {
+                      "start": 49,
+                      "end": 52,
+                      "ctxt": 0
+                    },
+                    "literal": {
+                      "type": "BigIntLiteral",
+                      "span": {
+                        "start": 50,
+                        "end": 52,
+                        "ctxt": 0
+                      },
+                      "value": [
+                        -1,
+                        [
+                          1
+                        ]
+                      ],
+                      "raw": "-1n"
+                    }
+                  },
+                  {
+                    "type": "TsLiteralType",
+                    "span": {
+                      "start": 55,
+                      "end": 57,
+                      "ctxt": 0
+                    },
+                    "literal": {
+                      "type": "BigIntLiteral",
+                      "span": {
+                        "start": 55,
+                        "end": 57,
+                        "ctxt": 0
+                      },
+                      "value": [
+                        1,
+                        [
+                          1
+                        ]
+                      ],
+                      "raw": "1n"
+                    }
+                  }
+                ]
+              }
+            }
+          },
+          "kind": "method",
+          "isStatic": false,
+          "accessibility": null,
+          "isAbstract": false,
+          "isOptional": false,
+          "isOverride": false
+        }
+      ],
+      "superClass": null,
+      "isAbstract": false,
+      "typeParams": null,
+      "superTypeParams": null,
+      "implements": []
+    }
+  ],
+  "interpreter": null
+}