fix(es/parser): Allow initializer of the var of for-in loop in non-strict mode (#5038)

This commit is contained in:
magic-akari 2022-06-25 18:02:43 +08:00 committed by GitHub
parent 8577caf535
commit f238093c3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 1 deletions

View File

@ -1130,7 +1130,7 @@ impl<'a, I: Tokens> Parser<I> {
self.emit_err(d.name.span(), SyntaxError::TooManyVarInForInHead);
}
} else {
if decl.decls[0].init.is_some() {
if (self.ctx().strict || is!(self, "of")) && decl.decls[0].init.is_some() {
self.emit_err(
decl.decls[0].name.span(),
SyntaxError::VarInitializerInForInHead,

View File

@ -353,3 +353,8 @@ fn illegal_language_mode_directive2() {
},
);
}
#[test]
fn parse_non_strict_for_loop() {
script("for (var v1 = 1 in v3) {}");
}

View File

@ -104,6 +104,8 @@ fn add_test<F: FnOnce() + Send + 'static>(
#[cfg(feature = "verify")]
fn error_tests(tests: &mut Vec<TestDescAndFn>) -> Result<(), io::Error> {
const IGNORED_ERROR_TESTS: &[&str] = &[
// pass in script. error in module.
"e3fbcf63d7e43ead.js",
// Old (wrong) tests
"569a2c1bad3beeb2.js",
"3b6f737a4ac948a8.js",