Do not parse template arguments in JavaScript files. (#36673)

Fixes #36662.
This commit is contained in:
Martin Probst
2020-11-19 20:41:35 +01:00
committed by GitHub
parent 2cc67ec0a6
commit 6b04f50394
9 changed files with 69 additions and 38 deletions

View File

@@ -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;
}