diff --git a/lib/6to5/transformers/constants.js b/lib/6to5/transformers/constants.js index b3c604fd9c..3150f86c62 100644 --- a/lib/6to5/transformers/constants.js +++ b/lib/6to5/transformers/constants.js @@ -9,17 +9,19 @@ exports.ForOfStatement = exports.ForStatement = function (node, parent, file) { var constants = []; - var check = function (node, name) { - if (constants.indexOf(name) >= 0) { - throw file.errorWithNode(node, name + " is read-only"); - } + var check = function (node, names) { + _.each(names, function (name) { + if (constants.indexOf(name) >= 0) { + throw file.errorWithNode(node, name + " is read-only"); + } + }); }; _.each(node.body, function (child) { if (child && t.isVariableDeclaration(child) && child.kind === "const") { _.each(child.declarations, function (declar) { _.each(t.getIds(declar.id), function (name) { - check(declar, name); + check(declar, [name]); constants.push(name); }); @@ -34,10 +36,8 @@ exports.ForStatement = function (node, parent, file) { traverse(node, function (child) { if (child._ignoreConstant) return; - if (t.isVariableDeclarator(child) || t.isFunctionDeclaration(child) || t.isClassDeclaration(child)) { - check(child, child.id.name); - } else if (t.isAssignmentExpression(child)) { - check(child, child.left.name); + if (t.isVariableDeclarator(child) || t.isFunctionDeclaration(child) || t.isClassDeclaration(child) || t.isAssignmentExpression(child)) { + check(child, t.getIds(child)); } }); };