Repository: swc-project/swc (rust)

Issue:
Panic on `@jsxFrag null`
### Describe the bug

SWC panics when transpiling TypeScript if `@jsxFrag` is `null`.


### Input code

```typescript
/* @jsx h */
/* @jsxFrag null */
<></>;
```


### Config

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    }
  },
  "isModule": true
}
```


### Playground link

https://play.swc.rs/?version=1.3.64&code=H4sIAAAAAAAAA9PXUnDIKq5QyFDQ0ufSh3DcihLTFfJKc3JAYjZ2Nvp21lwASiTFyigAAAA%3D&config=H4sIAAAAAAAAA6vmUlBQyipOVrJSqAYygZyCxKLi1CI4HyhSXJlXklgBFFEqqSxILU4uyiwoUdKByZYUg6RKikpTwSK1QLIWJKmUWeybn1KakwqTreUCAAfv7CNtAAAA

### Expected behavior

Babel and tsc output is `h(null, null)`.


### Actual behavior

```text
panicked at 'failed to determine top-level Id for jsx expression', /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_ecma_transforms_typescript-0.179.3/src/strip.rs:252:13
```


### Version

1.3.64

### Additional context

_No response_

Pull request description:
fix(es/typescript): Don't panic of `@jsxFrag null`
**Description:**

**Related issue:**

 - Closes #7539.

Patch:
diff --git a/crates/swc_ecma_transforms_typescript/src/strip.rs b/crates/swc_ecma_transforms_typescript/src/strip.rs
index ddf48d8050..3118a019f3 100644
--- a/crates/swc_ecma_transforms_typescript/src/strip.rs
+++ b/crates/swc_ecma_transforms_typescript/src/strip.rs
@@ -248,6 +248,7 @@ fn id_for_jsx(e: &Expr) -> Id {
     match e {
         Expr::Ident(i) => i.to_id(),
         Expr::Member(MemberExpr { obj, .. }) => id_for_jsx(obj),
+        Expr::Lit(Lit::Null(..)) => (js_word!("null"), Default::default()),
         _ => {
             panic!("failed to determine top-level Id for jsx expression")
         }


Test patch:
diff --git a/crates/swc/tests/fixture/issues-7xxx/7539/input/.swcrc b/crates/swc/tests/fixture/issues-7xxx/7539/input/.swcrc
new file mode 100644
index 0000000000..497481f1a0
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7539/input/.swcrc
@@ -0,0 +1,9 @@
+{
+    "jsc": {
+        "parser": {
+            "syntax": "typescript",
+            "tsx": true
+        }
+    },
+    "isModule": true
+}
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7539/input/index.js b/crates/swc/tests/fixture/issues-7xxx/7539/input/index.js
new file mode 100644
index 0000000000..27ad390aca
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7539/input/index.js
@@ -0,0 +1,3 @@
+/* @jsx h */
+/* @jsxFrag null */
+<></>;
\ No newline at end of file
diff --git a/crates/swc/tests/fixture/issues-7xxx/7539/output/index.js b/crates/swc/tests/fixture/issues-7xxx/7539/output/index.js
new file mode 100644
index 0000000000..2c1488f432
--- /dev/null
+++ b/crates/swc/tests/fixture/issues-7xxx/7539/output/index.js
@@ -0,0 +1,1 @@
+/* @jsx h */ /* @jsxFrag null */ /*#__PURE__*/ h(null, null);
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/input.tsx b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/input.tsx
new file mode 100644
index 0000000000..27ad390aca
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/input.tsx
@@ -0,0 +1,3 @@
+/* @jsx h */
+/* @jsxFrag null */
+<></>;
\ No newline at end of file
diff --git a/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/output.js b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/output.js
new file mode 100644
index 0000000000..d0f3e9c84a
--- /dev/null
+++ b/crates/swc_ecma_transforms_typescript/tests/fixture/issue-7539/output.js
@@ -0,0 +1,1 @@
+/* @jsx h */ /* @jsxFrag null */ <></>;