mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-02-05 16:38:05 -06:00
Simplify and inline getPropertySymbolsFromType (#25940)
* Simplify and inline getPropertySymbolsFromType * Combine lambdas
This commit is contained in:
parent
3057be3a0b
commit
673ae746da
@ -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
|
||||
|
||||
@ -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 &&
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user