Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,14 @@ function errorsP(state) {
errors.push(new E(node, "ForInStatement `right` member must be an expression node"));
if (!isStatement(node.body))
errors.push(new E(node, "ForInStatement `body` member must be a statement node"));
if (node.left != null)
if (node.left != null) {
if (node.left.type === "VariableDeclaration") {
if (node.left.declarations == null || node.left.declarations.length !== 1) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you combine this test with the one above it?

errors.push(new E(node, "VariableDeclaration `declarations` member must contain exactly one child inside the `left` member of a ForInStatement"));
}
}
[].push.apply(errors, recurse(node.left));
}
if (node.right != null)
[].push.apply(errors, recurse(node.right));
if (node.body != null)
Expand Down
3 changes: 3 additions & 0 deletions test/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,4 +172,7 @@ suite("unit", function() {
invalidStmt(1, {type: "VariableDeclaration", kind: "var", declarations: []});
});

test("VariableDeclaration `declarations` member must contain exactly one child inside the `left` member of a ForInStatement", function() {
invalidStmt(1, {type: "ForInStatement", left: {type: "VariableDeclaration", kind: "var", declarations: [{type: "VariableDeclarator", id: ID}, {type: "VariableDeclarator", id: ID}]}, right: EXPR, body: STMT});
});
});