diff --git a/packages/babel/src/traversal/scope/binding.js b/packages/babel/src/traversal/scope/binding.js index c3e14bf4b6..0ccd33b38f 100644 --- a/packages/babel/src/traversal/scope/binding.js +++ b/packages/babel/src/traversal/scope/binding.js @@ -1,5 +1,12 @@ /** - * [Please add a description.] + * This class is responsible for a binding inside of a scope. + * + * It tracks the following: + * + * * Node path. + * * Amount of times referenced by other nodes. + * * Paths to nodes that reassign or modify this binding. + * * The kind of binding. (Is it a parameter, declaration etc) */ export default class Binding { @@ -60,7 +67,7 @@ export default class Binding { } /** - * [Please add a description.] + * Register a constant violation with the provided `path`. */ reassign(path: Object) { @@ -69,7 +76,7 @@ export default class Binding { } /** - * [Please add a description.] + * Increment the amount of references to this binding. */ reference() { @@ -78,19 +85,11 @@ export default class Binding { } /** - * [Please add a description.] + * Decrement the amount of references to this binding. */ dereference() { this.references--; this.referenced = !!this.references; } - - /** - * [Please add a description.] - */ - - isCompatibleWithType(): boolean { - return false; - } } diff --git a/packages/babel/src/traversal/scope/index.js b/packages/babel/src/traversal/scope/index.js index d2a5807c39..2c91c5ed14 100644 --- a/packages/babel/src/traversal/scope/index.js +++ b/packages/babel/src/traversal/scope/index.js @@ -187,19 +187,14 @@ var renameVisitor = { if (!scope.bindingIdentifierEquals(state.oldName, state.binding)) { this.skip(); } - } -}; + }, -/** - * [Please add a description.] - */ + "AssignmentExpression|Declaration"(node, parent, scope, state) { + var ids = this.getBindingIdentifiers(); -renameVisitor.AssignmentExpression = -renameVisitor.Declaration = function (node, parent, scope, state) { - var ids = this.getBindingIdentifiers(); - - for (var name in ids) { - if (name === state.oldName) ids[name].name = state.newName; + for (var name in ids) { + if (name === state.oldName) ids[name].name = state.newName; + } } }; @@ -237,11 +232,13 @@ export default class Scope { /** * Globals. */ + static globals = flatten([globals.builtin, globals.browser, globals.node].map(Object.keys)); /** * Variables available in current context. */ + static contextVariables = [ "arguments", "undefined", @@ -555,14 +552,7 @@ export default class Scope { var ids = left.getBindingIdentifiers(); for (var name in ids) { var binding = this.getBinding(name); - if (!binding) continue; - - if (right) { - var rightType = right.typeAnnotation; - if (rightType && binding.isCompatibleWithType(rightType)) continue; - } - - binding.reassign(root, left, right); + if (binding) binding.reassign(root, left, right); } }