@@ -5684,7 +5684,7 @@ namespace Parser {
5684
5684
// Just like in parseUpdateExpression, we need to avoid parsing type assertions when
5685
5685
// in JSX and we see an expression like "+ <foo> bar".
5686
5686
if (languageVariant === LanguageVariant.JSX) {
5687
- return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true);
5687
+ return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, /*topInvalidNodePosition*/ undefined, /*openingTag*/ undefined, /*mustBeUnary*/ true );
5688
5688
}
5689
5689
// This is modified UnaryExpression grammar in TypeScript
5690
5690
// UnaryExpression (modified):
@@ -5911,7 +5911,7 @@ namespace Parser {
5911
5911
return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true)), pos);
5912
5912
}
5913
5913
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 {
5915
5915
const pos = getNodePos();
5916
5916
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
5917
5917
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
@@ -5968,7 +5968,9 @@ namespace Parser {
5968
5968
// does less damage and we can report a better error.
5969
5969
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
5970
5970
// 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) {
5972
5974
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
5973
5975
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
5974
5976
if (invalidElement) {
0 commit comments