Skip to content

Commit

Permalink
Correctly parse consecutive semicolons
Browse files Browse the repository at this point in the history
  • Loading branch information
raskad committed Jan 14, 2023
1 parent 390d7c0 commit 4f74bd7
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
31 changes: 23 additions & 8 deletions boa_engine/src/bytecompiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -643,12 +643,20 @@ impl<'b, 'icu> ByteCompiler<'b, 'icu> {
use_expr: bool,
configurable_globals: bool,
) -> JsResult<()> {
if let Some((last, items)) = list.statements().split_last() {
for node in items {
self.compile_stmt_list_item(node, false, configurable_globals)?;
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() {
self.compile_stmt_list_item(item, false, configurable_globals)?;
} else {
self.compile_stmt_list_item(item, use_expr, configurable_globals)?;
}
self.compile_stmt_list_item(last, use_expr, configurable_globals)?;
}

Ok(())
}

Expand All @@ -664,11 +672,18 @@ impl<'b, 'icu> ByteCompiler<'b, 'icu> {

self.create_decls(list, true);

if let Some((last, items)) = list.statements().split_last() {
for node in items {
self.compile_stmt_list_item(node, false, 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() {
self.compile_stmt_list_item(item, false, true)?;
} else {
self.compile_stmt_list_item(item, use_expr, true)?;
}
self.compile_stmt_list_item(last, use_expr, true)?;
}

let (num_bindings, compile_environment) = self.context.pop_compile_time_environment();
Expand Down
3 changes: 0 additions & 3 deletions boa_parser/src/parser/statement/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ where
}

items.push(item);

// move the cursor forward for any consecutive semicolon.
while cursor.next_if(Punctuator::Semicolon, interner)?.is_some() {}
}

items.sort_by(ast::StatementListItem::hoistable_order);
Expand Down

0 comments on commit 4f74bd7

Please sign in to comment.