diff options
Diffstat (limited to 'tools/eslint/node_modules/esrecurse/esrecurse.js')
-rw-r--r-- | tools/eslint/node_modules/esrecurse/esrecurse.js | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/tools/eslint/node_modules/esrecurse/esrecurse.js b/tools/eslint/node_modules/esrecurse/esrecurse.js index 0774f86f6b..0805e67f39 100644 --- a/tools/eslint/node_modules/esrecurse/esrecurse.js +++ b/tools/eslint/node_modules/esrecurse/esrecurse.js @@ -24,18 +24,17 @@ (function () { 'use strict'; - var estraverse, + var assign, + estraverse, isArray, objectKeys; + assign = require('object-assign'); estraverse = require('estraverse'); - isArray = Array.isArray; - if (!isArray) { - isArray = function isArray(array) { - return Object.prototype.toString.call(array) === '[object Array]'; - }; - } + isArray = Array.isArray || function isArray(array) { + return Object.prototype.toString.call(array) === '[object Array]'; + }; objectKeys = Object.keys || function (o) { var keys = [], key; @@ -56,8 +55,18 @@ return (nodeType === estraverse.Syntax.ObjectExpression || nodeType === estraverse.Syntax.ObjectPattern) && key === 'properties'; } - function Visitor(visitor) { + function Visitor(visitor, options) { + options = options || {}; + this.__visitor = visitor || this; + this.__childVisitorKeys = options.childVisitorKeys + ? assign({}, estraverse.VisitorKeys, options.childVisitorKeys) + : estraverse.VisitorKeys; + if (options.fallback === 'iteration') { + this.__fallback = objectKeys; + } else if (typeof options.fallback === 'function') { + this.__fallback = options.fallback; + } } /* Default method for visiting children. @@ -73,15 +82,19 @@ type = node.type || estraverse.Syntax.Property; - children = estraverse.VisitorKeys[type]; + children = this.__childVisitorKeys[type]; if (!children) { - children = objectKeys(node); + if (this.__fallback) { + children = this.__fallback(node); + } else { + throw new Error('Unknown node type ' + type + '.'); + } } for (i = 0, iz = children.length; i < iz; ++i) { child = node[children[i]]; if (child) { - if (Array.isArray(child)) { + if (isArray(child)) { for (j = 0, jz = child.length; j < jz; ++j) { if (child[j]) { if (isNode(child[j]) || isProperty(type, children[i])) { @@ -114,8 +127,8 @@ exports.version = require('./package.json').version; exports.Visitor = Visitor; - exports.visit = function (node, visitor) { - var v = new Visitor(visitor); + exports.visit = function (node, visitor, options) { + var v = new Visitor(visitor, options); v.visit(node); }; }()); |