Correct fullDisplayName returned from rename

The regular displayName had special handling for `as` clauses in imports
and exports but the fullDisplayName did not.  They should be consistent.

(The impact of this change is very minor - it only affects the root node
of the tree control in the rename preview, which is off by default.)

Bonus: Eliminate `getDeclaredName` which is only called by rename.

Note: Special handling of default exports was not preserved since
`default` cannot be renamed.
This commit is contained in:
Andrew Casey 2018-01-04 11:13:03 -08:00
parent f0d9cb3fbf
commit 50e3044ed2
2 changed files with 10 additions and 15 deletions

View file

@ -38,9 +38,17 @@ namespace ts.Rename {
return undefined;
}
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
return kind ? getRenameInfoSuccess(displayName, typeChecker.getFullyQualifiedName(symbol), kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile) : undefined;
if (!kind) {
return undefined;
}
const specifierName = (isImportOrExportSpecifierName(node) || isStringOrNumericLiteral(node) && node.parent.kind === SyntaxKind.ComputedPropertyName)
? stripQuotes(getTextOfIdentifierOrLiteral(node))
: undefined;
const displayName = specifierName || typeChecker.symbolToString(symbol);
const fullDisplayName = specifierName || typeChecker.getFullyQualifiedName(symbol);
return getRenameInfoSuccess(displayName, fullDisplayName, kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile);
}
}
else if (node.kind === SyntaxKind.StringLiteral) {

View file

@ -1278,19 +1278,6 @@ namespace ts {
});
}
export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node): string {
// If this is an export or import specifier it could have been renamed using the 'as' syntax.
// If so we want to search for whatever is under the cursor.
if (isImportOrExportSpecifierName(location) || isStringOrNumericLiteral(location) && location.parent.kind === SyntaxKind.ComputedPropertyName) {
return getTextOfIdentifierOrLiteral(location);
}
// Try to get the local symbol if we're dealing with an 'export default'
// since that symbol has the "true" name.
const localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
return typeChecker.symbolToString(localExportDefaultSymbol || symbol);
}
export function isImportOrExportSpecifierName(location: Node): location is Identifier {
return location.parent &&
(location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) &&