reject invalid for...of syntax (#4632)

This commit is contained in:
Alex Lam S.L
2021-02-09 21:42:27 +00:00
committed by GitHub
parent 14fedbf123
commit 228cdf8e7e
4 changed files with 91 additions and 44 deletions

View File

@@ -1067,6 +1067,9 @@ function parse($TEXT, options) {
if (init.definitions.length > 1) {
token_error(init.start, "Only one variable declaration allowed in for..in/of loop");
}
if (ctor !== AST_ForIn && init.definitions[0].value) {
token_error(init.definitions[0].value.start, "No initializers allowed in for..of loop");
}
} else if (!(is_assignable(init) || (init = to_destructured(init)) instanceof AST_Destructured)) {
token_error(init.start, "Invalid left-hand side in for..in/of loop");
}