Simplify and inline getPropertySymbolsFromType (#25940)

* Simplify and inline getPropertySymbolsFromType

* Combine lambdas
This commit is contained in:
Andy 2018-07-26 11:52:22 -07:00 committed by GitHub
parent 3057be3a0b
commit 673ae746da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 28 deletions

View File

@ -68,11 +68,12 @@ namespace ts.GoToDefinition {
// bar<Test>(({pr/*goto*/op1})=>{});
if (isPropertyName(node) && isBindingElement(parent) && isObjectBindingPattern(parent.parent) &&
(node === (parent.propertyName || parent.name))) {
const name = getNameFromPropertyName(node);
const type = typeChecker.getTypeAtLocation(parent.parent);
const propSymbols = getPropertySymbolsFromType(type, node);
if (propSymbols) {
return flatMap(propSymbols, propSymbol => getDefinitionFromSymbol(typeChecker, propSymbol, node));
}
return name === undefined ? emptyArray : flatMap(type.isUnion() ? type.types : [type], t => {
const prop = t.getProperty(name);
return prop && getDefinitionFromSymbol(typeChecker, prop, node);
});
}
// If the current location we want to find its definition is in an object literal, try to get the contextual type for the

View File

@ -2230,30 +2230,6 @@ namespace ts {
return discriminatedPropertySymbols;
}
/* @internal */
export function getPropertySymbolsFromType(type: Type, propName: PropertyName) {
const name = unescapeLeadingUnderscores(getTextOfPropertyName(propName));
if (name && type) {
const result: Symbol[] = [];
const symbol = type.getProperty(name);
if (type.flags & TypeFlags.Union) {
forEach((<UnionType>type).types, t => {
const symbol = t.getProperty(name);
if (symbol) {
result.push(symbol);
}
});
return result;
}
if (symbol) {
result.push(symbol);
return result;
}
}
return undefined;
}
function isArgumentOfElementAccessExpression(node: Node) {
return node &&
node.parent &&