mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-06-16 15:51:35 -05:00
Disable JSX recovery hack when in unary expression context (#53666)
This commit is contained in:
@@ -5694,7 +5694,7 @@ namespace Parser {
|
||||
// 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);
|
||||
return parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, /*topInvalidNodePosition*/ undefined, /*openingTag*/ undefined, /*mustBeUnary*/ true);
|
||||
}
|
||||
// This is modified UnaryExpression grammar in TypeScript
|
||||
// UnaryExpression (modified):
|
||||
@@ -5921,7 +5921,7 @@ namespace Parser {
|
||||
return finishNode(factoryCreatePropertyAccessExpression(expression, parseRightSideOfDot(/*allowIdentifierNames*/ true, /*allowPrivateIdentifiers*/ true)), pos);
|
||||
}
|
||||
|
||||
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment): JsxElement | JsxSelfClosingElement | JsxFragment {
|
||||
function parseJsxElementOrSelfClosingElementOrFragment(inExpressionContext: boolean, topInvalidNodePosition?: number, openingTag?: JsxOpeningElement | JsxOpeningFragment, mustBeUnary = false): JsxElement | JsxSelfClosingElement | JsxFragment {
|
||||
const pos = getNodePos();
|
||||
const opening = parseJsxOpeningOrSelfClosingElementOrOpeningFragment(inExpressionContext);
|
||||
let result: JsxElement | JsxSelfClosingElement | JsxFragment;
|
||||
@@ -5978,7 +5978,9 @@ namespace Parser {
|
||||
// does less damage and we can report a better error.
|
||||
// Since JSX elements are invalid < operands anyway, this lookahead parse will only occur in error scenarios
|
||||
// of one sort or another.
|
||||
if (inExpressionContext && token() === SyntaxKind.LessThanToken) {
|
||||
// If we are in a unary context, we can't do this recovery; the binary expression we return here is not
|
||||
// a valid UnaryExpression and will cause problems later.
|
||||
if (!mustBeUnary && inExpressionContext && token() === SyntaxKind.LessThanToken) {
|
||||
const topBadPos = typeof topInvalidNodePosition === "undefined" ? result.pos : topInvalidNodePosition;
|
||||
const invalidElement = tryParse(() => parseJsxElementOrSelfClosingElementOrFragment(/*inExpressionContext*/ true, topBadPos));
|
||||
if (invalidElement) {
|
||||
|
||||
Reference in New Issue
Block a user