index.js
function traverse(object, visitor) {
  let child;
  if (!object) return;

  let r = visitor.call(null, object);
  if (r === STOP) return STOP; // stop whole traverse immediately
  if (r === SKIP_BRANCH) return; // skip going into AST branch

  for (let i = 0, keys = Object.keys(object); i < keys.length; i++) {
    let key = keys[i];
    if (IGNORED_KEYS.indexOf(key) !== -1) continue;

    child = object[key];
    if (typeof child === 'object' && child !== null) {
      if (traverse(child, visitor) === STOP) {
        return STOP;
      }
    }
  }
}
function traverse(object, visitor) {
  let child;
  if (!object) return;

  let r = visitor.call(null, object);
  if (r === STOP) return STOP; // stop whole traverse immediately
  if (r === SKIP_BRANCH) return; // skip going into AST branch

  for (let i = 0, keys = Object.keys(object); i < keys.length; i++) {
    let key = keys[i];
    if (IGNORED_KEYS.indexOf(key) !== -1) continue;

    child = object[key];
    if (typeof child === 'object' && child !== null) {
      if (traverse(child, visitor) === STOP) {
        return STOP;
      }
    }
  }
}
function traverse ( object , visitor ) { let child ; if ( ! object ) return ; let r = visitor . call ( null , object ) ; if ( r === STOP ) return STOP ; // stop whole traverse immediately if ( r === SKIP_BRANCH ) return ; // skip going into AST branch for ( let i = 0 , keys = Object . keys ( object ) ; i < keys . length ; i ++ ) { let key = keys [ i ] ; if ( IGNORED_KEYS . indexOf ( key ) !== - 1 ) continue ; child = object [ key ] ; if ( typeof child === 'object' && child !== null ) { if ( traverse ( child , visitor ) === STOP ) { return STOP ; } } } }
From an esprima example for traversing its ast. modified to support branch skip.
From an esprima example for traversing its ast . modified to support branch skip .