Repository: swc-project/swc (rust)

Issue:
Error: Unexpected token div. Expected jsx identifier
### Describe the bug

The code fails to compile while using SWC.

```
const StyledComponent = ({ className }) => {
  const style = className({ theme: { blue: '#0000ff' } });
  return <div style={style}>Hello</div>;
};

const getStatusLabel = () => {
  const disabled = false;

  return (
    <div>
      {disabled ? <StyledComponent className={({ theme }): { [key: string]: any } => ({ color: theme.blue })} /> : null}
    </div>
  );
};
const Temp = () => <div>{getStatusLabel()}</div>;

export default Temp;
```

It works fine if I remove return type of the function which I passed to the prop className
 

### Input code

```typescript
const StyledComponent = ({ className }) => {
  const style = className({ theme: { blue: '#0000ff' } });
  return <div style={style}>Hello</div>;
};

const getStatusLabel = () => {
  const disabled = false;

  return (
    <div>
      {disabled ? <StyledComponent className={({ theme }): { [key: string]: any } => ({ color: theme.blue })} /> : null}
    </div>
  );
};
const Temp = () => <div>{getStatusLabel()}</div>;

export default Temp;
```


### Config

```json
{
  "$schema": "http://json.schemastore.org/swcrc",
  "jsc": {
    "experimental": {
      "plugins": [["jest_workaround", {}]]
    },
    "parser": {
      "syntax": "typescript",
      "tsx": true,
      "decorators": false,
      "dynamicImport": true
    }
  },
  "module": {
    "type": "commonjs"
  }
}
```


### Playground link

https://play.swc.rs/?version=1.3.46&code=H4sIAAAAAAAAA12Ru27EIBBFe75ipBT2NnFqv1KkSRGlyKaLUmB7vGsFwwpwFAvx7xkgi5R1w0jca86BZb0obeEN%2BWhh1mqFQoe5aBgblTQWjnYXOD0pCkqUFjooHYyCG%2FPKVwR%2FgK4HxwBS3IQ4hXKC0vaMK9bgYBAbrcXdA33zXICnekNVjXbTEtpp%2BU4%2F6FxcfP%2BMQqi2oo2%2BYT5DndAeLbebeeEDisB0gzEthg%2FETVszFwapmY8paYR4WB8nAJfjj9DeCmeTzl1dCDvofHzhXhOwXuTpswYudzIijHBBSihdp%2FR90KaKh6qHGuQmhE8I1R%2FDIbol8ndcL1koQrr%2FtuXBXy%2BE4U98vglnvonUbdgv5K0jC9QBAAA%3D&config=H4sIAAAAAAAAA01Pyw6CQAy88xWk8Ujkzh%2F4DYaYzVJ5yG43bYkSwr%2B7K6jc2pnpzHTJ8hxOYjt0BqocOtVQleUg5M8bKkqMZ%2BK2lKdlC0W6GMRG9RLHuOArIPcOvZrxh0Y8jFPbe4nQ9QoDit6exA%2FDNPkGinxZ6%2FojXYvNJxgW5KODzNHzlXrpHFAs90Gh%2BLIqiVKe8Ac1aIlNbJxS72aUAzV743p7cYFY97stPtsrgKNmGvH%2FWApN4ZacIz8IJGW2vgHh5Wx0NAEAAA%3D%3D

### Expected behavior

Code should be compiled and produce appropriate JS file

### Actual behavior

```
  x Unexpected token `div`. Expected jsx identifier
    ,-[input.tsx:9:1]
  9 |   const disabled = false;
 10 | 
 11 |   return (
 12 |     <div>
    :      ^^^
 13 |       {disabled ? <StyledComponent className={({ theme }): { [key: string]: any } => ({ color: theme.blue })} /> : null}
 14 |     </div>
 15 |   );
    `----
