From 3fa30f48262bb786835556fdef5d6c9b737642c7 Mon Sep 17 00:00:00 2001 From: Andrew Branch Date: Wed, 25 Nov 2020 09:01:56 -0800 Subject: [PATCH] Remove obsolete go-to-definition code after CommonJS alias changes (#41522) * Remove obsolete code * Revert package-lock change --- src/services/goToDefinition.ts | 30 +++++------------------------- 1 file changed, 5 insertions(+), 25 deletions(-) diff --git a/src/services/goToDefinition.ts b/src/services/goToDefinition.ts index de473a79c97..3567716cb1c 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;