Skip to content

Commit 724e656

Browse files
author
Andy
authored
Don't show a definition at a 'require' call (microsoft#23822)
1 parent deef6cd commit 724e656

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/services/goToDefinition.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ namespace ts.GoToDefinition {
3131
const sigInfo = createDefinitionFromSignatureDeclaration(typeChecker, calledDeclaration);
3232
// For a function, if this is the original function definition, return just sigInfo.
3333
// If this is the original constructor definition, parent is the class.
34-
return typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s)
34+
return typeChecker.getRootSymbols(symbol).some(s => calledDeclaration.symbol === s || calledDeclaration.symbol.parent === s) ||
35+
// TODO: GH#23742 Following check shouldn't be necessary if 'require' is an alias
36+
symbol.declarations.some(d => isVariableDeclaration(d) && d.initializer && isRequireCall(d.initializer, /*checkArgumentIsStringLiteralLike*/ false))
3537
? [sigInfo]
3638
: [sigInfo, ...getDefinitionFromSymbol(typeChecker, symbol, node)];
3739
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/// <reference path='fourslash.ts'/>
2+
3+
// @allowJs: true
4+
5+
// @Filename: /a.js
6+
////module.exports = function /*f*/f() {}
7+
8+
// @Filename: /b.js
9+
////const f = require("./a");
10+
////[|/*use*/f|]();
11+
12+
verify.goToDefinition("use", "f");

0 commit comments

Comments
 (0)