diff --git a/src/babel/transformation/transformers/es6/constants.js b/src/babel/transformation/transformers/es6/constants.js index 4125b68d10..518ee38609 100644 --- a/src/babel/transformation/transformers/es6/constants.js +++ b/src/babel/transformation/transformers/es6/constants.js @@ -1,44 +1,31 @@ import * as messages from "../../../messages"; import * as t from "../../../types"; -var visitor = { - enter(node, parent, scope, state) { - if (this.isAssignmentExpression() || this.isUpdateExpression()) { - var ids = this.getBindingIdentifiers(); +export function AssignmentExpression(node, parent, scope, file) { + var ids = this.getBindingIdentifiers(); - for (var name in ids) { - var id = ids[name]; + for (var name in ids) { + var id = ids[name]; - var constant = state.constants[name]; + var binding = scope.getBinding(name); - // no constant exists - if (!constant) continue; + // no binding exists + if (!binding) continue; - var constantIdentifier = constant.identifier; + // not a constant + if (binding.kind !== "const" && binding.kind !== "module") continue; - // check if the assignment id matches the constant declaration id - // if it does then it was the id used to initially declare the - // constant so we can just ignore it - if (id === constantIdentifier) continue; + // check if the assignment id matches the constant declaration id + // if it does then it was the id used to initially declare the + // constant so we can just ignore it + if (binding.identifier === id) continue; - // check if there's been a local binding that shadows this constant - if (!scope.bindingIdentifierEquals(name, constantIdentifier)) continue; - - throw state.file.errorWithNode(id, messages.get("readOnly", name)); - } - } else if (this.isScope()) { - this.skip(); - } + throw file.errorWithNode(id, messages.get("readOnly", name)); } -}; - -export function Scopable(node, parent, scope, file) { - this.traverse(visitor, { - constants: scope.getAllBindingsOfKind("const", "module"), - file: file - }); } +export { AssignmentExpression as UpdateExpression }; + export function VariableDeclaration(node) { if (node.kind === "const") node.kind = "let"; }