Skip to content

Commit 50e3044

Browse files
committed
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.
1 parent f0d9cb3 commit 50e3044

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/services/rename.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,17 @@ namespace ts.Rename {
3838
return undefined;
3939
}
4040

41-
const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node));
4241
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
43-
return kind ? getRenameInfoSuccess(displayName, typeChecker.getFullyQualifiedName(symbol), kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile) : undefined;
42+
if (!kind) {
43+
return undefined;
44+
}
45+
46+
const specifierName = (isImportOrExportSpecifierName(node) || isStringOrNumericLiteral(node) && node.parent.kind === SyntaxKind.ComputedPropertyName)
47+
? stripQuotes(getTextOfIdentifierOrLiteral(node))
48+
: undefined;
49+
const displayName = specifierName || typeChecker.symbolToString(symbol);
50+
const fullDisplayName = specifierName || typeChecker.getFullyQualifiedName(symbol);
51+
return getRenameInfoSuccess(displayName, fullDisplayName, kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile);
4452
}
4553
}
4654
else if (node.kind === SyntaxKind.StringLiteral) {

src/services/utilities.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,19 +1278,6 @@ namespace ts {
12781278
});
12791279
}
12801280

1281-
export function getDeclaredName(typeChecker: TypeChecker, symbol: Symbol, location: Node): string {
1282-
// If this is an export or import specifier it could have been renamed using the 'as' syntax.
1283-
// If so we want to search for whatever is under the cursor.
1284-
if (isImportOrExportSpecifierName(location) || isStringOrNumericLiteral(location) && location.parent.kind === SyntaxKind.ComputedPropertyName) {
1285-
return getTextOfIdentifierOrLiteral(location);
1286-
}
1287-
1288-
// Try to get the local symbol if we're dealing with an 'export default'
1289-
// since that symbol has the "true" name.
1290-
const localExportDefaultSymbol = getLocalSymbolForExportDefault(symbol);
1291-
return typeChecker.symbolToString(localExportDefaultSymbol || symbol);
1292-
}
1293-
12941281
export function isImportOrExportSpecifierName(location: Node): location is Identifier {
12951282
return location.parent &&
12961283
(location.parent.kind === SyntaxKind.ImportSpecifier || location.parent.kind === SyntaxKind.ExportSpecifier) &&

0 commit comments

Comments
 (0)