Repository: swc-project/swc (rust)

Issue:
 SyntaxError: Unexpected token '-'
### Describe the bug

When using null collapsing and dash in accessing object properties, it transform the variable in a incorrect js variable name

Codesandbox: https://codesandbox.io/s/swc-bug-1-3-15-1s90ov?file=/src/index.ts


### Input code

```typescript

Snippet: 

    // breaks swc SyntaxError: Unexpected token '-'
    // it breaks only in latest version 1.3.15
    // it works in 1.3.14
    const test = req.headers["test-dash"] ?? req.headers["test-dash-2"];

    // works
    const test2 = req.headers["test-dash"] || req.headers["test-dash-2"];

```
```


### Config

_No response_

### Playground link

https://codesandbox.io/s/swc-bug-1-3-15-1s90ov?file=/src/index.ts

### Expected behavior

It should work

### Actual behavior

```
/sandbox/src/index.ts:13
    var _req_headers_test-dash;
                         ^

SyntaxError: Unexpected token '-'
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
```

### Version

1.3.15

### Additional context

_No response_

Pull request:
fix(es/utils): Verify alias ident name
<!-- 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 #6420 

Patch:
diff --git a/crates/swc_ecma_utils/src/lib.rs b/crates/swc_ecma_utils/src/lib.rs
index 8261637b0a..66886fbadb 100644
--- a/crates/swc_ecma_utils/src/lib.rs
+++ b/crates/swc_ecma_utils/src/lib.rs
@@ -1964,6 +1964,10 @@ pub fn alias_ident_for(expr: &Expr, default: &str) -> Ident {
 
     let mut sym = sym(expr).unwrap_or_else(|| default.to_string());
 
+    if let Err(s) = Ident::verify_symbol(&sym) {
+        sym = s;
+    }
+
     if !sym.starts_with('_') {
         sym = format!("_{}", sym)
     }


Test patch:
diff --git a/crates/swc/tests/fixture/issues-6xxx/6420/input/input.js b/crates/swc/tests/fixture/issues-6xxx/6420/input/input.js
new file mode 100644
index 0000000000..4ed1bce29c
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-6xxx/6420/input/input.js
@@ -0,0 +1,1 @@
+const test = req.headers["test-dash"] ?? req.headers["test-dash-2"];
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-6xxx/6420/output/input.js b/crates/swc/tests/fixture/issues-6xxx/6420/output/input.js
new file mode 100644
index 0000000000..ad9276b44d
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-6xxx/6420/output/input.js
@@ -0,0 +1,2 @@
+var _req_headers_testdash;
+var test = (_req_headers_testdash = req.headers["test-dash"]) !== null && _req_headers_testdash !== void 0 ? _req_headers_testdash : req.headers["test-dash-2"];