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

* Remove obsolete code

* Revert package-lock change
This commit is contained in:
Andrew Branch
2020-11-25 09:01:56 -08:00
committed by GitHub
parent 86429aae33
commit 3fa30f4826

View File

@@ -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;