diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 171b6eb1837..ca7df8d9810 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -13371,17 +13371,27 @@ namespace ts { case SyntaxKind.EnumDeclaration: copySymbols(getSymbolOfNode(location).exports, meaning & SymbolFlags.EnumMember); break; + case SyntaxKind.ClassExpression: + let className = (location).name; + if (className) { + copySymbol(className.text, location.symbol, meaning); + } + // fall through; this fall-through is necessary because we would like to handle + // type parameter inside class expression similar to how we handle it in classDeclaration and interface Declaration case SyntaxKind.ClassDeclaration: case SyntaxKind.InterfaceDeclaration: + // If we didn't come from static member of class or interface, add the type parameters into the symbol table + // (type parameters of classDeclaration/classExpression and interface are in member property of the symbol. + // jNote: that the memberFlags come from previous iteration. if (!(memberFlags & NodeFlags.Static)) { copySymbols(getSymbolOfNode(location).members, meaning & SymbolFlags.Type); } break; case SyntaxKind.FunctionExpression: case SyntaxKind.ClassExpression: - let name = (location).name; - if (name) { - copySymbol(name.text, location.symbol, meaning); + let funcName = (location).name; + if (funcName) { + copySymbol(funcName.text, location.symbol, meaning); } break; } @@ -13396,7 +13406,7 @@ namespace ts { /** * Copy the given symbol into symbol tables if the symbol has the given meaning * and it doesn't already existed in the symbol table - * @param key a key for storing in symbol table; if null, use symbol.name + * @param key a key for storing in symbol table; if undefined, use symbol.name * @param symbol the symbol to be added into symbol table * @param meaning meaning of symbol to filter by before adding to symbol table */ diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index 2454ebb26c9..475a73ccd7c 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2215,7 +2215,7 @@ module FourSlash { var itemsString = items.map((item) => JSON.stringify({ name: item.name, kind: item.kind })).join(",\n"); - this.raiseError('Expected "' + JSON.stringify({ name: name, text: text, documentation: documentation, kind: kind }) + '" to be in list [' + itemsString + ']'); + this.raiseError('Expected "' + JSON.stringify({ name, text, documentation, kind }) + '" to be in list [' + itemsString + ']'); } private findFile(indexOrName: any) { diff --git a/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts new file mode 100644 index 00000000000..6f016b73a76 --- /dev/null +++ b/tests/cases/fourslash/completionListInClassExpressionWithTypeParameter.ts @@ -0,0 +1,14 @@ +/// + +//// var x = class myClass { +//// getClassName (){ +//// /*0*/ +//// } +//// prop: Ty/*1*/ +//// } + +goTo.marker("0"); +verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); + +goTo.marker("1"); +verify.completionListContains("TypeParam", "(type parameter) TypeParam in myClass", /*documentation*/ undefined, "type parameter"); \ No newline at end of file