@@ -100,10 +100,13 @@ namespace ts.GoToDefinition {
100
100
/**
101
101
* True if we should not add definitions for both the signature symbol and the definition symbol.
102
102
* True for `const |f = |() => 0`, false for `function |f() {} const |g = f;`.
103
+ * Also true for any assignment RHS.
103
104
*/
104
105
function symbolMatchesSignature ( s : Symbol , calledDeclaration : SignatureDeclaration ) {
105
- return s === calledDeclaration . symbol || s === calledDeclaration . symbol . parent ||
106
- ! isCallLikeExpression ( calledDeclaration . parent ) && s === calledDeclaration . parent . symbol ;
106
+ return s === calledDeclaration . symbol
107
+ || s === calledDeclaration . symbol . parent
108
+ || isAssignmentExpression ( calledDeclaration . parent )
109
+ || ( ! isCallLikeExpression ( calledDeclaration . parent ) && s === calledDeclaration . parent . symbol ) ;
107
110
}
108
111
109
112
export function getReferenceAtPosition ( sourceFile : SourceFile , position : number , program : Program ) : { fileName : string , file : SourceFile } | undefined {
@@ -246,7 +249,9 @@ namespace ts.GoToDefinition {
246
249
// There are cases when you extend a function by adding properties to it afterwards,
247
250
// we want to strip those extra properties.
248
251
// For deduping purposes, we also want to exclude any declarationNodes if provided.
249
- const filteredDeclarations = filter ( symbol . declarations , d => d !== declarationNode && ( ! isAssignmentDeclaration ( d ) || d === symbol . valueDeclaration ) ) || undefined ;
252
+ const filteredDeclarations =
253
+ filter ( symbol . declarations , d => d !== declarationNode && ( ! isAssignmentDeclaration ( d ) || d === symbol . valueDeclaration ) )
254
+ || undefined ;
250
255
return getConstructSignatureDefinition ( ) || getCallSignatureDefinition ( ) || map ( filteredDeclarations , declaration => createDefinitionInfo ( declaration , typeChecker , symbol , node ) ) ;
251
256
252
257
function getConstructSignatureDefinition ( ) : DefinitionInfo [ ] | undefined {
@@ -330,15 +335,11 @@ namespace ts.GoToDefinition {
330
335
331
336
/** Returns a CallLikeExpression where `node` is the target being invoked. */
332
337
function getAncestorCallLikeExpression ( node : Node ) : CallLikeExpression | undefined {
333
- const target = climbPastManyPropertyAccesses ( node ) ;
334
- const callLike = target . parent ;
338
+ const target = findAncestor ( node , n => ! isRightSideOfPropertyAccess ( n ) ) ;
339
+ const callLike = target ? .parent ;
335
340
return callLike && isCallLikeExpression ( callLike ) && getInvokedExpression ( callLike ) === target ? callLike : undefined ;
336
341
}
337
342
338
- function climbPastManyPropertyAccesses ( node : Node ) : Node {
339
- return isRightSideOfPropertyAccess ( node ) ? climbPastManyPropertyAccesses ( node . parent ) : node ;
340
- }
341
-
342
343
function tryGetSignatureDeclaration ( typeChecker : TypeChecker , node : Node ) : SignatureDeclaration | undefined {
343
344
const callLike = getAncestorCallLikeExpression ( node ) ;
344
345
const signature = callLike && typeChecker . getResolvedSignature ( callLike ) ;
0 commit comments