mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-05-15 21:36:50 -05:00
Do not parse template arguments in JavaScript files. (#36673)
Fixes #36662.
This commit is contained in:
@@ -4909,7 +4909,7 @@ namespace ts {
|
||||
}
|
||||
|
||||
const tagName = parseJsxElementName();
|
||||
const typeArguments = tryParseTypeArguments();
|
||||
const typeArguments = (contextFlags & NodeFlags.JavaScriptFile) === 0 ? tryParseTypeArguments() : undefined;
|
||||
const attributes = parseJsxAttributes();
|
||||
|
||||
let node: JsxOpeningLikeElement;
|
||||
@@ -5174,7 +5174,8 @@ namespace ts {
|
||||
expression = parseMemberExpressionRest(pos, expression, /*allowOptionalChain*/ true);
|
||||
const questionDotToken = parseOptionalToken(SyntaxKind.QuestionDotToken);
|
||||
// handle 'foo<<T>()'
|
||||
if (token() === SyntaxKind.LessThanToken || token() === SyntaxKind.LessThanLessThanToken) {
|
||||
// parse template arguments only in TypeScript files (not in JavaScript files).
|
||||
if ((contextFlags & NodeFlags.JavaScriptFile) === 0 && (token() === SyntaxKind.LessThanToken || token() === SyntaxKind.LessThanLessThanToken)) {
|
||||
// See if this is the start of a generic invocation. If so, consume it and
|
||||
// keep checking for postfix expressions. Otherwise, it's just a '<' that's
|
||||
// part of an arithmetic expression. Break out so we consume it higher in the
|
||||
@@ -5220,6 +5221,11 @@ namespace ts {
|
||||
}
|
||||
|
||||
function parseTypeArgumentsInExpression() {
|
||||
if ((contextFlags & NodeFlags.JavaScriptFile) !== 0) {
|
||||
// TypeArguments must not be parsed in JavaScript files to avoid ambiguity with binary operators.
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (reScanLessThanToken() !== SyntaxKind.LessThanToken) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user