mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-10 18:04:18 -05:00
Ensure we treat "type assertions" as JSX within a unary expression (#52667)
This commit is contained in:
@@ -5648,6 +5648,11 @@ namespace Parser {
|
||||
case SyntaxKind.VoidKeyword:
|
||||
return parseVoidExpression();
|
||||
case SyntaxKind.LessThanToken:
|
||||
// Just like in parseUpdateExpression, we need to avoid parsing type assertions when
|
||||
// in JSX and we see an expression like "+ <foo> bar".
|
||||
if (languageVariant === LanguageVariant.JSX) {
|
||||
return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true);
|
||||
}
|
||||
// This is modified UnaryExpression grammar in TypeScript
|
||||
// UnaryExpression (modified):
|
||||
// < type > UnaryExpression
|
||||
@@ -6163,6 +6168,7 @@ namespace Parser {
|
||||
}
|
||||
|
||||
function parseTypeAssertion(): TypeAssertion {
|
||||
Debug.assert(scriptKind === ScriptKind.TS, "Type assertions should never be parsed outside of TS; they should either be comparisons or JSX.");
|
||||
const pos = getNodePos();
|
||||
parseExpected(SyntaxKind.LessThanToken);
|
||||
const type = parseType();
|
||||
|
||||
Reference in New Issue
Block a user