@@ -21,39 +21,31 @@ namespace ts.Rename {
21
21
22
22
function getRenameInfoForNode ( node : Node , typeChecker : TypeChecker , sourceFile : SourceFile , isDefinedInLibraryFile : ( declaration : Node ) => boolean ) : RenameInfo | undefined {
23
23
const symbol = typeChecker . getSymbolAtLocation ( node ) ;
24
-
24
+ if ( ! symbol ) return ;
25
25
// Only allow a symbol to be renamed if it actually has at least one declaration.
26
- if ( symbol ) {
27
- const { declarations } = symbol ;
28
- if ( declarations && declarations . length > 0 ) {
29
- // Disallow rename for elements that are defined in the standard TypeScript library.
30
- if ( declarations . some ( isDefinedInLibraryFile ) ) {
31
- return getRenameInfoError ( Diagnostics . You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library ) ;
32
- }
33
-
34
- // Cannot rename `default` as in `import { default as foo } from "./someModule";
35
- if ( isIdentifier ( node ) && node . originalKeywordKind === SyntaxKind . DefaultKeyword && symbol . parent ! . flags & SymbolFlags . Module ) {
36
- return undefined ;
37
- }
38
-
39
- // Can't rename a module name.
40
- if ( isStringLiteralLike ( node ) && tryGetImportFromModuleSpecifier ( node ) ) return undefined ;
26
+ const { declarations } = symbol ;
27
+ if ( ! declarations || declarations . length === 0 ) return ;
41
28
42
- const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , node ) ;
43
- const specifierName = ( isImportOrExportSpecifierName ( node ) || isStringOrNumericLiteral ( node ) && node . parent . kind === SyntaxKind . ComputedPropertyName )
44
- ? stripQuotes ( getTextOfIdentifierOrLiteral ( node ) )
45
- : undefined ;
46
- const displayName = specifierName || typeChecker . symbolToString ( symbol ) ;
47
- const fullDisplayName = specifierName || typeChecker . getFullyQualifiedName ( symbol ) ;
48
- return getRenameInfoSuccess ( displayName , fullDisplayName , kind , SymbolDisplay . getSymbolModifiers ( symbol ) , node , sourceFile ) ;
49
- }
29
+ // Disallow rename for elements that are defined in the standard TypeScript library.
30
+ if ( declarations . some ( isDefinedInLibraryFile ) ) {
31
+ return getRenameInfoError ( Diagnostics . You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library ) ;
50
32
}
51
- else if ( isStringLiteral ( node ) ) {
52
- if ( isDefinedInLibraryFile ( node ) ) {
53
- return getRenameInfoError ( Diagnostics . You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library ) ;
54
- }
55
- return getRenameInfoSuccess ( node . text , node . text , ScriptElementKind . variableElement , ScriptElementKindModifier . none , node , sourceFile ) ;
33
+
34
+ // Cannot rename `default` as in `import { default as foo } from "./someModule";
35
+ if ( isIdentifier ( node ) && node . originalKeywordKind === SyntaxKind . DefaultKeyword && symbol . parent ! . flags & SymbolFlags . Module ) {
36
+ return undefined ;
56
37
}
38
+
39
+ // Can't rename a module name.
40
+ if ( isStringLiteralLike ( node ) && tryGetImportFromModuleSpecifier ( node ) ) return undefined ;
41
+
42
+ const kind = SymbolDisplay . getSymbolKind ( typeChecker , symbol , node ) ;
43
+ const specifierName = ( isImportOrExportSpecifierName ( node ) || isStringOrNumericLiteral ( node ) && node . parent . kind === SyntaxKind . ComputedPropertyName )
44
+ ? stripQuotes ( getTextOfIdentifierOrLiteral ( node ) )
45
+ : undefined ;
46
+ const displayName = specifierName || typeChecker . symbolToString ( symbol ) ;
47
+ const fullDisplayName = specifierName || typeChecker . getFullyQualifiedName ( symbol ) ;
48
+ return getRenameInfoSuccess ( displayName , fullDisplayName , kind , SymbolDisplay . getSymbolModifiers ( symbol ) , node , sourceFile ) ;
57
49
}
58
50
59
51
function getRenameInfoSuccess ( displayName : string , fullDisplayName : string , kind : ScriptElementKind , kindModifiers : string , node : Node , sourceFile : SourceFile ) : RenameInfo {
0 commit comments