@@ -5684,7 +5684,7 @@ namespace Parser {
56845684 // Just like in parseUpdateExpression, we need to avoid parsing type assertions when
56855685 // in JSX and we see an expression like "+ <foo> bar".
56865686 if (languageVariant === LanguageVariant.JSX) {
5687- return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true);
5687+ return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, /*topInvalidNodePosition*/ undefined, /*openingTag*/ undefined, /*mustBeUnary*/ true );
56885688 }
56895689 // This is modified UnaryExpression grammar in TypeScript
56905690 // UnaryExpression (modified):
@@ -5911,7 +5911,7 @@ namespace Parser {
59115911 return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true)), pos);
59125912 }
59135913
5914- function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment): JsxElement | JsxSelfClosingElement | JsxFragment {
5914+ function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment, mustBeUnary = false ): JsxElement | JsxSelfClosingElement | JsxFragment {
59155915 const pos = getNodePos();
59165916 const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
59175917 let result: JsxElement | JsxSelfClosingElement | JsxFragment;
@@ -5968,7 +5968,9 @@ namespace Parser {
59685968 // does less damage and we can report a better error.
59695969 // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
59705970 // of one sort or another.
5971- if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
5971+ // If we are in a unary context, we can't do this recovery; the binary expression we return here is not
5972+ // a valid UnaryExpression and will cause problems later.
5973+ if (!mustBeUnary && inExpressionContext && token() === SyntaxKind.LessThanToken) {
59725974 const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
59735975 const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
59745976 if (invalidElement) {
0 commit comments