diff --git a/Libraries/LibJS/Rust/src/ast.rs b/Libraries/LibJS/Rust/src/ast.rs index 5fbc65c825..b4c667f5fb 100644 --- a/Libraries/LibJS/Rust/src/ast.rs +++ b/Libraries/LibJS/Rust/src/ast.rs @@ -162,9 +162,9 @@ impl FunctionTable { self.collect_from_statement(alt, result); } } - StatementKind::While { test, body } => { - self.collect_from_expression(test, result); - self.collect_from_statement(body, result); + StatementKind::While(data) => { + self.collect_from_expression(&data.test, result); + self.collect_from_statement(&data.body, result); } StatementKind::DoWhile { test, body } => { self.collect_from_statement(body, result); @@ -1459,6 +1459,12 @@ pub struct IfStatementData { pub alternate: Option>, } +#[derive(Clone, Debug)] +pub struct WhileStatementData { + pub test: Box, + pub body: Box, +} + // ============================================================================= // Statement enum // ============================================================================= @@ -1481,10 +1487,7 @@ pub enum StatementKind { // Control flow If(Box), - While { - test: Box, - body: Box, - }, + While(Box), DoWhile { test: Box, body: Box, diff --git a/Libraries/LibJS/Rust/src/ast_dump.rs b/Libraries/LibJS/Rust/src/ast_dump.rs index b9362e6a78..3badfd23be 100644 --- a/Libraries/LibJS/Rust/src/ast_dump.rs +++ b/Libraries/LibJS/Rust/src/ast_dump.rs @@ -406,10 +406,10 @@ fn dump_statement(statement: &Statement, state: &DumpState) { } } - StatementKind::While { test, body } => { + StatementKind::While(data) => { dump_node!(state, "WhileStatement", &statement.range); - dump_labeled_expression("test", test, false, state); - dump_labeled_statement("body", body, true, state); + dump_labeled_expression("test", &data.test, false, state); + dump_labeled_statement("body", &data.body, true, state); } StatementKind::DoWhile { test, body } => { diff --git a/Libraries/LibJS/Rust/src/bytecode/codegen.rs b/Libraries/LibJS/Rust/src/bytecode/codegen.rs index 0576b778d3..8e25318fea 100644 --- a/Libraries/LibJS/Rust/src/bytecode/codegen.rs +++ b/Libraries/LibJS/Rust/src/bytecode/codegen.rs @@ -953,8 +953,8 @@ pub fn generate_statement( ), // === While === - StatementKind::While { test, body } => { - generate_while_statement(generator, test, body, preferred_dst) + StatementKind::While(data) => { + generate_while_statement(generator, &data.test, &data.body, preferred_dst) } // === DoWhile === @@ -6688,7 +6688,7 @@ fn generate_labelled_statement( &effective_inner.inner, StatementKind::For { .. } | StatementKind::ForInOf { .. } - | StatementKind::While { .. } + | StatementKind::While(_) | StatementKind::DoWhile { .. } | StatementKind::Switch(_) ); diff --git a/Libraries/LibJS/Rust/src/lib.rs b/Libraries/LibJS/Rust/src/lib.rs index 61f0b21bea..fb10fca1c5 100644 --- a/Libraries/LibJS/Rust/src/lib.rs +++ b/Libraries/LibJS/Rust/src/lib.rs @@ -1954,9 +1954,10 @@ fn for_each_child_statement( f(&alt.inner); } } - StatementKind::While { body, .. } - | StatementKind::DoWhile { body, .. } - | StatementKind::With { body, .. } => { + StatementKind::While(data) => { + f(&data.body.inner); + } + StatementKind::DoWhile { body, .. } | StatementKind::With { body, .. } => { f(&body.inner); } StatementKind::For { init, body, .. } => { diff --git a/Libraries/LibJS/Rust/src/parser/statements.rs b/Libraries/LibJS/Rust/src/parser/statements.rs index 6dc90ea3b3..357ea4af5d 100644 --- a/Libraries/LibJS/Rust/src/parser/statements.rs +++ b/Libraries/LibJS/Rust/src/parser/statements.rs @@ -344,10 +344,10 @@ impl Parser<'_> { self.statement( start, - StatementKind::While { + StatementKind::While(Box::new(WhileStatementData { test: Box::new(test), body: Box::new(body), - }, + })), ) }