goToDefinition: Put variable definition before signature definition (#24649)
* goToDefinition: Put variable definition before signature definition * Fix lint
This commit is contained in:
parent
2f73986b44
commit
a641e6f85f
4 changed files with 13 additions and 8 deletions
|
@ -32,11 +32,16 @@ namespace ts.GoToDefinition {
|
||||||
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
|
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
|
||||||
// For a function, if this is the original function definition, return just sigInfo.
|
// For a function, if this is the original function definition, return just sigInfo.
|
||||||
// If this is the original constructor definition, parent is the class.
|
// If this is the original constructor definition, parent is the class.
|
||||||
return typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
|
if (typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
|
||||||
// TODO: GH#23742 Following check shouldn't be necessary if 'require' is an alias
|
// TODO: GH#23742 Following check shouldn't be necessary if 'require' is an alias
|
||||||
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))
|
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))) {
|
||||||
? [sigInfo]
|
return [sigInfo];
|
||||||
: [sigInfo, ...getDefinitionFromSymbol(typeChecker, symbol, node)!];
|
}
|
||||||
|
else {
|
||||||
|
const defs = getDefinitionFromSymbol(typeChecker, symbol, node)!;
|
||||||
|
// For a 'super()' call, put the signature first, else put the variable first.
|
||||||
|
return node.kind === SyntaxKind.SuperKeyword ? [sigInfo, ...defs] : [...defs, sigInfo];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because name in short-hand property assignment has two different meanings: property name and property value,
|
// Because name in short-hand property assignment has two different meanings: property name and property value,
|
||||||
|
|
|
@ -11,6 +11,6 @@
|
||||||
////new [|/*invokeExpression2*/I2|]();
|
////new [|/*invokeExpression2*/I2|]();
|
||||||
|
|
||||||
verify.goToDefinition({
|
verify.goToDefinition({
|
||||||
invokeExpression1: ["constructSignature", "I"],
|
invokeExpression1: ["I", "constructSignature"],
|
||||||
invokeExpression2: "symbolDeclaration"
|
invokeExpression2: "symbolDeclaration"
|
||||||
});
|
});
|
||||||
|
|
|
@ -10,6 +10,6 @@
|
||||||
|
|
||||||
verify.goToDefinition({
|
verify.goToDefinition({
|
||||||
useF: "f",
|
useF: "f",
|
||||||
useG: ["f", "g"],
|
useG: ["g", "f"],
|
||||||
useH: ["f", "h"],
|
useH: ["h", "f"],
|
||||||
});
|
});
|
||||||
|
|
|
@ -22,5 +22,5 @@
|
||||||
//// <[|SFC/*one*/Comp|] x />
|
//// <[|SFC/*one*/Comp|] x />
|
||||||
|
|
||||||
verify.goToDefinition({
|
verify.goToDefinition({
|
||||||
"one": ["pt1", "def"],
|
"one": ["def", "pt1"],
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue