allow constant properties to be modified - fixes #131

This commit is contained in:
Sebastian McKenzie
2014-11-10 13:09:45 +11:00
parent 833e8b091b
commit 8c97f1d92e
2 changed files with 10 additions and 3 deletions

View File

@@ -17,10 +17,14 @@ exports.ForStatement = function (node, parent, file) {
});
};
var getIds = function (node) {
return t.getIds(node, false, ["MemberExpression"]);
};
_.each(node.body, function (child) {
if (child && t.isVariableDeclaration(child, { kind: "const" })) {
_.each(child.declarations, function (declar) {
_.each(t.getIds(declar), function (name) {
_.each(getIds(declar), function (name) {
check(declar, [name]);
constants.push(name);
});
@@ -39,7 +43,7 @@ exports.ForStatement = function (node, parent, file) {
if (child._ignoreConstant) return;
if (t.isVariableDeclarator(child) || t.isDeclaration(child) || t.isAssignmentExpression(child)) {
check(child, t.getIds(child));
check(child, getIds(child));
}
});
};

View File

@@ -156,13 +156,16 @@ t.toBlock = function (node, parent) {
return t.blockStatement(node);
};
t.getIds = function (node, map) {
t.getIds = function (node, map, ignoreTypes) {
ignoreTypes = ignoreTypes || [];
var search = [node];
var ids = {};
while (search.length) {
var id = search.shift();
if (!id) continue;
if (_.contains(ignoreTypes, id.type)) continue;
var nodeKey = t.getIds.nodes[id.type];
var arrKey = t.getIds.arrays[id.type];