mirror of
https://github.com/microsoft/TypeScript.git
synced 2025-11-18 17:21:48 +00:00
Use symbol.getName for classExpression and functionExpression since it now correctly represent declared-name.
This commit is contained in:
@@ -13414,7 +13414,7 @@ namespace ts {
|
||||
case SyntaxKind.ClassExpression:
|
||||
let className = (<ClassExpression>location).name;
|
||||
if (className) {
|
||||
copySymbol(className.text, location.symbol, meaning);
|
||||
copySymbol(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
|
||||
@@ -13432,7 +13432,7 @@ namespace ts {
|
||||
case SyntaxKind.ClassExpression:
|
||||
let funcName = (<FunctionExpression>location).name;
|
||||
if (funcName) {
|
||||
copySymbol(funcName.text, location.symbol, meaning);
|
||||
copySymbol(location.symbol, meaning);
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -13451,9 +13451,12 @@ namespace ts {
|
||||
* @param symbol the symbol to be added into symbol table
|
||||
* @param meaning meaning of symbol to filter by before adding to symbol table
|
||||
*/
|
||||
function copySymbol(key: string, symbol: Symbol, meaning: SymbolFlags): void {
|
||||
function copySymbol(symbol: Symbol, meaning: SymbolFlags): void {
|
||||
if (symbol.flags & meaning) {
|
||||
let id = key || symbol.name;
|
||||
let id = symbol.name;
|
||||
// We will copy all symbol regardless of its reserved name because
|
||||
// symbolsToArray will check whether the key is a reserved name and
|
||||
// it will not copy symbol with reserved name to the array
|
||||
if (!hasProperty(symbols, id)) {
|
||||
symbols[id] = symbol;
|
||||
}
|
||||
@@ -13464,7 +13467,7 @@ namespace ts {
|
||||
if (meaning) {
|
||||
for (let id in source) {
|
||||
let symbol = source[id];
|
||||
copySymbol(symbol.name, symbol, meaning);
|
||||
copySymbol(symbol, meaning);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+16
-23
@@ -2808,30 +2808,23 @@ namespace ts {
|
||||
* @return undefined if the name is of external module otherwise a name with striped of any quote
|
||||
*/
|
||||
function getCompletionEntryDisplayNameForSymbol(symbol: Symbol, target: ScriptTarget, performCharacterChecks: boolean, location: Node): string {
|
||||
let displayName: string;
|
||||
let displayName: string = symbol.getName();
|
||||
|
||||
// In the case of default export, function expression and class expression,
|
||||
// the binder bind them with "default", "__function", "__class" respectively.
|
||||
// However, for completion entry, we want to display its declared name rather than binder name.
|
||||
if (getLocalSymbolForExportDefault(symbol) ||
|
||||
getDeclarationOfKind(symbol, SyntaxKind.FunctionExpression) ||
|
||||
getDeclarationOfKind(symbol, SyntaxKind.ClassExpression)) {
|
||||
let typeChecker = program.getTypeChecker();
|
||||
displayName = getDeclaredName(typeChecker, symbol, location);
|
||||
|
||||
// At this point, we expect that all completion list entries have declared name including function expression and class expression
|
||||
// because when we gather all relevant symbols, we check that the function expression and class expression must have declared name
|
||||
// before adding the symbol into our symbols table. (see: getSymbolsInScope)
|
||||
Debug.assert(displayName !== undefined, "Expected displayed name from declaration to existed in this symbol: " + symbol.getName());
|
||||
}
|
||||
else {
|
||||
displayName = symbol.getName();
|
||||
let firstCharCode = displayName.charCodeAt(0);
|
||||
// First check of the displayName is not external module; if it is an external module, it is not valid entry
|
||||
if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
|
||||
// If the symbol is external module, don't show it in the completion list
|
||||
// (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there)
|
||||
return undefined;
|
||||
if (displayName) {
|
||||
if (displayName === "default") {
|
||||
// In the case of default export, the binder bind them with "default".
|
||||
// However, for completion entry, we want to display its declared name rather than binder name.
|
||||
let typeChecker = program.getTypeChecker();
|
||||
displayName = getDeclaredName(typeChecker, symbol, location);
|
||||
}
|
||||
else {
|
||||
let firstCharCode = displayName.charCodeAt(0);
|
||||
// First check of the displayName is not external module; if it is an external module, it is not valid entry
|
||||
if ((symbol.flags & SymbolFlags.Namespace) && (firstCharCode === CharacterCodes.singleQuote || firstCharCode === CharacterCodes.doubleQuote)) {
|
||||
// If the symbol is external module, don't show it in the completion list
|
||||
// (i.e declare module "http" { let x; } | // <= request completion here, "http" should not be there)
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user