From e6e93840a6d9b872ec5bf6b0cd5f22dc89b5228b Mon Sep 17 00:00:00 2001 From: Sebastian McKenzie Date: Tue, 3 Feb 2015 12:03:38 +1100 Subject: [PATCH] check for scope collisions in constants transformer - fixes #331 --- lib/6to5/transformation/transformers/es6/constants.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/6to5/transformation/transformers/es6/constants.js b/lib/6to5/transformation/transformers/es6/constants.js index 1030a290ec..394bf7a49d 100644 --- a/lib/6to5/transformation/transformers/es6/constants.js +++ b/lib/6to5/transformation/transformers/es6/constants.js @@ -6,7 +6,7 @@ var t = require("../../../types"); var visitor = { enter: function (node, parent, scope, context, state) { if (t.isDeclaration(node) || t.isAssignmentExpression(node)) { - var ids = t.getDeclarations(node); + var ids = t.getBindingIdentifiers(node); for (var key in ids) { var id = ids[key]; @@ -21,6 +21,9 @@ var visitor = { // constant so we can just ignore it if (id === constant) continue; + var localBinding = scope.get(key, true); + if (localBinding !== constant) continue; + throw state.file.errorWithNode(id, key + " is read-only"); } } else if (t.isScope(node)) {