node/tools/eslint/lib/util/traverser.js
Rich Trott 316665235c tools: update ESLint to 3.19.0
PR-URL: https://github.com/nodejs/node/pull/12162
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-04-04 10:24:10 -07:00

45 lines
1.2 KiB
JavaScript

/**
* @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;