import { AST } from "@glimmer/syntax" ; import { Position , SourceLocation } from "estree" ; import { containsPosition } from "./estTreeUtils" ; export interface FocusPath { parent : FocusPath | null ; data : AST . Node | null ; } /**
 * Returns a linked list where the root node is the item found at the corresponding
 * position with links back to all of its parent nodes.
 */ export function createFocusPath ( node , position , seen = new Set ( ) , astPathNode = { parent : null , data : null } ) { seen . add ( node ) ; let range = node . loc ; if ( range ) { if ( containsPosition ( range , position ) ) { astPathNode . parent = { data : astPathNode . data , parent : astPathNode . parent , } ; astPathNode . data = node ; } else { return null ; } } for ( let key of Object . keys ( node ) ) { let value = node [ key ] ; if ( ! value || typeof value !== "object" || seen . has ( value ) ) { continue ; } createFocusPath ( value , position , seen , astPathNode ) ; } return astPathNode ; }