Skip to content

Commit 919b36f

Browse files
committed
Instantiation expressions followed by line breaks or binary operators
1 parent e8df098 commit 919b36f

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/compiler/parser.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5732,20 +5732,18 @@ namespace ts {
57325732
case SyntaxKind.NoSubstitutionTemplateLiteral: // foo<T> `...`
57335733
case SyntaxKind.TemplateHead: // foo<T> `...${100}...`
57345734
return true;
5735-
// Technically strict mode reserved words are valid identifiers in non-strict mode, and can thus
5736-
// start an expression. However, when they follow a type argument list and are immediately
5737-
// preceded by a line break, we don't consider them expression starters.
5738-
// This supports a semicolon-less style for code like the following:
5739-
//
5740-
// let specialFoo = foo<string>
5741-
// let value = ...
5742-
//
5743-
case SyntaxKind.InterfaceKeyword:
5744-
case SyntaxKind.LetKeyword:
5745-
return scanner.hasPrecedingLineBreak();
5735+
// A type argument list followed by `<` never makes sense, and a type argument list followed
5736+
// by `>` is ambiguous with a (re-scanned) `>>` operator, so we disqualify both.
5737+
case SyntaxKind.LessThanToken:
5738+
case SyntaxKind.GreaterThanToken:
5739+
// In this context, `+` and `-` are unary operators, not binary operators.
5740+
case SyntaxKind.PlusToken:
5741+
case SyntaxKind.MinusToken:
5742+
return false;
57465743
}
5747-
// Consider something a type argument list only if the following token can't start an expression.
5748-
return !isStartOfExpression();
5744+
// We favor the type argument list interpretation when it is immediately followed by
5745+
// a line break, a binary operator, or something that can't start an expression.
5746+
return scanner.hasPrecedingLineBreak() || isBinaryOperator() || !isStartOfExpression();
57495747
}
57505748

57515749
function parsePrimaryExpression(): PrimaryExpression {

0 commit comments

Comments
 (0)