@@ -5694,7 +5694,7 @@ namespace Parser {
56945694 // Just like in parseUpdateExpression, we need to avoid parsing type assertions when
56955695 // in JSX and we see an expression like "+ <foo> bar".
56965696 if (languageVariant === LanguageVariant.JSX) {
5697- return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true);
5697+ return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, /*topInvalidNodePosition*/ undefined, /*openingTag*/ undefined, /*mustBeUnary*/ true );
56985698 }
56995699 // This is modified UnaryExpression grammar in TypeScript
57005700 // UnaryExpression (modified):
@@ -5921,7 +5921,7 @@ namespace Parser {
59215921 return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true)), pos);
59225922 }
59235923
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 {
59255925 const pos = getNodePos();
59265926 const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
59275927 let result: JsxElement | JsxSelfClosingElement | JsxFragment;
@@ -5978,7 +5978,9 @@ namespace Parser {
59785978 // does less damage and we can report a better error.
59795979 // Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
59805980 // 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) {
59825984 const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
59835985 const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
59845986 if (invalidElement) {
0 commit comments