How to use the esprima.TreeIterator function in esprima

To help you get started, we’ve selected a few esprima examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github thejohnfreeman / jfdoc / lib / parser / scopedIterator.js View on Github external
for (var i = 0; i < this.stk.length; ++i) {
      var scope = this.stk[i].scope;
      if (scope.hasOwnProperty(name)) {
        decl = scope[name];
        break;
      }
    }
    return decl;
  };

  var ScopedIterator = function ScopedIterator(root, globalScope) {
    this.scopes = new ScopeStack(root, globalScope);
    esprima.TreeIterator.call(this, root);
  };

  var Base = esprima.TreeIterator.prototype;
  ScopedIterator.prototype = Object.create(Base);

  ScopedIterator.prototype.stepIn = function stepIn() {
    var node = this.get();
    var type = node.type;
    if (type === "FunctionDeclaration" || type === "FunctionExpression") {
      this.scopes.push(node);
    }
    Base.stepIn.call(this);
  };

  ScopedIterator.prototype.stepOut = function stepOut() {
    if (!Base.stepOut.call(this)) return false;
    var node = this.get();
    if (node === this.scopes.top().node) {
      this.scopes.pop(node);
github thejohnfreeman / jfdoc / lib / utility / esprima / treeIterator.js View on Github external
/**
   * Moves to the next node in the depth-first iteration order (which may be a
   * child).
   * @param skipSubtree {Boolean}
   *   Whether or not to skip over the current node's children.
   */
  TreeIterator.prototype.next = function next(skipSubtree) {
    if (skipSubtree || this.isLeaf()) {
      this.nextNonDescendant();
    } else {
      this.stepIn();
    }
  };

  require("esprima").TreeIterator = TreeIterator;

}());
github thejohnfreeman / jfdoc / lib / parser / scopedIterator.js View on Github external
var ScopedIterator = function ScopedIterator(root, globalScope) {
    this.scopes = new ScopeStack(root, globalScope);
    esprima.TreeIterator.call(this, root);
  };