Skip to content

Commit a641e6f

Browse files
author
Andy
authored
goToDefinition: Put variable definition before signature definition (microsoft#24649)
* goToDefinition: Put variable definition before signature definition * Fix lint
1 parent 2f73986 commit a641e6f

File tree

4 files changed

+13
-8
lines changed

4 files changed

+13
-8
lines changed

src/services/goToDefinition.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ namespace ts.GoToDefinition {
3232
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
3333
// For a function, if this is the original function definition, return just sigInfo.
3434
// If this is the original constructor definition, parent is the class.
35-
return typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
35+
if (typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
3636
// TODO: GH#23742 Following check shouldn't be necessary if 'require' is an alias
37-
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))
38-
? [sigInfo]
39-
: [sigInfo, ...getDefinitionFromSymbol(typeChecker, symbol, node)!];
37+
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))) {
38+
return [sigInfo];
39+
}
40+
else {
41+
const defs = getDefinitionFromSymbol(typeChecker, symbol, node)!;
42+
// For a 'super()' call, put the signature first, else put the variable first.
43+
return node.kind === SyntaxKind.SuperKeyword ? [sigInfo, ...defs] : [...defs, sigInfo];
44+
}
4045
}
4146

4247
// Because name in short-hand property assignment has two different meanings: property name and property value,

tests/cases/fourslash/goToDefinitionNewExpressionTargetNotClass.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
////new [|/*invokeExpression2*/I2|]();
1212

1313
verify.goToDefinition({
14-
invokeExpression1: ["constructSignature", "I"],
14+
invokeExpression1: ["I", "constructSignature"],
1515
invokeExpression2: "symbolDeclaration"
1616
});

tests/cases/fourslash/goToDefinitionSignatureAlias.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010

1111
verify.goToDefinition({
1212
useF: "f",
13-
useG: ["f", "g"],
14-
useH: ["f", "h"],
13+
useG: ["g", "f"],
14+
useH: ["h", "f"],
1515
});

tests/cases/fourslash/tsxGoToDefinitionUnionElementType1.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@
2222
//// <[|SFC/*one*/Comp|] x />
2323

2424
verify.goToDefinition({
25-
"one": ["pt1", "def"],
25+
"one": ["def", "pt1"],
2626
});

0 commit comments

Comments
 (0)