import type { TSESTree } from '@typescript-eslint/experimental-utils' ; export function findFirstMatchingAncestor ( node , predicate ) { return ancestorsChain ( node , new Set ( ) ) . find ( predicate ) ; } export function ancestorsChain ( node , boundaryTypes ) { const chain = [ ] ; let currentNode = node . parent ; while ( currentNode ) { chain . push ( currentNode ) ; if ( boundaryTypes . has ( currentNode . type ) ) { break ; } currentNode = currentNode . parent ; } return chain ; }