import ts = require ( 'typescript' ) ; import { Visitor , VisitorContext } from './visitor' ; function descend ( node , context ) { return function visit ( ... visitors ) : void { visitors . forEach ( visitor => { traverseAst ( node , visitor , context ) ; } ) ; } ; } export function traverseAst ( root , visitor , context ) { function traverse ( node ) { if ( visitor . filter ( node ) ) { visitor . visit ( node , context , descend ( node , context ) ) ; return context . halted || ts . forEachChild ( node , traverse ) ; } return ts . forEachChild ( node , traverse ) ; } return traverse ( root ) ; }