export function getAncestors < T > ( node , getParent ) { const ancestors = [ ] ; forEachAncestor ( node , ( x ) => ancestors . push ( x ) ) ; return ancestors ; function forEachAncestor ( node , callback ) { const parent = getParent ( node ) ; if ( ! parent ) { return ; } callback ( parent ) ; forEachAncestor ( parent , callback ) ; } }