Skip to content

Commit 3fa30f4

Browse files
authored
Remove obsolete go-to-definition code after CommonJS alias changes (#41522)
* Remove obsolete code * Revert package-lock change
1 parent 86429aa commit 3fa30f4

File tree

1 file changed

+5
-25
lines changed

1 file changed

+5
-25
lines changed

src/services/goToDefinition.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,6 @@ namespace ts.GoToDefinition {
9696
return getDefinitionFromSymbol(typeChecker, symbol, node);
9797
}
9898

99-
function isShorthandPropertyAssignmentOfModuleExports(symbol: Symbol): boolean {
100-
const shorthandProperty = tryCast(symbol.valueDeclaration, isShorthandPropertyAssignment);
101-
const binaryExpression = tryCast(shorthandProperty?.parent.parent, isAssignmentExpression);
102-
return !!binaryExpression && getAssignmentDeclarationKind(binaryExpression) === AssignmentDeclarationKind.ModuleExports;
103-
}
104-
10599
/**
106100
* True if we should not add definitions for both the signature symbol and the definition symbol.
107101
* True for `const |f = |() => 0`, false for `function |f() {} const |g = f;`.
@@ -204,29 +198,15 @@ namespace ts.GoToDefinition {
204198
}
205199

206200
function getSymbol(node: Node, checker: TypeChecker): Symbol | undefined {
207-
let symbol = checker.getSymbolAtLocation(node);
201+
const symbol = checker.getSymbolAtLocation(node);
208202
// If this is an alias, and the request came at the declaration location
209203
// get the aliased symbol instead. This allows for goto def on an import e.g.
210204
// import {A, B} from "mod";
211205
// to jump to the implementation directly.
212-
while (symbol) {
213-
if (symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
214-
const aliased = checker.getAliasedSymbol(symbol);
215-
if (!aliased.declarations) {
216-
break;
217-
}
218-
symbol = aliased;
219-
}
220-
else if (isShorthandPropertyAssignmentOfModuleExports(symbol)) {
221-
// Skip past `module.exports = { Foo }` even though 'Foo' is not a real alias
222-
const shorthandTarget = checker.resolveName(symbol.name, symbol.valueDeclaration, SymbolFlags.Value, /*excludeGlobals*/ false);
223-
if (!some(shorthandTarget?.declarations)) {
224-
break;
225-
}
226-
symbol = shorthandTarget;
227-
}
228-
else {
229-
break;
206+
if (symbol && symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
207+
const aliased = checker.getAliasedSymbol(symbol);
208+
if (aliased.declarations) {
209+
return aliased;
230210
}
231211
}
232212
return symbol;

0 commit comments

Comments
 (0)