Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit b271df1

Browse filesBrowse files
author
Andy
authored
Simplify getParentSymbolsOfPropertyAccess (microsoft#23513)
1 parent 0e9b815 commit b271df1
Copy full SHA for b271df1

1 file changed

+7-25Lines changed: 7 additions & 25 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/findAllReferences.ts‎

Copy file name to clipboardExpand all lines: src/services/findAllReferences.ts
+7-25Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1030,10 +1030,6 @@ namespace ts.FindAllReferences.Core {
10301030
}
10311031
}
10321032

1033-
function getPropertyAccessExpressionFromRightHandSide(node: Node): PropertyAccessExpression {
1034-
return isRightSideOfPropertyAccess(node) && <PropertyAccessExpression>node.parent;
1035-
}
1036-
10371033
/**
10381034
* `classSymbol` is the class where the constructor was defined.
10391035
* Reference the constructor and all calls to `new this()`.
@@ -1130,18 +1126,6 @@ namespace ts.FindAllReferences.Core {
11301126
}
11311127
}
11321128

1133-
function getSymbolsForClassAndInterfaceComponents(type: UnionOrIntersectionType, result: Symbol[] = []): Symbol[] {
1134-
for (const componentType of type.types) {
1135-
if (componentType.symbol && componentType.symbol.getFlags() & (SymbolFlags.Class | SymbolFlags.Interface)) {
1136-
result.push(componentType.symbol);
1137-
}
1138-
if (componentType.isUnionOrIntersection()) {
1139-
getSymbolsForClassAndInterfaceComponents(componentType, result);
1140-
}
1141-
}
1142-
return result;
1143-
}
1144-
11451129
function getContainingTypeReference(node: Node): Node {
11461130
let topLevelTypeReference: Node;
11471131

@@ -1462,7 +1446,7 @@ namespace ts.FindAllReferences.Core {
14621446
? rootSymbol && !(getCheckFlags(sym) & CheckFlags.Synthetic) ? rootSymbol : sym
14631447
: undefined,
14641448
/*allowBaseTypes*/ rootSymbol =>
1465-
!(search.parents && !some(search.parents, parent => explicitlyInheritsFrom(rootSymbol.parent, parent, state.inheritsFromCache, checker))));
1449+
!(search.parents && !search.parents.some(parent => explicitlyInheritsFrom(rootSymbol.parent, parent, state.inheritsFromCache, checker))));
14661450
}
14671451

14681452
/** Gets all symbols for one property. Does not get symbols for every property. */
@@ -1549,13 +1533,11 @@ namespace ts.FindAllReferences.Core {
15491533
* symbol may have a different parent symbol if the local type's symbol does not declare the property
15501534
* being accessed (i.e. it is declared in some parent class or interface)
15511535
*/
1552-
function getParentSymbolsOfPropertyAccess(location: Node, symbol: Symbol, checker: TypeChecker): Symbol[] | undefined {
1553-
const propertyAccessExpression = getPropertyAccessExpressionFromRightHandSide(location);
1554-
const localParentType = propertyAccessExpression && checker.getTypeAtLocation(propertyAccessExpression.expression);
1555-
return localParentType && localParentType.symbol && localParentType.symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface) && localParentType.symbol !== symbol.parent
1556-
? [localParentType.symbol]
1557-
: localParentType && localParentType.isUnionOrIntersection()
1558-
? getSymbolsForClassAndInterfaceComponents(localParentType)
1559-
: undefined;
1536+
function getParentSymbolsOfPropertyAccess(location: Node, symbol: Symbol, checker: TypeChecker): ReadonlyArray<Symbol> | undefined {
1537+
const propertyAccessExpression = isRightSideOfPropertyAccess(location) ? <PropertyAccessExpression>location.parent : undefined;
1538+
const lhsType = propertyAccessExpression && checker.getTypeAtLocation(propertyAccessExpression.expression);
1539+
const res = mapDefined(lhsType && (lhsType.isUnionOrIntersection() ? lhsType.types : lhsType.symbol === symbol.parent ? undefined : [lhsType]), t =>
1540+
t.symbol && t.symbol.flags & (SymbolFlags.Class | SymbolFlags.Interface) ? t.symbol : undefined);
1541+
return res.length === 0 ? undefined : res;
15601542
}
15611543
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.