Ensure we treat "type assertions" as JSX within a unary expression (#52667)

This commit is contained in:
Jake Bailey
2023-02-09 11:34:47 -08:00
committed by GitHub
parent bec0fdac23
commit 0ef9e8eac9
18 changed files with 207 additions and 0 deletions

View File

@@ -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();