support duplicate constants within different block scopes - fixes #161
This commit is contained in:
parent
682806f1ca
commit
58fac2e2be
@ -9,11 +9,12 @@ exports.ForOfStatement =
|
||||
exports.ForStatement = function (node, parent, file) {
|
||||
var constants = [];
|
||||
|
||||
var check = function (node, names) {
|
||||
var check = function (node, names, parent) {
|
||||
_.each(names, function (name) {
|
||||
if (constants.indexOf(name) >= 0) {
|
||||
throw file.errorWithNode(node, name + " is read-only");
|
||||
}
|
||||
if (!_.has(constants, name)) return;
|
||||
if (t.isBlockStatement(parent) && parent !== constants[name]) return;
|
||||
|
||||
throw file.errorWithNode(node, name + " is read-only");
|
||||
});
|
||||
};
|
||||
|
||||
@ -21,12 +22,12 @@ exports.ForStatement = function (node, parent, file) {
|
||||
return t.getIds(node, false, ["MemberExpression"]);
|
||||
};
|
||||
|
||||
_.each(node.body, function (child) {
|
||||
_.each(node.body, function (child, parent) {
|
||||
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
|
||||
_.each(child.declarations, function (declar) {
|
||||
_.each(getIds(declar), function (name) {
|
||||
check(declar, [name]);
|
||||
constants.push(name);
|
||||
check(declar, [name], parent);
|
||||
constants[name] = parent;
|
||||
});
|
||||
|
||||
declar._ignoreConstant = true;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user