@@ -28,28 +28,27 @@ namespace ts.GoToDefinition {
28
28
29
29
if ( isStaticModifier ( node ) && isClassStaticBlockDeclaration ( node . parent ) ) {
30
30
const classDecl = node . parent . parent ;
31
- const { symbol, isAliasTarget, failedAliasResolution } = getSymbol ( classDecl , typeChecker ) ;
32
- if ( aliasesOnly && ! isAliasTarget ) return undefined ;
31
+ const { symbol, failedAliasResolution } = getSymbol ( classDecl , typeChecker ) ;
33
32
34
33
const staticBlocks = filter ( classDecl . members , isClassStaticBlockDeclaration ) ;
35
34
const containerName = symbol ? typeChecker . symbolToString ( symbol , classDecl ) : "" ;
36
35
const sourceFile = node . getSourceFile ( ) ;
37
36
return map ( staticBlocks , staticBlock => {
38
37
let { pos } = moveRangePastModifiers ( staticBlock ) ;
39
38
pos = skipTrivia ( sourceFile . text , pos ) ;
40
- return createDefinitionInfoFromName ( typeChecker , staticBlock , ScriptElementKind . constructorImplementationElement , "static {}" , containerName , isAliasTarget , failedAliasResolution , { start : pos , length : "static" . length } ) ;
39
+ return createDefinitionInfoFromName ( typeChecker , staticBlock , ScriptElementKind . constructorImplementationElement , "static {}" , containerName , failedAliasResolution , { start : pos , length : "static" . length } ) ;
41
40
} ) ;
42
41
}
43
42
44
- let { symbol, isAliasTarget , failedAliasResolution } = getSymbol ( node , typeChecker ) ;
43
+ let { symbol, failedAliasResolution } = getSymbol ( node , typeChecker ) ;
45
44
let fallbackNode = node ;
46
45
47
46
if ( aliasesOnly && failedAliasResolution ) {
48
47
// We couldn't resolve the specific import, try on the module specifier.
49
48
const importDeclaration = findAncestor ( node , isAnyImportOrBareOrAccessedRequire ) ;
50
49
const moduleSpecifier = importDeclaration && tryGetModuleSpecifierFromDeclaration ( importDeclaration ) ;
51
50
if ( moduleSpecifier ) {
52
- ( { symbol, isAliasTarget , failedAliasResolution } = getSymbol ( moduleSpecifier , typeChecker ) ) ;
51
+ ( { symbol, failedAliasResolution } = getSymbol ( moduleSpecifier , typeChecker ) ) ;
53
52
fallbackNode = moduleSpecifier ;
54
53
}
55
54
}
@@ -66,33 +65,32 @@ namespace ts.GoToDefinition {
66
65
containerKind : undefined ! ,
67
66
kind : ScriptElementKind . scriptElement ,
68
67
textSpan : createTextSpan ( 0 , 0 ) ,
69
- isAliasTarget : true ,
70
68
failedAliasResolution,
71
69
isAmbient : isDeclarationFileName ( ref . resolvedFileName ) ,
72
70
unverified : fallbackNode !== node ,
73
71
} ] ;
74
72
}
75
73
}
76
74
77
- if ( aliasesOnly && ! isAliasTarget ) return undefined ;
78
-
79
75
// Could not find a symbol e.g. node is string or number keyword,
80
76
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
81
77
if ( ! symbol ) {
82
78
return concatenate ( fileReferenceDefinition , getDefinitionInfoForIndexSignatures ( node , typeChecker ) ) ;
83
79
}
84
80
81
+ if ( aliasesOnly && every ( symbol . declarations , d => d . getSourceFile ( ) . fileName === sourceFile . fileName ) ) return undefined ;
82
+
85
83
const calledDeclaration = tryGetSignatureDeclaration ( typeChecker , node ) ;
86
84
// Don't go to the component constructor definition for a JSX element, just go to the component definition.
87
85
if ( calledDeclaration && ! ( isJsxOpeningLikeElement ( node . parent ) && isConstructorLike ( calledDeclaration ) ) ) {
88
- const sigInfo = createDefinitionFromSignatureDeclaration ( typeChecker , calledDeclaration , isAliasTarget , failedAliasResolution ) ;
86
+ const sigInfo = createDefinitionFromSignatureDeclaration ( typeChecker , calledDeclaration , failedAliasResolution ) ;
89
87
// For a function, if this is the original function definition, return just sigInfo.
90
88
// If this is the original constructor definition, parent is the class.
91
89
if ( typeChecker . getRootSymbols ( symbol ) . some ( s => symbolMatchesSignature ( s , calledDeclaration ) ) ) {
92
90
return [ sigInfo ] ;
93
91
}
94
92
else {
95
- const defs = getDefinitionFromSymbol ( typeChecker , symbol , node , isAliasTarget , failedAliasResolution , calledDeclaration ) || emptyArray ;
93
+ const defs = getDefinitionFromSymbol ( typeChecker , symbol , node , failedAliasResolution , calledDeclaration ) || emptyArray ;
96
94
// For a 'super()' call, put the signature first, else put the variable first.
97
95
return node . kind === SyntaxKind . SuperKeyword ? [ sigInfo , ...defs ] : [ ...defs , sigInfo ] ;
98
96
}
@@ -105,7 +103,7 @@ namespace ts.GoToDefinition {
105
103
// assignment. This case and others are handled by the following code.
106
104
if ( node . parent . kind === SyntaxKind . ShorthandPropertyAssignment ) {
107
105
const shorthandSymbol = typeChecker . getShorthandAssignmentValueSymbol ( symbol . valueDeclaration ) ;
108
- const definitions = shorthandSymbol ?. declarations ? shorthandSymbol . declarations . map ( decl => createDefinitionInfo ( decl , typeChecker , shorthandSymbol , node , isAliasTarget , failedAliasResolution ) ) : emptyArray ;
106
+ const definitions = shorthandSymbol ?. declarations ? shorthandSymbol . declarations . map ( decl => createDefinitionInfo ( decl , typeChecker , shorthandSymbol , node , failedAliasResolution ) ) : emptyArray ;
109
107
return concatenate ( definitions , getDefinitionFromObjectLiteralElement ( typeChecker , node ) || emptyArray ) ;
110
108
}
111
109
@@ -130,7 +128,7 @@ namespace ts.GoToDefinition {
130
128
} ) ;
131
129
}
132
130
133
- return concatenate ( fileReferenceDefinition , getDefinitionFromObjectLiteralElement ( typeChecker , node ) || getDefinitionFromSymbol ( typeChecker , symbol , node , isAliasTarget , failedAliasResolution ) ) ;
131
+ return concatenate ( fileReferenceDefinition , getDefinitionFromObjectLiteralElement ( typeChecker , node ) || getDefinitionFromSymbol ( typeChecker , symbol , node , failedAliasResolution ) ) ;
134
132
}
135
133
136
134
/**
@@ -234,25 +232,25 @@ namespace ts.GoToDefinition {
234
232
}
235
233
236
234
if ( isImportMeta ( node . parent ) && node . parent . name === node ) {
237
- return definitionFromType ( typeChecker . getTypeAtLocation ( node . parent ) , typeChecker , node . parent , /*isAliasTarget*/ false , /* failedAliasResolution*/ false ) ;
235
+ return definitionFromType ( typeChecker . getTypeAtLocation ( node . parent ) , typeChecker , node . parent , /*failedAliasResolution*/ false ) ;
238
236
}
239
237
240
- const { symbol, isAliasTarget , failedAliasResolution } = getSymbol ( node , typeChecker ) ;
238
+ const { symbol, failedAliasResolution } = getSymbol ( node , typeChecker ) ;
241
239
if ( ! symbol ) return undefined ;
242
240
243
241
const typeAtLocation = typeChecker . getTypeOfSymbolAtLocation ( symbol , node ) ;
244
242
const returnType = tryGetReturnTypeOfFunction ( symbol , typeAtLocation , typeChecker ) ;
245
- const fromReturnType = returnType && definitionFromType ( returnType , typeChecker , node , isAliasTarget , failedAliasResolution ) ;
243
+ const fromReturnType = returnType && definitionFromType ( returnType , typeChecker , node , failedAliasResolution ) ;
246
244
// If a function returns 'void' or some other type with no definition, just return the function definition.
247
- const typeDefinitions = fromReturnType && fromReturnType . length !== 0 ? fromReturnType : definitionFromType ( typeAtLocation , typeChecker , node , isAliasTarget , failedAliasResolution ) ;
245
+ const typeDefinitions = fromReturnType && fromReturnType . length !== 0 ? fromReturnType : definitionFromType ( typeAtLocation , typeChecker , node , failedAliasResolution ) ;
248
246
return typeDefinitions . length ? typeDefinitions
249
- : ! ( symbol . flags & SymbolFlags . Value ) && symbol . flags & SymbolFlags . Type ? getDefinitionFromSymbol ( typeChecker , skipAlias ( symbol , typeChecker ) , node , isAliasTarget , failedAliasResolution )
247
+ : ! ( symbol . flags & SymbolFlags . Value ) && symbol . flags & SymbolFlags . Type ? getDefinitionFromSymbol ( typeChecker , skipAlias ( symbol , typeChecker ) , node , failedAliasResolution )
250
248
: undefined ;
251
249
}
252
250
253
- function definitionFromType ( type : Type , checker : TypeChecker , node : Node , isAliasTarget : boolean , failedAliasResolution : boolean | undefined ) : readonly DefinitionInfo [ ] {
251
+ function definitionFromType ( type : Type , checker : TypeChecker , node : Node , failedAliasResolution : boolean | undefined ) : readonly DefinitionInfo [ ] {
254
252
return flatMap ( type . isUnion ( ) && ! ( type . flags & TypeFlags . Enum ) ? type . types : [ type ] , t =>
255
- t . symbol && getDefinitionFromSymbol ( checker , t . symbol , node , isAliasTarget , failedAliasResolution ) ) ;
253
+ t . symbol && getDefinitionFromSymbol ( checker , t . symbol , node , failedAliasResolution ) ) ;
256
254
}
257
255
258
256
function tryGetReturnTypeOfFunction ( symbol : Symbol , type : Type , checker : TypeChecker ) : Type | undefined {
@@ -304,13 +302,13 @@ namespace ts.GoToDefinition {
304
302
if ( symbol ?. declarations && symbol . flags & SymbolFlags . Alias && shouldSkipAlias ( node , symbol . declarations [ 0 ] ) ) {
305
303
const aliased = checker . getAliasedSymbol ( symbol ) ;
306
304
if ( aliased . declarations ) {
307
- return { symbol : aliased , isAliasTarget : true } ;
305
+ return { symbol : aliased } ;
308
306
}
309
307
else {
310
308
failedAliasResolution = true ;
311
309
}
312
310
}
313
- return { symbol, isAliasTarget : ! ! ( symbol && isExternalModuleSymbol ( symbol ) ) , failedAliasResolution } ;
311
+ return { symbol, failedAliasResolution } ;
314
312
}
315
313
316
314
// Go to the original declaration for cases:
@@ -358,11 +356,11 @@ namespace ts.GoToDefinition {
358
356
return ! ! containingAssignment && getAssignmentDeclarationKind ( containingAssignment ) === AssignmentDeclarationKind . Property ;
359
357
}
360
358
361
- function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node , isAliasTarget ?: boolean , failedAliasResolution ?: boolean , excludeDeclaration ?: Node ) : DefinitionInfo [ ] | undefined {
359
+ function getDefinitionFromSymbol ( typeChecker : TypeChecker , symbol : Symbol , node : Node , failedAliasResolution ?: boolean , excludeDeclaration ?: Node ) : DefinitionInfo [ ] | undefined {
362
360
const filteredDeclarations = filter ( symbol . declarations , d => d !== excludeDeclaration ) ;
363
361
const withoutExpandos = filter ( filteredDeclarations , d => ! isExpandoDeclaration ( d ) ) ;
364
362
const results = some ( withoutExpandos ) ? withoutExpandos : filteredDeclarations ;
365
- return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( results , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node , isAliasTarget , failedAliasResolution ) ) ;
363
+ return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( results , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node , failedAliasResolution ) ) ;
366
364
367
365
function getConstructSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
368
366
// Applicable only if we are in a new expression, or we are on a constructor declaration
@@ -390,21 +388,21 @@ namespace ts.GoToDefinition {
390
388
return declarations . length
391
389
? declarationsWithBody . length !== 0
392
390
? declarationsWithBody . map ( x => createDefinitionInfo ( x , typeChecker , symbol , node ) )
393
- : [ createDefinitionInfo ( last ( declarations ) , typeChecker , symbol , node , isAliasTarget , failedAliasResolution ) ]
391
+ : [ createDefinitionInfo ( last ( declarations ) , typeChecker , symbol , node , failedAliasResolution ) ]
394
392
: undefined ;
395
393
}
396
394
}
397
395
398
396
/** Creates a DefinitionInfo from a Declaration, using the declaration's name if possible. */
399
- export function createDefinitionInfo ( declaration : Declaration , checker : TypeChecker , symbol : Symbol , node : Node , isAliasTarget ?: boolean , failedAliasResolution ?: boolean ) : DefinitionInfo {
397
+ export function createDefinitionInfo ( declaration : Declaration , checker : TypeChecker , symbol : Symbol , node : Node , failedAliasResolution ?: boolean ) : DefinitionInfo {
400
398
const symbolName = checker . symbolToString ( symbol ) ; // Do not get scoped name, just the name of the symbol
401
399
const symbolKind = SymbolDisplay . getSymbolKind ( checker , symbol , node ) ;
402
400
const containerName = symbol . parent ? checker . symbolToString ( symbol . parent , node ) : "" ;
403
- return createDefinitionInfoFromName ( checker , declaration , symbolKind , symbolName , containerName , isAliasTarget , failedAliasResolution ) ;
401
+ return createDefinitionInfoFromName ( checker , declaration , symbolKind , symbolName , containerName , failedAliasResolution ) ;
404
402
}
405
403
406
404
/** Creates a DefinitionInfo directly from the name of a declaration. */
407
- function createDefinitionInfoFromName ( checker : TypeChecker , declaration : Declaration , symbolKind : ScriptElementKind , symbolName : string , containerName : string , isAliasTarget ?: boolean , failedAliasResolution ?: boolean , textSpan ?: TextSpan ) : DefinitionInfo {
405
+ function createDefinitionInfoFromName ( checker : TypeChecker , declaration : Declaration , symbolKind : ScriptElementKind , symbolName : string , containerName : string , failedAliasResolution ?: boolean , textSpan ?: TextSpan ) : DefinitionInfo {
408
406
const sourceFile = declaration . getSourceFile ( ) ;
409
407
if ( ! textSpan ) {
410
408
const name = getNameOfDeclaration ( declaration ) || declaration ;
@@ -424,7 +422,6 @@ namespace ts.GoToDefinition {
424
422
) ,
425
423
isLocal : ! isDefinitionVisible ( checker , declaration ) ,
426
424
isAmbient : ! ! ( declaration . flags & NodeFlags . Ambient ) ,
427
- isAliasTarget,
428
425
failedAliasResolution,
429
426
} ;
430
427
}
@@ -460,8 +457,8 @@ namespace ts.GoToDefinition {
460
457
}
461
458
}
462
459
463
- function createDefinitionFromSignatureDeclaration ( typeChecker : TypeChecker , decl : SignatureDeclaration , isAliasTarget ?: boolean , failedAliasResolution ?: boolean ) : DefinitionInfo {
464
- return createDefinitionInfo ( decl , typeChecker , decl . symbol , decl , isAliasTarget , failedAliasResolution ) ;
460
+ function createDefinitionFromSignatureDeclaration ( typeChecker : TypeChecker , decl : SignatureDeclaration , failedAliasResolution ?: boolean ) : DefinitionInfo {
461
+ return createDefinitionInfo ( decl , typeChecker , decl . symbol , decl , failedAliasResolution ) ;
465
462
}
466
463
467
464
export function findReferenceInPosition ( refs : readonly FileReference [ ] , pos : number ) : FileReference | undefined {
@@ -477,7 +474,6 @@ namespace ts.GoToDefinition {
477
474
containerName : undefined ! ,
478
475
containerKind : undefined ! , // TODO: GH#18217
479
476
unverified,
480
- isAliasTarget : true ,
481
477
} ;
482
478
}
483
479
0 commit comments