Skip to content

Commit 73947b6

Browse files
author
Andy
authored
Minor cleanup in getRenameInfoForNode (#22130)
1 parent bb2c58b commit 73947b6

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

src/services/rename.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,19 @@ namespace ts.Rename {
2424

2525
// Only allow a symbol to be renamed if it actually has at least one declaration.
2626
if (symbol) {
27-
const declarations = symbol.getDeclarations();
27+
const { declarations } = symbol;
2828
if (declarations && declarations.length > 0) {
2929
// Disallow rename for elements that are defined in the standard TypeScript library.
30-
if (some(declarations, isDefinedInLibraryFile)) {
30+
if (declarations.some(isDefinedInLibraryFile)) {
3131
return getRenameInfoError(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library);
3232
}
3333

3434
// Cannot rename `default` as in `import { default as foo } from "./someModule";
35-
if (node.kind === SyntaxKind.Identifier &&
36-
(node as Identifier).originalKeywordKind === SyntaxKind.DefaultKeyword &&
37-
symbol.parent.flags & ts.SymbolFlags.Module) {
35+
if (isIdentifier(node) && node.originalKeywordKind === SyntaxKind.DefaultKeyword && symbol.parent.flags & SymbolFlags.Module) {
3836
return undefined;
3937
}
4038

4139
const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
42-
if (!kind) {
43-
return undefined;
44-
}
45-
4640
const specifierName = (isImportOrExportSpecifierName(node) || isStringOrNumericLiteral(node) && node.parent.kind === SyntaxKind.ComputedPropertyName)
4741
? stripQuotes(getTextOfIdentifierOrLiteral(node))
4842
: undefined;
@@ -51,13 +45,11 @@ namespace ts.Rename {
5145
return getRenameInfoSuccess(displayName, fullDisplayName, kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile);
5246
}
5347
}
54-
else if (node.kind === SyntaxKind.StringLiteral) {
48+
else if (isStringLiteral(node)) {
5549
if (isDefinedInLibraryFile(node)) {
5650
return getRenameInfoError(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library);
5751
}
58-
59-
const displayName = stripQuotes((node as StringLiteral).text);
60-
return getRenameInfoSuccess(displayName, displayName, ScriptElementKind.variableElement, ScriptElementKindModifier.none, node, sourceFile);
52+
return getRenameInfoSuccess(node.text, node.text, ScriptElementKind.variableElement, ScriptElementKindModifier.none, node, sourceFile);
6153
}
6254
}
6355

0 commit comments

Comments
 (0)