support patterns in constants

This commit is contained in:
Sebastian McKenzie
2014-10-11 23:31:53 +11:00
parent bb9b7455b5
commit 2dbdb9e3a5
5 changed files with 57 additions and 3 deletions

View File

@@ -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";
}