From dff815d545b883f64246472cd39b1be0649ad8fe Mon Sep 17 00:00:00 2001 From: Haled Odat Date: Sun, 30 Apr 2023 14:47:01 +0000 Subject: [PATCH] Fix `for-of` expression parsing (#2882) This PR makes parsing of expressions in for-of loops use `AssignmentExpression` expression parsing as defined in the spec. --- .../src/parser/statement/iteration/for_statement.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/boa_parser/src/parser/statement/iteration/for_statement.rs b/boa_parser/src/parser/statement/iteration/for_statement.rs index 15802b682c..2a5c27cc18 100644 --- a/boa_parser/src/parser/statement/iteration/for_statement.rs +++ b/boa_parser/src/parser/statement/iteration/for_statement.rs @@ -10,7 +10,7 @@ use crate::{ lexer::{Error as LexError, TokenKind}, parser::{ - expression::Expression, + expression::{AssignmentExpression, Expression}, statement::declaration::LexicalDeclaration, statement::{variable::VariableDeclarationList, Statement}, AllowAwait, AllowReturn, AllowYield, Cursor, OrAbrupt, ParseResult, TokenParser, @@ -169,8 +169,13 @@ where )?; cursor.advance(interner); - let expr = Expression::new(None, true, self.allow_yield, self.allow_await) - .parse(cursor, interner)?; + let expr = if in_loop { + Expression::new(None, true, self.allow_yield, self.allow_await) + .parse(cursor, interner)? + } else { + AssignmentExpression::new(None, true, self.allow_yield, self.allow_await) + .parse(cursor, interner)? + }; cursor.expect(Punctuator::CloseParen, "for in/of statement", interner)?;