```

Moreover it works fine if I remove type { [key: string]: any } 

### Version

1.3.46

### Additional context

_No response_

Pull request:
fix(es/parser): Fix parsing of tsx with type ann in cond expr
**Description:**


**Related issue:**

 - Closes #7224.

Patch:
diff --git a/crates/swc_ecma_parser/src/parser/jsx.rs b/crates/swc_ecma_parser/src/parser/jsx.rs
index d897866c66..696cfa4f81 100644
--- a/crates/swc_ecma_parser/src/parser/jsx.rs
+++ b/crates/swc_ecma_parser/src/parser/jsx.rs
@@ -173,7 +173,13 @@ impl<I: Tokens> Parser<I> {
 
         let name = self.parse_jsx_namespaced_name()?;
         let value = if eat!(self, '=') {
-            self.parse_jsx_attr_value().map(Some)?
+            let ctx = Context {
+                in_cond_expr: false,
+                will_expect_colon_for_cond: false,
+                ..self.ctx()
+            };
+
+            self.with_ctx(ctx).parse_jsx_attr_value().map(Some)?
         } else {
             None
         };


Test patch:
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx
new file mode 100644
index 0000000000..16e9c855d6
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx
@@ -0,0 +1,8 @@
+const getStatusLabel = () => {
+  return (
+    <div>
+      {disabled ? <StyledComponent className={({ theme }): { [key: string]: any } => ({ color: theme.blue })} /> : null}
+    </div>
+  );
+};
+export default getStatusLabel;
diff --git a/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json
new file mode 100644
index 0000000000..2190769f79
--- /dev/null
+++ b/crates/swc_ecma_parser/tests/typescript/issue-7224/1/input.tsx.json
@@ -0,0 +1,438 @@
+{
+  "type": "Module",
+  "span": {
+    "start": 1,
+    "end": 223,
+    "ctxt": 0
+  },
+  "body": [
+    {
+      "type": "VariableDeclaration",
+      "span": {
+        "start": 1,
+        "end": 192,
+        "ctxt": 0
+      },
+      "kind": "const",
+      "declare": false,
+      "declarations": [
+        {
+          "type": "VariableDeclarator",
+          "span": {
+            "start": 7,
+            "end": 191,
+            "ctxt": 0
+          },
+          "id": {
+            "type": "Identifier",
+            "span": {
+              "start": 7,
+              "end": 21,
+              "ctxt": 0
+            },
+            "value": "getStatusLabel",
+            "optional": false,
+            "typeAnnotation": null
+          },
+          "init": {
+            "type": "ArrowFunctionExpression",
+            "span": {
+              "start": 24,
+              "end": 191,
+              "ctxt": 0
+            },
+            "params": [],
+            "body": {
+              "type": "BlockStatement",
+              "span": {
+                "start": 30,
+                "end": 191,
+                "ctxt": 0
+              },
+              "stmts": [
+                {
+                  "type": "ReturnStatement",
+                  "span": {
+                    "start": 34,
+                    "end": 189,
+                    "ctxt": 0
+                  },
+                  "argument": {
+                    "type": "ParenthesisExpression",
+                    "span": {
+                      "start": 41,
+                      "end": 188,
+                      "ctxt": 0
+                    },
+                    "expression": {
+                      "type": "JSXElement",
+                      "span": {
+                        "start": 47,
+                        "end": 184,
+                        "ctxt": 0
+                      },
+                      "opening": {
+                        "type": "JSXOpeningElement",
+                        "name": {
+                          "type": "Identifier",
+                          "span": {
+                            "start": 48,
+                            "end": 51,
+                            "ctxt": 0
+                          },
+                          "value": "div",
+                          "optional": false
+                        },
+                        "span": {
+                          "start": 47,
+                          "end": 52,
+                          "ctxt": 0
+                        },
+                        "attributes": [],
+                        "selfClosing": false,
+                        "typeArguments": null
+                      },
+                      "children": [
+                        {
+                          "type": "JSXText",
+                          "span": {
+                            "start": 52,
+                            "end": 59,
+                            "ctxt": 0
+                          },
+                          "value": "\n\n      ",
+                          "raw": "\n\n      "
+                        },
+                        {
+                          "type": "JSXExpressionContainer",
+                          "span": {
+                            "start": 59,
+                            "end": 173,
+                            "ctxt": 0
+                          },
+                          "expression": {
+                            "type": "ConditionalExpression",
+                            "span": {
+                              "start": 60,
+                              "end": 172,
+                              "ctxt": 0
+                            },
+                            "test": {
+                              "type": "Identifier",
+                              "span": {
+                                "start": 60,
+                                "end": 68,
+                                "ctxt": 0
+                              },
+                              "value": "disabled",
+                              "optional": false
+                            },
+                            "consequent": {
+                              "type": "JSXElement",
+                              "span": {
+                                "start": 71,
+                                "end": 165,
+                                "ctxt": 0
+                              },
+                              "opening": {
+                                "type": "JSXOpeningElement",
+                                "name": {
+                                  "type": "Identifier",
+                                  "span": {
+                                    "start": 72,
+                                    "end": 87,
+                                    "ctxt": 0
+                                  },
+                                  "value": "StyledComponent",
+                                  "optional": false
+                                },
+                                "span": {
+                                  "start": 71,
+                                  "end": 165,
+                                  "ctxt": 0
+                                },
+                                "attributes": [
+                                  {
+                                    "type": "JSXAttribute",
+                                    "span": {
+                                      "start": 88,
+                                      "end": 162,
+                                      "ctxt": 0
+                                    },
+                                    "name": {
+                                      "type": "Identifier",
+                                      "span": {
+                                        "start": 88,
+                                        "end": 97,
+                                        "ctxt": 0
+                                      },
+                                      "value": "className",
+                                      "optional": false
+                                    },
+                                    "value": {
+                                      "type": "JSXExpressionContainer",
+                                      "span": {
+                                        "start": 98,
+                                        "end": 162,
+                                        "ctxt": 0
+                                      },
+                                      "expression": {
+                                        "type": "ArrowFunctionExpression",
+                                        "span": {
+                                          "start": 99,
+                                          "end": 161,
+                                          "ctxt": 0
+                                        },
+                                        "params": [
+                                          {
+                                            "type": "ObjectPattern",
+                                            "span": {
+                                              "start": 100,
+                                              "end": 109,
+                                              "ctxt": 0
+                                            },
+                                            "properties": [
+                                              {
+                                                "type": "AssignmentPatternProperty",
+                                                "span": {
+                                                  "start": 102,
+                                                  "end": 107,
+                                                  "ctxt": 0
+                                                },
+                                                "key": {
+                                                  "type": "Identifier",
+                                                  "span": {
+                                                    "start": 102,
+                                                    "end": 107,
+                                                    "ctxt": 0
+                                                  },
+                                                  "value": "theme",
+                                                  "optional": false
+                                                },
+                                                "value": null
+                                              }
+                                            ],
+                                            "optional": false,
+                                            "typeAnnotation": null
+                                          }
+                                        ],
+                                        "body": {
+                                          "type": "ParenthesisExpression",
+                                          "span": {
+                                            "start": 138,
+                                            "end": 161,
+                                            "ctxt": 0
+                                          },
+                                          "expression": {
+                                            "type": "ObjectExpression",
+                                            "span": {
+                                              "start": 139,
+                                              "end": 160,
+                                              "ctxt": 0
+                                            },
+                                            "properties": [
+                                              {
+                                                "type": "KeyValueProperty",
+                                                "key": {
+                                                  "type": "Identifier",
+                                                  "span": {
+                                                    "start": 141,
+                                                    "end": 146,
+                                                    "ctxt": 0
+                                                  },
+                                                  "value": "color",
+                                                  "optional": false
+                                                },
+                                                "value": {
+                                                  "type": "MemberExpression",
+                                                  "span": {
+                                                    "start": 148,
+                                                    "end": 158,
+                                                    "ctxt": 0
+                                                  },
+                                                  "object": {
+                                                    "type": "Identifier",
+                                                    "span": {
+                                                      "start": 148,
+                                                      "end": 153,
+                                                      "ctxt": 0
+                                                    },
+                                                    "value": "theme",
+                                                    "optional": false
+                                                  },
+                                                  "property": {
+                                                    "type": "Identifier",
+                                                    "span": {
+                                                      "start": 154,
+                                                      "end": 158,
+                                                      "ctxt": 0
+                                                    },
+                                                    "value": "blue",
+                                                    "optional": false
+                                                  }
+                                                }
+                                              }
+                                            ]
+                                          }
+                                        },
+                                        "async": false,
+                                        "generator": false,
+                                        "typeParameters": null,
+                                        "returnType": {
+                                          "type": "TsTypeAnnotation",
+                                          "span": {
+                                            "start": 110,
+                                            "end": 134,
+                                            "ctxt": 0
+                                          },
+                                          "typeAnnotation": {
+                                            "type": "TsTypeLiteral",
+                                            "span": {
+                                              "start": 112,
+                                              "end": 134,
+                                              "ctxt": 0
+                                            },
+                                            "members": [
+                                              {
+                                                "type": "TsIndexSignature",
+                                                "params": [
+                                                  {
+                                                    "type": "Identifier",
+                                                    "span": {
+                                                      "start": 115,
+                                                      "end": 126,
+                                                      "ctxt": 0
+                                                    },
+                                                    "value": "key",
+                                                    "optional": false,
+                                                    "typeAnnotation": {
+                                                      "type": "TsTypeAnnotation",
+                                                      "span": {
+                                                        "start": 118,
+                                                        "end": 126,
+                                                        "ctxt": 0
+                                                      },
+                                                      "typeAnnotation": {
+                                                        "type": "TsKeywordType",
+                                                        "span": {
+                                                          "start": 120,
+                                                          "end": 126,
+                                                          "ctxt": 0
+                                                        },
+                                                        "kind": "string"
+                                                      }
+                                                    }
+                                                  }
+                                                ],
+                                                "typeAnnotation": {
+                                                  "type": "TsTypeAnnotation",
+                                                  "span": {
+                                                    "start": 127,
+                                                    "end": 132,
+                                                    "ctxt": 0
+                                                  },
+                                                  "typeAnnotation": {
+                                                    "type": "TsKeywordType",
+                                                    "span": {
+                                                      "start": 129,
+                                                      "end": 132,
+                                                      "ctxt": 0
+                                                    },
+                                                    "kind": "any"
+                                                  }
+                                                },
+                                                "readonly": false,
+                                                "static": false,
+                                                "span": {
+                                                  "start": 114,
+                                                  "end": 132,
+                                                  "ctxt": 0
+                                                }
+                                              }
+                                            ]
+                                          }
+                                        }
+                                      }
+                                    }
+                                  }
+                                ],
+                                "selfClosing": true,
+                                "typeArguments": null
+                              },
+                              "children": [],
+                              "closing": null
+                            },
+                            "alternate": {
+                              "type": "NullLiteral",
+                              "span": {
+                                "start": 168,
+                                "end": 172,
+                                "ctxt": 0
+                              }
+                            }
+                          }
+                        },
+                        {
+                          "type": "JSXText",
+                          "span": {
+                            "start": 173,
+                            "end": 178,
+                            "ctxt": 0
+                          },
+                          "value": "\n\n    ",
+                          "raw": "\n\n    "
+                        }
+                      ],
+                      "closing": {
+                        "type": "JSXClosingElement",
+                        "span": {
+                          "start": 178,
+                          "end": 184,
+                          "ctxt": 0
+                        },
+                        "name": {
+                          "type": "Identifier",
+                          "span": {
+                            "start": 180,
+                            "end": 183,
+                            "ctxt": 0
+                          },
+                          "value": "div",
+                          "optional": false
+                        }
+                      }
+                    }
+                  }
+                }
+              ]
+            },
+            "async": false,
+            "generator": false,
+            "typeParameters": null,
+            "returnType": null
+          },
+          "definite": false
+        }
+      ]
+    },
+    {
+      "type": "ExportDefaultExpression",
+      "span": {
+        "start": 193,
+        "end": 223,
+        "ctxt": 0
+      },
+      "expression": {
+        "type": "Identifier",
+        "span": {
+          "start": 208,
+          "end": 222,
+          "ctxt": 0
+        },
+        "value": "getStatusLabel",
+        "optional": false
+      }
+    }
+  ],
+  "interpreter": null
+}