diff --git a/lib/6to5/traverse/index.js b/lib/6to5/traverse/index.js index 7307a7665d..a9c5c381b3 100644 --- a/lib/6to5/traverse/index.js +++ b/lib/6to5/traverse/index.js @@ -104,17 +104,18 @@ TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent, var node = obj[key]; // type is blacklisted - if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) - return; + if (opts.blacklist && opts.blacklist.indexOf(node.type) > -1) return; var ourScope = scope; - if (t.isScope(node)) + if (t.isScope(node)) { ourScope = new Scope(node, scope); + } node = this.enterNode(obj, key, node, opts.enter, parent, ourScope, state); - if (this.didSkip) + if (this.didSkip) { return this.didStop; + } traverseNode(node, opts, ourScope, state); this.exitNode(obj, key, node, opts.exit, parent, ourScope, state); @@ -155,8 +156,9 @@ function traverseNode(node, opts, scope, state) { var context = new TraversalContext(); for (var j = 0; j < keys.length; j++) { - if (context.visit(node, keys[j], opts, scope, state)) + if (context.visit(node, keys[j], opts, scope, state)) { return; + } } } @@ -169,13 +171,12 @@ function traverse(parent, opts, scope, state) { if (!opts.exit) opts.exit = noop; // array of nodes - if (!Array.isArray(parent)) { + if (Array.isArray(parent)) { + for (var i = 0; i < parent.length; i++) { + traverseNode(parent[i], opts, scope, state); + } + } else { traverseNode(parent, opts, scope, state); - return; - } - - for (var i = 0; i < parent.length; i++) { - traverseNode(parent[i], opts, scope, state); } }