Skip to content

Commit

Permalink
Return the correct value from a statement list
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jan 21, 2023
1 parent f19467a commit 70ca9d4
Showing 1 changed file with 38 additions and 20 deletions.
58 changes: 38 additions & 20 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -660,17 +660,26 @@ impl<'b, 'host> ByteCompiler<'b, 'host> {
use_expr: bool,
configurable_globals: bool,
) -> JsResult<()> {
let mut items = list
.statements()
.iter()
.filter(|item| item != &&StatementListItem::Statement(Statement::Empty))
.peekable();

while let Some(item) = items.next() {
if items.peek().is_some() {
if use_expr {
let expr_index = list
.statements()
.iter()
.rev()
.skip_while(|item| {
matches!(
item,
&&StatementListItem::Statement(Statement::Empty | Statement::Var(_))
| &&StatementListItem::Declaration(_)
)
})
.count();

for (i, item) in list.statements().iter().enumerate() {
self.compile_stmt_list_item(item, i + 1 == expr_index, configurable_globals)?;
}
} else {
for item in list.statements() {
self.compile_stmt_list_item(item, false, configurable_globals)?;
} else {
self.compile_stmt_list_item(item, use_expr, configurable_globals)?;
}
}

Expand All @@ -689,17 +698,26 @@ impl<'b, 'host> ByteCompiler<'b, 'host> {

self.create_decls(list, true);

let mut items = list
.statements()
.iter()
.filter(|item| item != &&StatementListItem::Statement(Statement::Empty))
.peekable();

while let Some(item) = items.next() {
if items.peek().is_some() {
if use_expr {
let expr_index = list
.statements()
.iter()
.rev()
.skip_while(|item| {
matches!(
item,
&&StatementListItem::Statement(Statement::Empty | Statement::Var(_))
| &&StatementListItem::Declaration(_)
)
})
.count();

for (i, item) in list.statements().iter().enumerate() {
self.compile_stmt_list_item(item, i + 1 == expr_index, true)?;
}
} else {
for item in list.statements() {
self.compile_stmt_list_item(item, false, true)?;
} else {
self.compile_stmt_list_item(item, use_expr, true)?;
}
}

Expand Down

0 comments on commit 70ca9d4

Please sign in to comment.