goToDefinition: Put variable definition before signature definition (#24649)

* goToDefinition: Put variable definition before signature definition

* Fix lint
This commit is contained in:
Andy 2018-06-04 14:13:27 -07:00 committed by GitHub
parent 2f73986b44
commit a641e6f85f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 13 additions and 8 deletions

View file

@ -32,11 +32,16 @@ namespace ts.GoToDefinition {
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
// For a function, if this is the original function definition, return just sigInfo.
// 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
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))
? [sigInfo]
: [sigInfo, ...getDefinitionFromSymbol(typeChecker, symbol, node)!];
symbol.declarations.some(d => isVariableDeclaration(d) && !!d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))) {
return [sigInfo];
}
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,

View file

@ -11,6 +11,6 @@
////new [|/*invokeExpression2*/I2|]();
verify.goToDefinition({
invokeExpression1: ["constructSignature", "I"],
invokeExpression1: ["I", "constructSignature"],
invokeExpression2: "symbolDeclaration"
});

View file

@ -10,6 +10,6 @@
verify.goToDefinition({
useF: "f",
useG: ["f", "g"],
useH: ["f", "h"],
useG: ["g", "f"],
useH: ["h", "f"],
});

View file

@ -22,5 +22,5 @@
//// <[|SFC/*one*/Comp|] x />
verify.goToDefinition({
"one": ["pt1", "def"],
"one": ["def", "pt1"],
});