Blame view

node_modules/eslint/lib/util/traverser.js 1.19 KB
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  /**
   * @fileoverview Wrapper around estraverse
   * @author Nicholas C. Zakas
   */
  "use strict";
  
  //------------------------------------------------------------------------------
  // Requirements
  //------------------------------------------------------------------------------
  
  const estraverse = require("estraverse");
  
  //------------------------------------------------------------------------------
  // Helpers
  //------------------------------------------------------------------------------
  
  const KEY_BLACKLIST = new Set([
      "parent",
      "leadingComments",
      "trailingComments"
  ]);
  
  /**
   * Wrapper around an estraverse controller that ensures the correct keys
   * are visited.
   * @constructor
   */
  class Traverser extends estraverse.Controller {
      traverse(node, visitor) {
          visitor.fallback = Traverser.getKeys;
          return super.traverse(node, visitor);
      }
  
      /**
       * Calculates the keys to use for traversal.
       * @param {ASTNode} node The node to read keys from.
       * @returns {string[]} An array of keys to visit on the node.
       * @private
       */
      static getKeys(node) {
          return Object.keys(node).filter(key => !KEY_BLACKLIST.has(key));
      }
  }
  
  module.exports = Traverser;