function visit(ast, context, visitor) {
  var stack;
  var parent;
  var keys = [];
  var index = -1;

  do {
    index++;
    if (stack && index === keys.length) {
      parent = stack.parent;
      keys = stack.keys;
      index = stack.index;
      stack = stack.prev;
    } else {
      var node = parent ? parent[keys[index]] : getProgram(ast);
      if (node && typeof node === 'object' && (node.type || node.length)) {
        if (node.type) {
          var visitFn = visitor[node.type];
          if (visitFn && visitFn(context, node, ast) === false) {
            continue;
          }
        }
        stack = {parent: parent, keys: keys, index: index, prev: stack};
        parent = node;
        keys = Object.keys(node);
        index = -1;
      }
    }
  } while (stack);
}
function visit(ast, context, visitor) {
  var stack;
  var parent;
  var keys = [];
  var index = -1;

  do {
    index++;
    if (stack && index === keys.length) {
      parent = stack.parent;
      keys = stack.keys;
      index = stack.index;
      stack = stack.prev;
    } else {
      var node = parent ? parent[keys[index]] : getProgram(ast);
      if (node && typeof node === 'object' && (node.type || node.length)) {
        if (node.type) {
          var visitFn = visitor[node.type];
          if (visitFn && visitFn(context, node, ast) === false) {
            continue;
          }
        }
        stack = {parent: parent, keys: keys, index: index, prev: stack};
        parent = node;
        keys = Object.keys(node);
        index = -1;
      }
    }
  } while (stack);
}
function visit ( ast , context , visitor ) { var stack ; var parent ; var keys = [ ] ; var index = - 1 ; do { index ++ ; if ( stack && index === keys . length ) { parent = stack . parent ; keys = stack . keys ; index = stack . index ; stack = stack . prev ; } else { var node = parent ? parent [ keys [ index ] ] : getProgram ( ast ) ; if ( node && typeof node === 'object' && ( node . type || node . length ) ) { if ( node . type ) { var visitFn = visitor [ node . type ] ; if ( visitFn && visitFn ( context , node , ast ) === false ) { continue ; } } stack = { parent : parent , keys : keys , index : index , prev : stack } ; parent = node ; keys = Object . keys ( node ) ; index = - 1 ; } } } while ( stack ) ; }
Given the AST output from the parser, walk through in a depth-first order, calling methods on the given visitor, providing context as the first argument.
Given the AST output from the parser walk through in a depth - first order calling methods on the given visitor providing context as the first argument .
Visit the given AST.