LibJS: Box StatementKind::While variant

This commit is contained in:
Johan Dahlin 2026-03-22 19:37:43 +01:00 committed by Andreas Kling
parent 3496379d09
commit f29b7ab579
5 changed files with 22 additions and 18 deletions

View file

@ -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<Box<Statement>>,
}
#[derive(Clone, Debug)]
pub struct WhileStatementData {
pub test: Box<Expression>,
pub body: Box<Statement>,
}
// =============================================================================
// Statement enum
// =============================================================================
@ -1481,10 +1487,7 @@ pub enum StatementKind {
// Control flow
If(Box<IfStatementData>),
While {
test: Box<Expression>,
body: Box<Statement>,
},
While(Box<WhileStatementData>),
DoWhile {
test: Box<Expression>,
body: Box<Statement>,

View file

@ -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 } => {

View file

@ -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(_)
);

View file

@ -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, .. } => {

View file

@ -344,10 +344,10 @@ impl Parser<'_> {
self.statement(
start,
StatementKind::While {
StatementKind::While(Box::new(WhileStatementData {
test: Box::new(test),
body: Box::new(body),
},
})),
)
}