diff --git a/src/babel/transformation/transformer.js b/src/babel/transformation/transformer.js index a98de824b9..e5df3296bb 100644 --- a/src/babel/transformation/transformer.js +++ b/src/babel/transformation/transformer.js @@ -65,10 +65,6 @@ export default class Transformer { } buildPass(file: File): TransformerPass { - if (!(file instanceof File)) { - throw new Error("Multiple versions of babel are interacting, this is either due to a version mismatch in a plugin or it was resolved incorrectly"); - } - return new TransformerPass(file, this); } } diff --git a/src/babel/traversal/path/index.js b/src/babel/traversal/path/index.js index 46d08294b0..6ff0b903bf 100644 --- a/src/babel/traversal/path/index.js +++ b/src/babel/traversal/path/index.js @@ -1,3 +1,4 @@ +import PathHoister from "./hoister"; import isBoolean from "lodash/lang/isBoolean"; import isNumber from "lodash/lang/isNumber"; import isRegExp from "lodash/lang/isRegExp"; @@ -10,7 +11,7 @@ import Scope from "../scope"; import * as t from "../../types"; var hoistVariablesVisitor = { - enter(node, parent, scope ) { + enter(node, parent, scope) { if (this.isFunction()) { return this.skip(); } @@ -100,7 +101,7 @@ export default class TraversalPath { if (this.node) nodes.push(this.node); this.replaceExpressionWithStatements(nodes); } else { - throw new Error("no idea what to do with this"); + throw new Error("no idea what to do with this "); } } @@ -258,10 +259,16 @@ export default class TraversalPath { } _verifyNodeList(nodes) { + if (typeof nodes === "object") { + nodes = [nodes]; + } + for (var i = 0; i < nodes.length; i++) { var node = nodes[i]; if (!node) throw new Error(`Node list has falsy node with the index of ${i}`); } + + return nodes; } replaceWithMultiple(nodes: Array) { @@ -601,10 +608,6 @@ export default class TraversalPath { return t.isVar(this.node); } - isScope(): boolean { - return t.isScope(this.node, this.parent); - } - isPreviousType(type: string): boolean { return t.isType(this.type, type); } @@ -633,8 +636,9 @@ export default class TraversalPath { return t.getBindingIdentifiers(this.node); } - traverse(opts, state) { - traverse(this.node, opts, this.scope, state, this); + traverse(visitor, state) { + traverse(this.node, visitor, this.scope, state, this); + } /** * Description diff --git a/src/babel/traversal/scope.js b/src/babel/traversal/scope.js index 24a3d8cb40..0f09ddc0a0 100644 --- a/src/babel/traversal/scope.js +++ b/src/babel/traversal/scope.js @@ -57,7 +57,7 @@ var blockVariableVisitor = { enter(node, parent, scope, state) { if (this.isFunctionDeclaration() || this.isBlockScoped()) { state.registerDeclaration(this); - } else if (t.isScope(node, parent)) { + } else if (this.isScope()) { this.skip(); } } @@ -71,11 +71,8 @@ export default class Scope { */ constructor(path: TraversalPath, parent?: Scope, file?: File) { - var cached = path.getData("scope"); - if (cached) { - return cached; - } else { - //path.setData("scope", this); + if (parent && parent.block === path.node) { + return parent; } this.parent = parent; @@ -252,7 +249,7 @@ export default class Scope { for (var name in ids) { if (name === oldName) ids[name].name = newName; } - } else if (t.isScope(node, parent)) { + } else if (this.isScope()) { if (!scope.bindingIdentifierEquals(oldName, binding)) { this.skip(); } @@ -266,6 +263,18 @@ export default class Scope { binding.name = newName; } + /** + * Description + */ + + dump() { + var scope = this; + do { + console.log(scope.block.type, "Bindings:", Object.keys(scope.bindings)); + } while(scope = scope.parent); + console.log("-------------"); + } + /** * Description */