Skip to content

Commit 78e0384

Browse files
author
Orta
authored
Merge pull request microsoft#31946 from orta/30246
Don't let the additional property setting on an object show up as a definition to tsserver
2 parents 9d404b4 + 3145656 commit 78e0384

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/services/goToDefinition.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,23 @@ namespace ts.GoToDefinition {
233233
}
234234

235235
function getDefinitionFromSymbol(typeChecker: TypeChecker, symbol: Symbol, node: Node): DefinitionInfo[] | undefined {
236-
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(symbol.declarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
236+
// There are cases when you extend a function by adding properties to it afterwards,
237+
// we want to strip those extra properties
238+
const filteredDeclarations = filter(symbol.declarations, d => !isAssignmentDeclaration(d) || d === symbol.valueDeclaration) || undefined;
239+
return getConstructSignatureDefinition() || getCallSignatureDefinition() || map(filteredDeclarations, declaration => createDefinitionInfo(declaration, typeChecker, symbol, node));
237240

238241
function getConstructSignatureDefinition(): DefinitionInfo[] | undefined {
239242
// Applicable only if we are in a new expression, or we are on a constructor declaration
240243
// and in either case the symbol has a construct signature definition, i.e. class
241244
if (symbol.flags & SymbolFlags.Class && (isNewExpressionTarget(node) || node.kind === SyntaxKind.ConstructorKeyword)) {
242-
const cls = find(symbol.declarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
245+
const cls = find(filteredDeclarations, isClassLike) || Debug.fail("Expected declaration to have at least one class-like declaration");
243246
return getSignatureDefinition(cls.members, /*selectConstructors*/ true);
244247
}
245248
}
246249

247250
function getCallSignatureDefinition(): DefinitionInfo[] | undefined {
248251
return isCallOrNewExpressionTarget(node) || isNameOfFunctionDeclaration(node)
249-
? getSignatureDefinition(symbol.declarations, /*selectConstructors*/ false)
252+
? getSignatureDefinition(filteredDeclarations, /*selectConstructors*/ false)
250253
: undefined;
251254
}
252255

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// export const /*FunctionResult*/Component = () => { return "OK"}
4+
//// Component./*PropertyResult*/displayName = 'Component'
5+
////
6+
//// [|/*FunctionClick*/Component|]
7+
////
8+
//// Component.[|/*PropertyClick*/displayName|]
9+
10+
verify.goToDefinition("FunctionClick", "FunctionResult")
11+
verify.goToDefinition("PropertyClick", "PropertyResult")

0 commit comments

Comments
 (0)