export class AstWalker { param { Object } ast param { Object or public walk ( ast , callback ) { if ( callback instanceof Function ) { callback = { '*' : callback } ; } if ( ! ( '*' in callback ) ) { callback [ '*' ] = function ( ) { return true ; } ; } if ( this . manageCallBack ( ast , callback ) && ast . children && ast . children . length > 0 ) { for ( const k in ast . children ) { const child = ast . children [ k ] ; this . walk ( child , callback ) ; } } } public walkDetail ( ast , parent , depth , callback ) { if ( callback instanceof Function ) { callback = { '*' : callback } ; } if ( ! ( '*' in callback ) ) { callback [ '*' ] = function ( ) { return true ; } ; } if ( this . manageCallBackDetail ( ast , parent , depth , callback ) && ast . children && ast . children . length > 0 ) { for ( const k in ast . children ) { const child = ast . children [ k ] ; this . walkDetail ( child , ast , depth + 1 , callback ) ; } } } param { Object } sourcesList param { Function } public walkAstList ( sourcesList , callback ) { const walker = new AstWalker ( ) ; for ( const k in sourcesList ) { walker . walk ( sourcesList [ k ] . AST , callback ) ; } } private manageCallBack ( node , callback ) { if ( node . name in callback ) { return callback [ node . name ] ( node ) ; } else { return callback [ '*' ] ( node ) ; } } private manageCallBackDetail ( node , parent , depth , callback ) { if ( node . name in callback ) { return callback [ node . name ] ( node , parent , depth ) ; } else { return callback [ '*' ] ( node , parent , depth ) ; } } }