Sha256: 3e29ba4f6397a566dbe2a09c8f04f89d0da611e13c586e94bd6b090f975365a9
Contents?: true
Size: 1.42 KB
Versions: 45
Compression:
Stored size: 1.42 KB
Contents
/** * @fileoverview Wrapper around estraverse * @author Nicholas C. Zakas */ "use strict"; //------------------------------------------------------------------------------ // Requirements //------------------------------------------------------------------------------ var estraverse = require("estraverse"); //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ var KEY_BLACKLIST = [ "parent", "leadingComments", "trailingComments" ]; /** * Wrapper around an estraverse controller that ensures the correct keys * are visited. * @constructor */ function Traverser() { var controller = Object.create(new estraverse.Controller()), originalTraverse = controller.traverse; // intercept call to traverse() and add the fallback key to the visitor controller.traverse = function(node, visitor) { visitor.fallback = Traverser.getKeys; return originalTraverse.call(this, node, visitor); }; return controller; } /** * 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 */ Traverser.getKeys = function(node) { return Object.keys(node).filter(function(key) { return KEY_BLACKLIST.indexOf(key) === -1; }); }; module.exports = Traverser;
Version data entries
45 entries across 45 versions & 2 rubygems