diff --git a/src/babel/traversal/index.js b/src/babel/traversal/index.js index 0f0a5db68c..ffeebb7b86 100644 --- a/src/babel/traversal/index.js +++ b/src/babel/traversal/index.js @@ -5,9 +5,9 @@ import * as t from "../types"; export default function traverse(parent, opts, scope, state, parentPath) { if (!parent) return; - if (!opts.noScope && !scope) { + if (!opts.noScope && (!scope || !parentPath)) { if (parent.type !== "Program" && parent.type !== "File") { - throw new Error(`Must pass a scope unless traversing a Program/File got a ${parent.type} node`); + throw new Error(`Must pass a scope and parentPath unless traversing a Program/File got a ${parent.type} node`); } } diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index f2320dd516..33cd9dfe7b 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -216,9 +216,9 @@ export default class TraversalPath { this.opts = context.opts; } - this.setScope(file); - this.type = this.node && this.node.type; + + this.setScope(file); } _remove() { diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index f07f75b54e..e090462403 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -57,7 +57,8 @@ var blockVariableVisitor = { enter(node, parent, scope, state) { if (this.isFunctionDeclaration() || this.isBlockScoped()) { state.registerDeclaration(this); - } else if (this.isScope()) { + } + if (this.isScope()) { this.skip(); } } @@ -100,7 +101,7 @@ export default class Scope { */ traverse(node: Object, opts: Object, state?) { - traverse(node, opts, this, state); + traverse(node, opts, this, state, this.path); } /**