Skip to content

Commit 86d0fa2

Browse files
author
Andy
authored
Use findAncestor in more places (#17601)
1 parent 1552761 commit 86d0fa2

File tree

1 file changed

+2
-12
lines changed

1 file changed

+2
-12
lines changed

src/compiler/utilities.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -922,21 +922,11 @@ namespace ts {
922922
}
923923

924924
export function getContainingFunction(node: Node): FunctionLike {
925-
while (true) {
926-
node = node.parent;
927-
if (!node || isFunctionLike(node)) {
928-
return <FunctionLike>node;
929-
}
930-
}
925+
return findAncestor(node.parent, isFunctionLike);
931926
}
932927

933928
export function getContainingClass(node: Node): ClassLikeDeclaration {
934-
while (true) {
935-
node = node.parent;
936-
if (!node || isClassLike(node)) {
937-
return <ClassLikeDeclaration>node;
938-
}
939-
}
929+
return findAncestor(node.parent, isClassLike);
940930
}
941931

942932
export function getThisContainer(node: Node, includeArrowFunctions: boolean): Node {

0 commit comments

Comments
 (0)