make it illegal to use destructuring outside of an ExpressionStatement
This commit is contained in:
parent
d5f47f4f4d
commit
2b458ec2d4
@ -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", {
|
||||
|
||||
3
test/fixtures/transformation/for-of/illegal-left/actual.js
vendored
Normal file
3
test/fixtures/transformation/for-of/illegal-left/actual.js
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
for (foo.bar of test) {
|
||||
|
||||
}
|
||||
3
test/fixtures/transformation/for-of/illegal-left/options.json
vendored
Normal file
3
test/fixtures/transformation/for-of/illegal-left/options.json
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
{
|
||||
"throws": "Unknown node type MemberExpression in ForOfStatement"
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user