fix for-in loop parsing (#2144)

This commit is contained in:
Alex Lam S.L
2017-06-23 04:14:30 +08:00
committed by GitHub
parent f67a6b0e43
commit 0692435f01
4 changed files with 44 additions and 2 deletions

View File

@@ -1010,8 +1010,12 @@ function parse($TEXT, options) {
? (next(), var_(true))
: expression(true, true);
if (is("operator", "in")) {
if (init instanceof AST_Var && init.definitions.length > 1)
croak("Only one variable declaration allowed in for..in loop");
if (init instanceof AST_Var) {
if (init.definitions.length > 1)
croak("Only one variable declaration allowed in for..in loop", init.start.line, init.start.col, init.start.pos);
} else if (!is_assignable(init)) {
croak("Invalid left-hand side in for..in loop", init.start.line, init.start.col, init.start.pos);
}
next();
return for_in(init);
}