mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-04 21:53:42 -06:00
goToDefinition: Don't add duplicate definitions for VariableDeclaration and ArrowFunction at f = () => {} (#24863)
This commit is contained in:
parent
1aad3c6273
commit
7df81311ac
@ -32,7 +32,7 @@ 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.
|
||||
if (typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
|
||||
if (typeChecker.getRootSymbols(symbol).some(s => symbolMatchesSignature(s, calledDeclaration)) ||
|
||||
// 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))) {
|
||||
return [sigInfo];
|
||||
@ -93,6 +93,15 @@ namespace ts.GoToDefinition {
|
||||
return getDefinitionFromSymbol(typeChecker, symbol, node);
|
||||
}
|
||||
|
||||
/**
|
||||
* True if we should not add definitions for both the signature symbol and the definition symbol.
|
||||
* True for `const |f = |() => 0`, false for `function |f() {} const |g = f;`.
|
||||
*/
|
||||
function symbolMatchesSignature(s: Symbol, calledDeclaration: SignatureDeclaration) {
|
||||
return s === calledDeclaration.symbol || s === calledDeclaration.symbol.parent ||
|
||||
isVariableDeclaration(calledDeclaration.parent) && s === calledDeclaration.parent.symbol;
|
||||
}
|
||||
|
||||
export function getReferenceAtPosition(sourceFile: SourceFile, position: number, program: Program): { fileName: string, file: SourceFile } | undefined {
|
||||
const referencePath = findReferenceInPosition(sourceFile.referencedFiles, position);
|
||||
if (referencePath) {
|
||||
|
||||
@ -8,8 +8,17 @@
|
||||
////[|/*useG*/g|]();
|
||||
////[|/*useH*/h|]();
|
||||
|
||||
////const i = /*i*/() => 0;
|
||||
////const /*j*/j = i;
|
||||
|
||||
////[|/*useI*/i|]();
|
||||
////[|/*useJ*/j|]();
|
||||
|
||||
verify.goToDefinition({
|
||||
useF: "f",
|
||||
useG: ["g", "f"],
|
||||
useH: ["h", "f"],
|
||||
|
||||
useI: "i",
|
||||
useJ: ["j", "i"],
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user