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

Version Path
govuk_publishing_components-18.0.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.21.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.20.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.19.1 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.19.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.18.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.17.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.16.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.15.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.14.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.13.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.12.2 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.12.1 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.12.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.11.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.10.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.9.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.8.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.7.0 node_modules/eslint/lib/util/traverser.js
govuk_publishing_components-17.6.1 node_modules/eslint/lib/util/traverser.js