import { Abbreviation , AbbreviationNode } from '@emmetio/abbreviation' ; export type Container = Abbreviation | AbbreviationNode ; export type WalkVisitor < S > = ( node : AbbreviationNode , ancestors : Container [ ] , state ? : S ) => void ; /**
 * Walks over each child node of given markup abbreviation AST node (not including
 * given one) and invokes `fn` on each node.
 * The `fn` callback accepts context node, list of ancestor nodes and optional
 * state object
 */ export function walk < S > ( node , fn , state ? ) { const ancestors = [ node ] ; const callback = ( ctx ) => { fn ( ctx , ancestors , state ) ; ancestors . push ( ctx ) ; ctx . children . forEach ( callback ) ; ancestors . pop ( ) ; } ; node . children . forEach ( callback ) ; } /**
 * Finds node which is the deepest for in current node or node itself.
 */ export function findDeepest ( node ) { let parent ; while ( node . children . length ) { parent = node ; node = node . children [ node . children . length - 1 ] ; } return { parent , node } ; } export function isNode ( node ) { return node . type === 'AbbreviationNode' ; }