From 128c13752a502c6eeb8f12b26be9ed6195a2fc81 Mon Sep 17 00:00:00 2001 From: Haled Odat <8566042+HalidOdat@users.noreply.github.com> Date: Mon, 8 May 2023 22:59:12 +0200 Subject: [PATCH] Allow `let` name in for-in loop in non-strict mode (#2915) --- .../parser/statement/iteration/for_statement.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/boa_parser/src/parser/statement/iteration/for_statement.rs b/boa_parser/src/parser/statement/iteration/for_statement.rs index 2a5c27cc18..3c839d727b 100644 --- a/boa_parser/src/parser/statement/iteration/for_statement.rs +++ b/boa_parser/src/parser/statement/iteration/for_statement.rs @@ -116,7 +116,21 @@ where .into(), ) } - TokenKind::Keyword((Keyword::Let | Keyword::Const, _)) => Some( + TokenKind::Keyword((Keyword::Let, _)) => Some('exit: { + if !cursor.strict() { + if let Some(token) = cursor.peek(1, interner)? { + if token.kind() == &TokenKind::Keyword((Keyword::In, false)) { + cursor.advance(interner); + break 'exit boa_ast::Expression::Identifier(Sym::LET.into()).into(); + } + } + } + + LexicalDeclaration::new(false, self.allow_yield, self.allow_await, true) + .parse(cursor, interner)? + .into() + }), + TokenKind::Keyword((Keyword::Const, _)) => Some( LexicalDeclaration::new(false, self.allow_yield, self.allow_await, true) .parse(cursor, interner)? .into(),