Don't show a definition at a 'require' call (#23822)

This commit is contained in:
Andy 2018-05-03 08:02:56 -07:00 committed by GitHub
parent deef6cd88c
commit 724e656acb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -31,7 +31,9 @@ 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)
return 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)];
}

View File

@ -0,0 +1,12 @@
/// <reference path='fourslash.ts'/>
// @allowJs: true
// @Filename: /a.js
////module.exports = function /*f*/f() {}
// @Filename: /b.js
////const f = require("./a");
////[|/*use*/f|]();
verify.goToDefinition("use", "f");