diff --git a/lib/6to5/traverse/index.js b/lib/6to5/traverse/index.js index 06efb546e6..d8a3e63229 100644 --- a/lib/6to5/traverse/index.js +++ b/lib/6to5/traverse/index.js @@ -110,7 +110,7 @@ TraversalContext.prototype.visitNode = function (obj, key, opts, scope, parent, var ourScope = scope; // we're entering a new scope so let's construct it! - if (t.isScope(node)) { + if (!opts.noScope && t.isScope(node)) { ourScope = new Scope(node, parent, scope); } @@ -177,7 +177,7 @@ function traverseNode(node, opts, scope, state) { function traverse(parent, opts, scope, state) { if (!parent) return; - if (!scope) { + if (!opts.noScope && !scope) { if (parent.type !== "Program" && parent.type !== "File") { throw new Error("Must pass a scope unless traversing a Program/File got a " + parent.type + " node"); } @@ -217,7 +217,10 @@ function clearNode(node) { } } -var clearVisitor = { enter: clearNode }; +var clearVisitor = { + noScope: true, + enter: clearNode +}; function clearComments(comments) { for (var i = 0; i < comments.length; i++) {