support patterns in constants
This commit is contained in:
@@ -18,11 +18,33 @@ exports.ForStatement = function (node) {
|
||||
_.each(node.body, function (child) {
|
||||
if (child && child.type === "VariableDeclaration" && child.kind === "const") {
|
||||
_.each(child.declarations, function (declar) {
|
||||
var name = declar.id.name;
|
||||
check(declar, name);
|
||||
var search = [declar.id];
|
||||
var names = [];
|
||||
|
||||
while (search.length) {
|
||||
var id = search.shift();
|
||||
|
||||
if (id.type === "Identifier") {
|
||||
names.push(id.name);
|
||||
} else if (id.type === "ArrayPattern") {
|
||||
_.each(id.elements, function (elem) {
|
||||
search.push(elem);
|
||||
});
|
||||
} else if (id.type === "ObjectPattern") {
|
||||
_.each(id.properties, function (prop) {
|
||||
search.push(prop.value);
|
||||
});
|
||||
} else {
|
||||
throw new Error("unknown node " + id.type);
|
||||
}
|
||||
}
|
||||
|
||||
_.each(names, function (name) {
|
||||
check(declar, name);
|
||||
constants.push(name);
|
||||
});
|
||||
|
||||
declar._ignoreConstant = true;
|
||||
constants.push(name);
|
||||
});
|
||||
child.kind = "let";
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user