<commit_before>import NodePath from "./path";
import * as t from "../types";

export default class TraversalContext {
  constructor(scope, opts, state, parentPath) {
    this.parentPath = parentPath;
    this.scope      = scope;
    this.state      = state;
    this.opts       = opts;
  }

  shouldVisit(node) {
    var keys = t.VISITOR_KEYS[node.type];
    return !!(this.opts.enter || this.opts.exit || this.opts[node.type] || (keys && keys.length));
  }

  create(node, obj, key, containerKey) {
    var path = NodePath.get({
      parentPath: this.parentPath,
      parent: node,
      container: obj,
      key: key,
      containerKey: containerKey
    });
    path.unshiftContext(this);
    return path;
  }

  visitMultiple(container, parent, containerKey) {
    // nothing to traverse!
    if (container.length === 0) return false;

    var visited = [];

    var queue = this.queue = [];
    var stop  = false;

    // build up initial queue
    for (let key = 0; key < container.length; key++) {
      var self = container[key];
      if (self && this.shouldVisit(self)) {
        queue.push(this.create(parent, container, key, containerKey));
      }<commit_msg>update TraversalContext#shouldVisit to check for existence of visitor keys<commit_after>import NodePath from "./path";
import * as t from "../types";

export default class TraversalContext {
  constructor(scope, opts, state, parentPath) {
    this.parentPath = parentPath;
    this.scope      = scope;
    this.state      = state;
    this.opts       = opts;
  }

  shouldVisit(node) {
    var opts = this.opts;
    if (opts.enter || opts.exit) return true;

    if (opts[node.type]) return true;

    var keys = t.VISITOR_KEYS[node.type];
    if (!keys || !keys.length) return false;

    for (var key of (keys: Array)) {
      if (node[key]) return true;
    }

    return false;
  }

  create(node, obj, key, containerKey) {
    var path = NodePath.get({
      parentPath: this.parentPath,
      parent: node,
      container: obj,
      key: key,
      containerKey: containerKey
    });
    path.unshiftContext(this);
    return path;
  }

  visitMultiple(container, parent, containerKey) {
    // nothing to traverse!
    if (container.length === 0) return false;

    var visited = [];

    var queue = this.queue = [];
    var stop  = false;

    // build up initial queue
    for (let key = 0; key < container.length; key++) {
      var self = container[key];
      if (self && this.shouldVisit(self)) {
        queue.push(this.create(parent, container, key, containerKey));
      }
{'fraction_non_alphanumeric': 0.13016367887763056, 'fraction_numerical': 0.001558846453624318, 'mean_word_length': 2.610407876230661, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1660865', 'n_tokens_mistral': 806, 'n_tokens_neox': 774, 'n_words': 221}