@@ -24,25 +24,19 @@ namespace ts.Rename {
24
24
25
25
// Only allow a symbol to be renamed if it actually has at least one declaration.
26
26
if ( symbol ) {
27
- const declarations = symbol . getDeclarations ( ) ;
27
+ const { declarations } = symbol ;
28
28
if ( declarations && declarations . length > 0 ) {
29
29
// Disallow rename for elements that are defined in the standard TypeScript library.
30
- if ( some ( declarations , isDefinedInLibraryFile ) ) {
30
+ if ( declarations . some ( isDefinedInLibraryFile ) ) {
31
31
return getRenameInfoError ( Diagnostics . You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library ) ;
32
32
}
33
33
34
34
// 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 ) {
38
36
return undefined ;
39
37
}
40
38
41
39
const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , node ) ;
42
- if ( ! kind ) {
43
- return undefined ;
44
- }
45
-
46
40
const specifierName = ( isImportOrExportSpecifierName ( node ) || isStringOrNumericLiteral ( node ) && node . parent . kind === SyntaxKind . ComputedPropertyName )
47
41
? stripQuotes ( getTextOfIdentifierOrLiteral ( node ) )
48
42
: undefined ;
@@ -51,13 +45,11 @@ namespace ts.Rename {
51
45
return getRenameInfoSuccess ( displayName , fullDisplayName , kind , SymbolDisplay . getSymbolModifiers ( symbol ) , node , sourceFile ) ;
52
46
}
53
47
}
54
- else if ( node . kind === SyntaxKind . StringLiteral ) {
48
+ else if ( isStringLiteral ( node ) ) {
55
49
if ( isDefinedInLibraryFile ( node ) ) {
56
50
return getRenameInfoError ( Diagnostics . You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library ) ;
57
51
}
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 ) ;
61
53
}
62
54
}
63
55
0 commit comments