Repository: swc-project/swc (rust)

Issue:
Nested generics in TSX script fail to compile
### Describe the bug

SWC errors when using nested generics in a `.tsx` file in a specific configuration. 

[SWC Playground](https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAA0vOzysuUUitSMwtyElVsFXQ0FSwtVOo5lJQKEotKS3KAzMVFNJK85KtFJITc3KSEpOzbUoqC1Lz0xSK83NTSzIy89JtQoAChjoKIMrIzk4jv6AkE2gwyKi80pwcTaAZtdZctdYAU5fgz24AAAA%3D&config=H4sIAAAAAAAAA02OvQ6DMAyEd54i8tyhytChbxOlpgoiEPmM1Ajx7nWgPyyW7zv7dGvnHA2IdHerrSZKELD8tBHUScPLCGktjCipKF2%2BrqJZKgvvZDsM0iBP1vbE8FfvPw%2BU05T6eo6Pcy7CgLE%2BjDjF7IPy%2FFhG%2FhdsJY7cG7WjbnsDOkAxqsUAAAA%3D)
[Typescript Playground](https://www.typescriptlang.org/play?#code/GYVwdgxgLglg9mABBAhgGzQIxRA1gHgBUA+ACgkwC5FSUAnAc2vFzDgHcwBKRAXmMRgQGHgG8AvgChJoSLASIAznAC2AUygALGGAZEANAFUyKaoX2IqiQ12qjEpxOcvVDicYlGTEiOhpB0SF4+Pij63iGYEeIA3JJSklAAngAOak6pagCMfEpQdDoMcclpGWkATLlCKphqdHGSEAiKUIhqAB4oKilo6bw0PPyeEX5QAUERPrIQ1KgY2Hj4JWpwwEqqGtq6RJlZFoSZ5cRkcCnyYIp8AkIi0XGx0h1dPWqkXDFAA)

The code that fails:
```typescript
const example = () => {
  return {
    func: callback<typeof something<Type1, Type2>>(options => null)
  };
};
```

SWC succeeds when the nested generics are externalised ([playground](https://play.swc.rs/?version=1.3.66&code=H4sIAAAAAAAAAyupLEhVcE7MyUlKTM72LyjJzM8rVrBVKAEK56cpFOfnppZkZOal24QABQx1FECUkR0XVzJQWYlCakVibkFOKlC9hqaCrZ1CNZeCQlFqSWlRHpipoJBWmpdspZAMNd4GzR47jXyYhXYKeaU5OZpATbXWXLXWADSvpiqWAAAA&config=H4sIAAAAAAAAA02OvQ6DMAyEd54i8tyhytChbxOlpgoiEPmM1Ajx7nWgPyyW7zv7dGvnHA2IdHerrSZKELD8tBHUScPLCGktjCipKF2%2BrqJZKgvvZDsM0iBP1vbE8FfvPw%2BU05T6eo6Pcy7CgLE%2BjDjF7IPy%2FFhG%2FhdsJY7cG7WjbnsDOkAxqsUAAAA%3D))

```typescript
type CallbackOptions = typeof something<Type1, Type2>

const example = () => {
  return {
    func: callback<CallbackOptions>(options => null)
  };
};
```

I have tried different variations to see where the problem is but they seem to compile as expected

```typescript
const example = callback<typeof something<Type1, Type2>>(options => null)
```

### Settings

```json
{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2022",
    "minify": {
      "compress": false
    },
  },
  "module": {
    "type": "es6"
  }
}
```

### Expected behavior

To strip the types

### Additional Info

This started happening with version 1.3.59 but was passing prior to that

[playground 1.3.58](https://play.swc.rs/?version=1.3.58&code=H4sIAAAAAAAAA0vOzysuUUitSMwtyElVsFXQ0FSwtVOo5lJQKEotKS3KAzMVFNJK85KtFJITc3KSEpOzbUoqC1Lz0xSK83NTSzIy89JtQoAChjoKIMrIzk4jv6AkE2gwyKi80pwcTaAZtdZctdYAU5fgz24AAAA%3D&config=H4sIAAAAAAAAA1WQvW7DMAyE9z6FoTmoCw8ZsrbIlilPQCh0w0J%2FICkgRuB3jyTHcbqJ3%2FF04N0%2Fus78iTWH7l6eZUjAgvyaC5EpKNwKMTolFMuU1OxWVaVKyhkbmRfBKPAvajWhDF%2FDYFbOEGSM7N8TsuAPjhTwGPnbgciR0F3k%2Be8rihGsvvkKIp8i6zlmtljDrqpJDn2P4j%2Fl2qfFstsMnIOSb7uQNXpQsuYpz%2F8ucDFK3RvBSb2tcePjJTvc6qqVLFfuzbZEgcZp9TZEclqdrav5AeQIxLB6AQAA)
[playground 1.3.59](https://play.swc.rs/?version=1.3.59&code=H4sIAAAAAAAAA0vOzysuUUitSMwtyElVsFXQ0FSwtVOo5lJQKEotKS3KAzMVFNJK85KtFJITc3KSEpOzbUoqC1Lz0xSK83NTSzIy89JtQoAChjoKIMrIzk4jv6AkE2gwyKi80pwcTaAZtdZctdYAU5fgz24AAAA%3D&config=H4sIAAAAAAAAA1WQvW7DMAyE9z6FoTmoCw8ZsrbIlilPQCh0w0J%2FICkgRuB3jyTHcbqJ3%2FF04N0%2Fus78iTWH7l6eZUjAgvyaC5EpKNwKMTolFMuU1OxWVaVKyhkbmRfBKPAvajWhDF%2FDYFbOEGSM7N8TsuAPjhTwGPnbgciR0F3k%2Be8rihGsvvkKIp8i6zlmtljDrqpJDn2P4j%2Fl2qfFstsMnIOSb7uQNXpQsuYpz%2F8ucDFK3RvBSb2tcePjJTvc6qqVLFfuzbZEgcZp9TZEclqdrav5AeQIxLB6AQAA)

### Version

1.3.66

Pull request description:
fix(es/parser): Adjust context while parsing type arguments of TypeScript type queries
**Description:**


**Related issue:**

 - Closes #7580.

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/typescript.rs b/crates/swc_ecma_parser/src/parser/typescript.rs
index beb72c833a..790642b928 100644
--- a/crates/swc_ecma_parser/src/parser/typescript.rs
+++ b/crates/swc_ecma_parser/src/parser/typescript.rs
@@ -361,7 +361,11 @@ impl<I: Tokens> Parser<I> {
         };
 
         let type_args = if !self.input.had_line_break_before_cur() && is!(self, '<') {
-            Some(self.parse_ts_type_args()?)
+            let ctx = Context {
+                should_not_lex_lt_or_gt_as_type: false,
+                ..self.ctx()
+            };
+            Some(self.with_ctx(ctx).parse_ts_type_args()?)
         } else {
             None
         };


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx b/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx
new file mode 100644
index 0000000000..ca74c80866
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx
@@ -0,0 +1,5 @@
+const example = () => {
+    return {
+      func: callback<typeof something<Type1, Type2>>(options => null)
+    };
+  };
\ No newline at end of file
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx.json
new file mode 100644
index 0000000000..28eb5e9760
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7580/input.tsx.json
@@ -0,0 +1,229 @@
+{
+  "type": "Script",
+  "span": {
+    "start": 1,
+    "end": 119,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "VariableDeclaration",
+      "span": {
+        "start": 1,
+        "end": 119,
+        "ctxt": 0
+      },
+      "kind": "const",
+      "declare": false,
+      "declarations": [
+        {
+          "type": "VariableDeclarator",
+          "span": {
+            "start": 7,
+            "end": 118,
+            "ctxt": 0
+          },
+          "id": {
+            "type": "Identifier",
+            "span": {
+              "start": 7,
+              "end": 14,
+              "ctxt": 0
+            },
+            "value": "example",
+            "optional": false,
+            "typeAnnotation": null
+          },
+          "init": {
+            "type": "ArrowFunctionExpression",
+            "span": {
+              "start": 17,
+              "end": 118,
+              "ctxt": 0
+            },
+            "params": [],
+            "body": {
+              "type": "BlockStatement",
+              "span": {
+                "start": 23,
+                "end": 118,
+                "ctxt": 0
+              },
+              "stmts": [
+                {
+                  "type": "ReturnStatement",
+                  "span": {
+                    "start": 29,
+                    "end": 114,
+                    "ctxt": 0
+                  },
+                  "argument": {
+                    "type": "ObjectExpression",
+                    "span": {
+                      "start": 36,
+                      "end": 113,
+                      "ctxt": 0
+                    },
+                    "properties": [
+                      {
+                        "type": "KeyValueProperty",
+                        "key": {
+                          "type": "Identifier",
+                          "span": {
+                            "start": 44,
+                            "end": 48,
+                            "ctxt": 0
+                          },
+                          "value": "func",
+                          "optional": false
+                        },
+                        "value": {
+                          "type": "CallExpression",
+                          "span": {
+                            "start": 50,
+                            "end": 107,
+                            "ctxt": 0
+                          },
+                          "callee": {
+                            "type": "Identifier",
+                            "span": {
+                              "start": 50,
+                              "end": 58,
+                              "ctxt": 0
+                            },
+                            "value": "callback",
+                            "optional": false
+                          },
+                          "arguments": [
+                            {
+                              "spread": null,
+                              "expression": {
+                                "type": "ArrowFunctionExpression",
+                                "span": {
+                                  "start": 91,
+                                  "end": 106,
+                                  "ctxt": 0
+                                },
+                                "params": [
+                                  {
+                                    "type": "Identifier",
+                                    "span": {
+                                      "start": 91,
+                                      "end": 98,
+                                      "ctxt": 0
+                                    },
+                                    "value": "options",
+                                    "optional": false,
+                                    "typeAnnotation": null
+                                  }
+                                ],
+                                "body": {
+                                  "type": "NullLiteral",
+                                  "span": {
+                                    "start": 102,
+                                    "end": 106,
+                                    "ctxt": 0
+                                  }
+                                },
+                                "async": false,
+                                "generator": false,
+                                "typeParameters": null,
+                                "returnType": null
+                              }
+                            }
+                          ],
+                          "typeArguments": {
+                            "type": "TsTypeParameterInstantiation",
+                            "span": {
+                              "start": 58,
+                              "end": 90,
+                              "ctxt": 0
+                            },
+                            "params": [
+                              {
+                                "type": "TsTypeQuery",
+                                "span": {
+                                  "start": 59,
+                                  "end": 89,
+                                  "ctxt": 0
+                                },
+                                "exprName": {
+                                  "type": "Identifier",
+                                  "span": {
+                                    "start": 66,
+                                    "end": 75,
+                                    "ctxt": 0
+                                  },
+                                  "value": "something",
+                                  "optional": false
+                                },
+                                "typeArguments": {
+                                  "type": "TsTypeParameterInstantiation",
+                                  "span": {
+                                    "start": 75,
+                                    "end": 89,
+                                    "ctxt": 0
+                                  },
+                                  "params": [
+                                    {
+                                      "type": "TsTypeReference",
+                                      "span": {
+                                        "start": 76,
+                                        "end": 81,
+                                        "ctxt": 0
+                                      },
+                                      "typeName": {
+                                        "type": "Identifier",
+                                        "span": {
+                                          "start": 76,
+                                          "end": 81,
+                                          "ctxt": 0
+                                        },
+                                        "value": "Type1",
+                                        "optional": false
+                                      },
+                                      "typeParams": null
+                                    },
+                                    {
+                                      "type": "TsTypeReference",
+                                      "span": {
+                                        "start": 83,
+                                        "end": 88,
+                                        "ctxt": 0
+                                      },
+                                      "typeName": {
+                                        "type": "Identifier",
+                                        "span": {
+                                          "start": 83,
+                                          "end": 88,
+                                          "ctxt": 0
+                                        },
+                                        "value": "Type2",
+                                        "optional": false
+                                      },
+                                      "typeParams": null
+                                    }
+                                  ]
+                                }
+                              }
+                            ]
+                          }
+                        }
+                      }
+                    ]
+                  }
+                }
+              ]
+            },
+            "async": false,
+            "generator": false,
+            "typeParameters": null,
+            "returnType": null
+          },
+          "definite": false
+        }
+      ]
+    }
+  ],
+  "interpreter": null
+}