Sha256: fe7ab2154193d91ef1479a6b84fc587584a5acd8d99f5237777c9cbca538409b

Contents?: true

Size: 1.15 KB

Versions: 11

Compression:

Stored size: 1.15 KB

Contents

function traverse(root, options) {
    "use strict";

    options = options || {};
    var pre = options.pre;
    var post = options.post;
    var skipProperty = options.skipProperty;

    function visit(node, parent, prop, idx) {
        if (!node || typeof node.type !== "string") {
            return;
        }

        var res = undefined;
        if (pre) {
            res = pre(node, parent, prop, idx);
        }

        if (res !== false) {
            for (var prop in node) {
                if (skipProperty ? skipProperty(prop, node) : prop[0] === "$") {
                    continue;
                }

                var child = node[prop];

                if (Array.isArray(child)) {
                    for (var i = 0; i < child.length; i++) {
                        visit(child[i], node, prop, i);
                    }
                } else {
                    visit(child, node, prop);
                }
            }
        }

        if (post) {
            post(node, parent, prop, idx);
        }
    }

    visit(root, null);
};

if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
    module.exports = traverse;
}

Version data entries

11 entries across 11 versions & 4 rubygems

Version Path
ilog-0.4.1 node_modules/ast-traverse/ast-traverse.js
ilog-0.4.0 node_modules/ast-traverse/ast-traverse.js
ilog-0.3.3 node_modules/ast-traverse/ast-traverse.js
xcodebuild-helper-1.2.5 externals/ios-sim-master/node_modules/ast-traverse/ast-traverse.js
xcodebuild-helper-1.2.3 externals/ios-sim-master/node_modules/ast-traverse/ast-traverse.js
es6_tilt-0.1.2 test/dummy/app/assets/javascripts/node_modules/ast-traverse/ast-traverse.js
es6_tilt-0.1.1 test/dummy/app/assets/javascripts/node_modules/ast-traverse/ast-traverse.js
es6_tilt-0.1.0 test/dummy/app/assets/javascripts/node_modules/ast-traverse/ast-traverse.js
gulp_assets-1.0.0.pre.5 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/ast-traverse/ast-traverse.js
gulp_assets-1.0.0.pre.4 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/ast-traverse/ast-traverse.js
gulp_assets-1.0.0.pre.3 template/node_modules/babel-core/node_modules/regenerator/node_modules/defs/node_modules/ast-traverse/ast-traverse.js