@@ -50,20 +50,8 @@ namespace ts.GoToDefinition {
50
50
// get the aliased symbol instead. This allows for goto def on an import e.g.
51
51
// import {A, B} from "mod";
52
52
// to jump to the implementation directly.
53
- if ( symbol . flags & SymbolFlags . Alias ) {
54
- const declaration = symbol . declarations [ 0 ] ;
55
-
56
- // Go to the original declaration for cases:
57
- //
58
- // (1) when the aliased symbol was declared in the location(parent).
59
- // (2) when the aliased symbol is originating from a named import.
60
- //
61
- if ( node . kind === SyntaxKind . Identifier &&
62
- ( node . parent === declaration ||
63
- ( declaration . kind === SyntaxKind . ImportSpecifier && declaration . parent && declaration . parent . kind === SyntaxKind . NamedImports ) ) ) {
64
-
65
- symbol = typeChecker . getAliasedSymbol ( symbol ) ;
66
- }
53
+ if ( symbol . flags & SymbolFlags . Alias && shouldSkipAlias ( node , symbol . declarations [ 0 ] ) ) {
54
+ symbol = typeChecker . getAliasedSymbol ( symbol ) ;
67
55
}
68
56
69
57
// Because name in short-hand property assignment has two different meanings: property name and property value,
@@ -136,6 +124,29 @@ namespace ts.GoToDefinition {
136
124
return getDefinitionFromSymbol ( typeChecker , type . symbol , node ) ;
137
125
}
138
126
127
+ // Go to the original declaration for cases:
128
+ //
129
+ // (1) when the aliased symbol was declared in the location(parent).
130
+ // (2) when the aliased symbol is originating from an import.
131
+ //
132
+ function shouldSkipAlias ( node : Node , declaration : Node ) : boolean {
133
+ if ( node . kind !== SyntaxKind . Identifier ) {
134
+ return false ;
135
+ }
136
+ if ( node . parent === declaration ) {
137
+ return true ;
138
+ }
139
+ switch ( declaration . kind ) {
140
+ case SyntaxKind . ImportClause :
141
+ case SyntaxKind . ImportEqualsDeclaration :
142
+ return true ;
143
+ case SyntaxKind . ImportSpecifier :
144
+ return declaration . parent . kind === SyntaxKind . NamedImports ;
145
+ default :
146
+ return false ;
147
+ }
148
+ }
149
+
139
150
function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node ) : DefinitionInfo [ ] {
140
151
const result : DefinitionInfo [ ] = [ ] ;
141
152
const declarations = symbol . getDeclarations ( ) ;
0 commit comments