Skip to content

Commit 673ae74

Browse files
author
Andy
authored
Simplify and inline getPropertySymbolsFromType (microsoft#25940)
* Simplify and inline getPropertySymbolsFromType * Combine lambdas
1 parent 3057be3 commit 673ae74

File tree

2 files changed

+5
-28
lines changed

2 files changed

+5
-28
lines changed

src/services/goToDefinition.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,12 @@ namespace ts.GoToDefinition {
6868
// bar<Test>(({pr/*goto*/op1})=>{});
6969
if (isPropertyName(node) && isBindingElement(parent) && isObjectBindingPattern(parent.parent) &&
7070
(node === (parent.propertyName || parent.name))) {
71+
const name = getNameFromPropertyName(node);
7172
const type = typeChecker.getTypeAtLocation(parent.parent);
72-
const propSymbols = getPropertySymbolsFromType(type, node);
73-
if (propSymbols) {
74-
return flatMap(propSymbols, propSymbol => getDefinitionFromSymbol(typeChecker, propSymbol, node));
75-
}
73+
return name === undefined ? emptyArray : flatMap(type.isUnion() ? type.types : [type], t => {
74+
const prop = t.getProperty(name);
75+
return prop && getDefinitionFromSymbol(typeChecker, prop, node);
76+
});
7677
}
7778

7879
// If the current location we want to find its definition is in an object literal, try to get the contextual type for the

src/services/services.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2230,30 +2230,6 @@ namespace ts {
22302230
return discriminatedPropertySymbols;
22312231
}
22322232

2233-
/* @internal */
2234-
export function getPropertySymbolsFromType(type: Type, propName: PropertyName) {
2235-
const name = unescapeLeadingUnderscores(getTextOfPropertyName(propName));
2236-
if (name && type) {
2237-
const result: Symbol[] = [];
2238-
const symbol = type.getProperty(name);
2239-
if (type.flags & TypeFlags.Union) {
2240-
forEach((<UnionType>type).types, t => {
2241-
const symbol = t.getProperty(name);
2242-
if (symbol) {
2243-
result.push(symbol);
2244-
}
2245-
});
2246-
return result;
2247-
}
2248-
2249-
if (symbol) {
2250-
result.push(symbol);
2251-
return result;
2252-
}
2253-
}
2254-
return undefined;
2255-
}
2256-
22572233
function isArgumentOfElementAccessExpression(node: Node) {
22582234
return node &&
22592235
node.parent &&

0 commit comments

Comments
 (0)