Skip to content

Commit dba80e3

Browse files
committed
Updates to prevent fourslash tests from failing.
Tests completionListInTypeParameterOfTypeAlias1 and 2 were failing before this commit. The completions.ts changes are self-explanatory but the parser.ts change is that I added semicolon as a terminator for type parameter lists. The reason is the code in the failing test looks like: ```ts type List1< type List2<T> = T[]; type List4<T> = T[]; type List3<T1> = ; ``` When type parameters were not allowed to have their own type parameters that code parsed as type `List1` with type parameters `type` and `List2`, with a missing comma between `type` and `List2`, and then the unexpected `<` from `List2<T>` was parsed as the list terminator for the assumed `List1` type parameter list. However now that type parameters are allowed to declare their own type parameter lists, the `<` from `List2<T>` is no longer unexpected so `List2<T> = T[]` is parsed as a syntactically correct definition of a type parameter `List2` that has its own type parameter `T` and a default of `T[]`. Then it ignored the unexpected semicolon and parsed the third line in exactly the same way as the second line, as additional type parameters of `List1`, with `List4<T>` defining its own child type parameter `T`. So adding semicolon as a type parameter list terminator stops the assumed `List1` type parameter list at the end of line 2.
1 parent ca237fe commit dba80e3

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

src/compiler/parser.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1609,7 +1609,8 @@ namespace ts {
16091609
return isVariableDeclaratorListTerminator();
16101610
case ParsingContext.TypeParameters:
16111611
// Tokens other than '>' are here for better error recovery
1612-
return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.OpenBraceToken || token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword;
1612+
return token() === SyntaxKind.GreaterThanToken || token() === SyntaxKind.OpenParenToken || token() === SyntaxKind.OpenBraceToken ||
1613+
token() === SyntaxKind.ExtendsKeyword || token() === SyntaxKind.ImplementsKeyword || token() === SyntaxKind.SemicolonToken;
16131614
case ParsingContext.ArgumentExpressions:
16141615
// Tokens other than ')' are here for better error recovery
16151616
return token() === SyntaxKind.CloseParenToken || token() === SyntaxKind.SemicolonToken;

src/services/completions.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1776,6 +1776,7 @@ namespace ts.Completions {
17761776
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A<T, |
17771777
containingNodeKind === SyntaxKind.ArrayBindingPattern || // var [x, y|
17781778
containingNodeKind === SyntaxKind.TypeAliasDeclaration || // type Map, K, |
1779+
containingNodeKind === SyntaxKind.TypeParameter || // <T<_T, |
17791780
// class A<T, |
17801781
// var C = class D<T, |
17811782
(isClassLike(parent) &&
@@ -1803,6 +1804,7 @@ namespace ts.Completions {
18031804
containingNodeKind === SyntaxKind.ClassExpression || // var C = class D< |
18041805
containingNodeKind === SyntaxKind.InterfaceDeclaration || // interface A< |
18051806
containingNodeKind === SyntaxKind.TypeAliasDeclaration || // type List< |
1807+
containingNodeKind === SyntaxKind.TypeParameter || // <T< |
18061808
isFunctionLikeKind(containingNodeKind);
18071809

18081810
case SyntaxKind.StaticKeyword:

0 commit comments

Comments
 (0)