Skip to content

Commit 4f5f8f5

Browse files
ikarienatorBei Zhang
authored andcommitted
VariableDeclarationStatment in ForInStatement can only has one VariableDeclarator.
1 parent a57c8c4 commit 4f5f8f5

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

index.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -272,8 +272,14 @@ function errorsP(state) {
272272
errors.push(new E(node, "ForInStatement `right` member must be an expression node"));
273273
if (!isStatement(node.body))
274274
errors.push(new E(node, "ForInStatement `body` member must be a statement node"));
275-
if (node.left != null)
275+
if (node.left != null) {
276+
if (node.left.type === "VariableDeclaration") {
277+
if (node.left.declarations == null || node.left.declarations.length !== 1) {
278+
errors.push(new E(node, "VariableDeclaration `declarations` member must contain exactly one child inside the `left` member of a ForInStatement"));
279+
}
280+
}
276281
[].push.apply(errors, recurse(node.left));
282+
}
277283
if (node.right != null)
278284
[].push.apply(errors, recurse(node.right));
279285
if (node.body != null)

test/unit.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,4 +172,7 @@ suite("unit", function() {
172172
invalidStmt(1, {type: "VariableDeclaration", kind: "var", declarations: []});
173173
});
174174

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

0 commit comments

Comments
 (0)