make it illegal to use destructuring outside of an ExpressionStatement

This commit is contained in:
Sebastian McKenzie 2014-11-14 00:53:10 +11:00
parent d5f47f4f4d
commit 2b458ec2d4
3 changed files with 11 additions and 5 deletions

View File

@ -5,17 +5,17 @@ exports.ForOfStatement = function (node, parent, file, scope) {
var left = node.left;
var declar;
var stepKey = t.identifier(file.generateUid("step", scope));
var stepValueId = t.memberExpression(stepKey, t.identifier("value"));
var stepKey = t.identifier(file.generateUid("step", scope));
var stepValue = t.memberExpression(stepKey, t.identifier("value"));
if (t.isIdentifier(left)) {
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValueId));
declar = t.expressionStatement(t.assignmentExpression("=", left, stepValue));
} else if (t.isVariableDeclaration(left)) {
declar = t.variableDeclaration(left.kind, [
t.variableDeclarator(left.declarations[0].id, stepValueId)
t.variableDeclarator(left.declarations[0].id, stepValue)
]);
} else {
return;
throw file.errorWithNode(left, "Unknown node type " + left.type + " in ForOfStatement");
}
var node2 = util.template("for-of", {

View File

@ -0,0 +1,3 @@
for (foo.bar of test) {
}

View File

@ -0,0 +1,3 @@
{
"throws": "Unknown node type MemberExpression in ForOfStatement"
}