@@ -5694,7 +5694,7 @@ namespace Parser {
5694
5694
// Just like in parseUpdateExpression, we need to avoid parsing type assertions when
5695
5695
// in JSX and we see an expression like "+ <foo> bar".
5696
5696
if (languageVariant === LanguageVariant.JSX) {
5697
- return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true);
5697
+ return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, /*topInvalidNodePosition*/ undefined, /*openingTag*/ undefined, /*mustBeUnary*/ true );
5698
5698
}
5699
5699
// This is modified UnaryExpression grammar in TypeScript
5700
5700
// UnaryExpression (modified):
@@ -5921,7 +5921,7 @@ namespace Parser {
5921
5921
return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true)), pos);
5922
5922
}
5923
5923
5924
- function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment): JsxElement | JsxSelfClosingElement | JsxFragment {
5924
+ function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment, mustBeUnary = false ): JsxElement | JsxSelfClosingElement | JsxFragment {
5925
5925
const pos = getNodePos();
5926
5926
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
5927
5927
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
@@ -5978,7 +5978,9 @@ namespace Parser {
5978
5978
// does less damage and we can report a better error.
5979
5979
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
5980
5980
// of one sort or another.
5981
- if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
5981
+ // If we are in a unary context, we can't do this recovery; the binary expression we return here is not
5982
+ // a valid UnaryExpression and will cause problems later.
5983
+ if (!mustBeUnary && inExpressionContext && token() === SyntaxKind.LessThanToken) {
5982
5984
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
5983
5985
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
5984
5986
if (invalidElement) {
0 commit comments