Repository: swc-project/swc (rust)

Issue:
Inappropriate error message
### Describe the bug

Expected ',', got 'Some(g)' 
We should not print `Display` trait string of `Some(Token)`, 
This may let users got confused, because not every javascript/typescript developer is familiar with `rust`
```bash

  x Expected ',', got 'Some(g)'
   ,----
 5 | g = CONST
   : ^
   `----


Caused by:
    0: failed to parse code
    1: error was recoverable, but proceeding would result in wrong codegen
    2: Syntax Error
```

### Input code

```typescript
const CONST = 9000 % 2;
const enum D {
    // Comma is required, but parser can recover because of the newline.
    d = 10,
    g = CONST
}
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": false
    },
    "target": "es5",
    "loose": false
  },
  "module": {
    "type": "es6"
  },
  "minify": false,
  "isModule": true,
  "env": {
    "targets": "chrome 50"
  }
}
```


### Playground link

https://play.swc.rs/?version=1.2.246&code=H4sIAAAAAAAAAx2NOw7CMBBEe59iGjqUGDqEqEJNinABZ7OAJbwGf6CIuDsrT%2FU0I82jKLlgGC%2FTFSccrLXYYH801HqWGnDGaqDpewwxBAefkfhdfeJli7kWvFzKnEBOdKD4UZ6ZXM2MeEN5MIS%2FTy%2FctaNFTTvb8K7Y5Ob3B3%2F8jPaKAAAA&config=H4sIAAAAAAAAA0WMSw7CMAxEr4K87oJNWfQOHCIKLgSlSeRxEVGVu%2BNEldjN580c9Ian5aDiBCxdoSZ1X1pIa2F4CUVpIoVFq4vgZsbJk9UQxmxdzBn8b7f82CP3q%2F4wqBv1PKSw1pObKOB%2Bgiq7eU6fsRnfsJl%2FSd74Ml%2BptR%2BfXRtTqAAAAA%3D%3D

### Expected behavior

Maybe the change the error message to `Expected ',', got 'g'` would be better.

### Actual behavior

_No response_

### Version

1.2.246

### Additional context

_No response_

Pull request description:
fix: #5718
<!-- 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:**
1. Fixed #5718 
<!-- Explain the **motivation** for making this change. What existing problem does the pull request solve? -->

**BREAKING CHANGE:**
Nope
<!--
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):**
1. Fixed #5718 


Patch:
diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs
index b28bbc8500..b5270e2d53 100644
--- a/crates/swc_ecma_parser/src/parser/typescript.rs
+++ b/crates/swc_ecma_parser/src/parser/typescript.rs
@@ -137,7 +137,10 @@ impl<I: Tokens> Parser<I> {
 
             if kind == ParsingContext::EnumMembers {
                 const TOKEN: &Token = &Token::Comma;
-                let cur = format!("{:?}", cur!(self, false).ok());
+                let cur = match cur!(self, false).ok() {
+                    Some(tok) => format!("{:?}", tok),
+                    None => "EOF".to_string(),
+                };
                 self.emit_err(self.input.cur_span(), SyntaxError::Expected(TOKEN, cur));
                 continue;
             }


Test patch:
diff --git a/crates/swc/tests/tsc-references/parserComputedPropertyName30.1.normal.js b/crates/swc/tests/tsc-references/parserComputedPropertyName30.1.normal.js
index 0f52b6afa0..5735d0491f 100644
--- a/crates/swc/tests/tsc-references/parserComputedPropertyName30.1.normal.js
+++ b/crates/swc/tests/tsc-references/parserComputedPropertyName30.1.normal.js
@@ -6,7 +6,7 @@
 //!    : ^^
 //!    `----
 //! 
-//!   x Expected ',', got 'Some([)'
+//!   x Expected ',', got '['
 //!    ,----
 //!  4 | [e2] = 1
 //!    : ^
diff --git a/crates/swc/tests/tsc-references/parserComputedPropertyName30.2.minified.js b/crates/swc/tests/tsc-references/parserComputedPropertyName30.2.minified.js
index 0f52b6afa0..5735d0491f 100644
--- a/crates/swc/tests/tsc-references/parserComputedPropertyName30.2.minified.js
+++ b/crates/swc/tests/tsc-references/parserComputedPropertyName30.2.minified.js
@@ -6,7 +6,7 @@
 //!    : ^^
 //!    `----
 //! 
-//!   x Expected ',', got 'Some([)'
+//!   x Expected ',', got '['
 //!    ,----
 //!  4 | [e2] = 1
 //!    : ^
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum-2/input.ts.stderr b/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum-2/input.ts.stderr
index b0e9e6ee51..0e981d194e 100644
--- a/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum-2/input.ts.stderr
+++ b/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum-2/input.ts.stderr
@@ -1,5 +1,5 @@
 
-  x Expected ',', got 'Some(c)'
+  x Expected ',', got 'c'
    ,-[$DIR/tests/typescript-errors/custom/const-enum-2/input.ts:4:5]
  4 | c
    : ^
diff --git a/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum/input.ts.stderr b/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum/input.ts.stderr
index 80640167a4..98a46bf976 100644
--- a/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum/input.ts.stderr
+++ b/crates/swc_ecma_parser/tests/typescript-errors/custom/const-enum/input.ts.stderr
@@ -1,5 +1,5 @@
 
-  x Expected ',', got 'Some(g)'
+  x Expected ',', got 'g'
    ,-[$DIR/tests/typescript-errors/custom/const-enum/input.ts:4:5]
  4 | g = CONST
    : ^