From 4f5f8f51531872619b5d357792b7b758e78f0062 Mon Sep 17 00:00:00 2001 From: Bei Zhang Date: Tue, 26 Aug 2014 21:14:40 -0700 Subject: [PATCH] VariableDeclarationStatment in ForInStatement can only has one VariableDeclarator. --- index.js | 8 +++++++- test/unit.js | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 4711dea..9150d46 100644 --- a/index.js +++ b/index.js @@ -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) { + 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) diff --git a/test/unit.js b/test/unit.js index a952452..6c4b3f8 100644 --- a/test/unit.js +++ b/test/unit.js @@ -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}); + }); });