Skip to content

Remove obsolete go-to-definition code after CommonJS alias changes #41522

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 5 additions & 25 deletions src/services/goToDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,6 @@ namespace ts.GoToDefinition {
return getDefinitionFromSymbol(typeChecker, symbol, node);
}

function isShorthandPropertyAssignmentOfModuleExports(symbol: Symbol): boolean {
const shorthandProperty = tryCast(symbol.valueDeclaration, isShorthandPropertyAssignment);
const binaryExpression = tryCast(shorthandProperty?.parent.parent, isAssignmentExpression);
return !!binaryExpression && getAssignmentDeclarationKind(binaryExpression) === AssignmentDeclarationKind.ModuleExports;
}

/**
* 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;`.
Expand Down Expand Up @@ -204,29 +198,15 @@ namespace ts.GoToDefinition {
}

function getSymbol(node: Node, checker: TypeChecker): Symbol | undefined {
let symbol = checker.getSymbolAtLocation(node);
const symbol = checker.getSymbolAtLocation(node);
// If this is an alias, and the request came at the declaration location
// get the aliased symbol instead. This allows for goto def on an import e.g.
// import {A, B} from "mod";
// to jump to the implementation directly.
while (symbol) {
if (symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
const aliased = checker.getAliasedSymbol(symbol);
if (!aliased.declarations) {
break;
}
symbol = aliased;
}
else if (isShorthandPropertyAssignmentOfModuleExports(symbol)) {
// Skip past `module.exports = { Foo }` even though 'Foo' is not a real alias
const shorthandTarget = checker.resolveName(symbol.name, symbol.valueDeclaration, SymbolFlags.Value, /*excludeGlobals*/ false);
if (!some(shorthandTarget?.declarations)) {
break;
}
symbol = shorthandTarget;
}
else {
break;
if (symbol && symbol.flags & SymbolFlags.Alias && shouldSkipAlias(node, symbol.declarations[0])) {
const aliased = checker.getAliasedSymbol(symbol);
if (aliased.declarations) {
return aliased;
}
}
return symbol;
Expand Down