Parser - Re-use for loop body if it's a block and an incr statement is needed
This commit is contained in:
parent
f95fcc4e3e
commit
b9e659350b
1 changed files with 8 additions and 4 deletions
|
@ -236,10 +236,14 @@ impl Parser {
|
|||
// inside a specific block if the initializer declares a variable.
|
||||
let body_stmt = self.parse_statement()?;
|
||||
let body_with_incr = if let Some(incr) = increment {
|
||||
ast::StmtNode::Block(vec![
|
||||
Box::new(body_stmt),
|
||||
Box::new(ast::StmtNode::Expression(incr)),
|
||||
])
|
||||
let incr_stmt = Box::new(ast::StmtNode::Expression(incr));
|
||||
let body_block = if let ast::StmtNode::Block(mut body_block) = body_stmt {
|
||||
body_block.push(incr_stmt);
|
||||
body_block
|
||||
} else {
|
||||
vec![Box::new(body_stmt), incr_stmt]
|
||||
};
|
||||
ast::StmtNode::Block(body_block)
|
||||
} else {
|
||||
body_stmt
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue