11/* @internal */
22namespace ts . GoToDefinition {
3- export function getDefinitionAtPosition ( program : Program , sourceFile : SourceFile , position : number , searchOtherFilesOnly ?: boolean ) : readonly DefinitionInfo [ ] | undefined {
3+ export function getDefinitionAtPosition ( program : Program , sourceFile : SourceFile , position : number , searchOtherFilesOnly ?: boolean , stopAtAlias ?: boolean ) : readonly DefinitionInfo [ ] | undefined {
44 const resolvedRef = getReferenceAtPosition ( sourceFile , position , program ) ;
55 const fileReferenceDefinition = resolvedRef && [ getDefinitionInfoForFileReference ( resolvedRef . reference . fileName , resolvedRef . fileName , resolvedRef . unverified ) ] || emptyArray ;
66 if ( resolvedRef ?. file ) {
@@ -28,7 +28,7 @@ namespace ts.GoToDefinition {
2828
2929 if ( isStaticModifier ( node ) && isClassStaticBlockDeclaration ( node . parent ) ) {
3030 const classDecl = node . parent . parent ;
31- const { symbol, failedAliasResolution } = getSymbol ( classDecl , typeChecker ) ;
31+ const { symbol, failedAliasResolution } = getSymbol ( classDecl , typeChecker , stopAtAlias ) ;
3232
3333 const staticBlocks = filter ( classDecl . members , isClassStaticBlockDeclaration ) ;
3434 const containerName = symbol ? typeChecker . symbolToString ( symbol , classDecl ) : "" ;
@@ -40,15 +40,15 @@ namespace ts.GoToDefinition {
4040 } ) ;
4141 }
4242
43- let { symbol, failedAliasResolution } = getSymbol ( node , typeChecker ) ;
43+ let { symbol, failedAliasResolution } = getSymbol ( node , typeChecker , stopAtAlias ) ;
4444 let fallbackNode = node ;
4545
4646 if ( searchOtherFilesOnly && failedAliasResolution ) {
4747 // We couldn't resolve the specific import, try on the module specifier.
4848 const importDeclaration = forEach ( [ node , ...symbol ?. declarations || emptyArray ] , n => findAncestor ( n , isAnyImportOrBareOrAccessedRequire ) ) ;
4949 const moduleSpecifier = importDeclaration && tryGetModuleSpecifierFromDeclaration ( importDeclaration ) ;
5050 if ( moduleSpecifier ) {
51- ( { symbol, failedAliasResolution } = getSymbol ( moduleSpecifier , typeChecker ) ) ;
51+ ( { symbol, failedAliasResolution } = getSymbol ( moduleSpecifier , typeChecker , stopAtAlias ) ) ;
5252 fallbackNode = moduleSpecifier ;
5353 }
5454 }
@@ -235,7 +235,7 @@ namespace ts.GoToDefinition {
235235 return definitionFromType ( typeChecker . getTypeAtLocation ( node . parent ) , typeChecker , node . parent , /*failedAliasResolution*/ false ) ;
236236 }
237237
238- const { symbol, failedAliasResolution } = getSymbol ( node , typeChecker ) ;
238+ const { symbol, failedAliasResolution } = getSymbol ( node , typeChecker , /*stopAtAlias*/ false ) ;
239239 if ( ! symbol ) return undefined ;
240240
241241 const typeAtLocation = typeChecker . getTypeOfSymbolAtLocation ( symbol , node ) ;
@@ -292,14 +292,14 @@ namespace ts.GoToDefinition {
292292 return mapDefined ( checker . getIndexInfosAtLocation ( node ) , info => info . declaration && createDefinitionFromSignatureDeclaration ( checker , info . declaration ) ) ;
293293 }
294294
295- function getSymbol ( node : Node , checker : TypeChecker ) {
295+ function getSymbol ( node : Node , checker : TypeChecker , stopAtAlias : boolean | undefined ) {
296296 const symbol = checker . getSymbolAtLocation ( node ) ;
297297 // If this is an alias, and the request came at the declaration location
298298 // get the aliased symbol instead. This allows for goto def on an import e.g.
299299 // import {A, B} from "mod";
300300 // to jump to the implementation directly.
301301 let failedAliasResolution = false ;
302- if ( symbol ?. declarations && symbol . flags & SymbolFlags . Alias && shouldSkipAlias ( node , symbol . declarations [ 0 ] ) ) {
302+ if ( symbol ?. declarations && symbol . flags & SymbolFlags . Alias && ! stopAtAlias && shouldSkipAlias ( node , symbol . declarations [ 0 ] ) ) {
303303 const aliased = checker . getAliasedSymbol ( symbol ) ;
304304 if ( aliased . declarations ) {
305305 return { symbol : aliased } ;
0 commit comments