diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index de473a79c97e8..3567716cb1cc5 100644 --- a/src/services/goToDefinition.ts +++ b/src/services/goToDefinition.ts @@ -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;`. @@ -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;