Skip to content

Commit f4cd1ac

Browse files
author
Yui T
committed
Address code review, handle type parameter in completion list inside class expression
1 parent b01e4d8 commit f4cd1ac

File tree

3 files changed

+29
-5
lines changed

3 files changed

+29
-5
lines changed

src/compiler/checker.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13371,17 +13371,27 @@ namespace ts {
1337113371
case SyntaxKind.EnumDeclaration:
1337213372
copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember);
1337313373
break;
13374+
case SyntaxKind.ClassExpression:
13375+
let className = (<ClassExpression>location).name;
13376+
if (className) {
13377+
copySymbol(className.text, location.symbol, meaning);
13378+
}
13379+
// fall through; this fall-through is necessary because we would like to handle
13380+
// type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration
1337413381
case SyntaxKind.ClassDeclaration:
1337513382
case SyntaxKind.InterfaceDeclaration:
13383+
// If we didn't come from static member of class or interface, add the type parameters into the symbol table
13384+
// (type parameters of classDeclaration/classExpression and interface are in member property of the symbol.
13385+
// jNote: that the memberFlags come from previous iteration.
1337613386
if (!(memberFlags & NodeFlags.Static)) {
1337713387
copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type);
1337813388
}
1337913389
break;
1338013390
case SyntaxKind.FunctionExpression:
1338113391
case SyntaxKind.ClassExpression:
13382-
let name = (<FunctionExpression|ClassExpression>location).name;
13383-
if (name) {
13384-
copySymbol(name.text, location.symbol, meaning);
13392+
let funcName = (<FunctionExpression>location).name;
13393+
if (funcName) {
13394+
copySymbol(funcName.text, location.symbol, meaning);
1338513395
}
1338613396
break;
1338713397
}
@@ -13396,7 +13406,7 @@ namespace ts {
1339613406
/**
1339713407
* Copy the given symbol into symbol tables if the symbol has the given meaning
1339813408
* and it doesn't already existed in the symbol table
13399-
* @param key a key for storing in symbol table; if null, use symbol.name
13409+
* @param key a key for storing in symbol table; if undefined, use symbol.name
1340013410
* @param symbol the symbol to be added into symbol table
1340113411
* @param meaning meaning of symbol to filter by before adding to symbol table
1340213412
*/

src/harness/fourslash.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2215,7 +2215,7 @@ module FourSlash {
22152215

22162216
var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n");
22172217

2218-
this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']');
2218+
this.raiseError('Expected "' + JSON.stringify({ name, text, documentation, kind }) + '" to be in list [' + itemsString + ']');
22192219
}
22202220

22212221
private findFile(indexOrName: any) {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
///<reference path="fourslash.ts" />
2+
3+
//// var x = class myClass <TypeParam> {
4+
//// getClassName (){
5+
//// /*0*/
6+
//// }
7+
//// prop: Ty/*1*/
8+
//// }
9+
10+
goTo.marker("0");
11+
verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass<TypeParam>", /*documentation*/ undefined, "type parameter");
12+
13+
goTo.marker("1");
14+
verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass<TypeParam>", /*documentation*/ undefined, "type parameter");

0 commit comments

Comments
 (0)