diff --git a/src/ast/mod.rs b/src/ast/mod.rs index 6160523..46e1add 100644 --- a/src/ast/mod.rs +++ b/src/ast/mod.rs @@ -229,7 +229,6 @@ pub enum TemplateAstExpr<'input> { IfConditional { if_block: Box>, content: Vec>, - end_block: Box>, }, ElseConditional { expression: Vec>, @@ -319,13 +318,10 @@ fn parse_conditional_chain<'input>( let mut chain = vec![]; let (content, end_block): (Vec<_>, _) = - repeat_till(0.., parse_ast, parse_end.map(Box::new)).parse_next(input)?; + repeat_till(0.., parse_ast, parse_end).parse_next(input)?; - chain.push(TemplateAstExpr::IfConditional { - if_block, - content, - end_block, - }); + chain.push(TemplateAstExpr::IfConditional { if_block, content }); + chain.push(end_block); Ok(TemplateAstExpr::ConditionalChain { chain }) }) @@ -519,13 +515,13 @@ mod tests { [Content]"Hiii" (13..17), ), ], - end_block: Block { - prev_whitespace_content: Some( - [Whitespace]" " (17..18), - ), - expression: EndBlock, - post_whitespace_content: None, - }, + }, + Block { + prev_whitespace_content: Some( + [Whitespace]" " (17..18), + ), + expression: EndBlock, + post_whitespace_content: None, }, ], }, diff --git a/src/ast/snapshots/nomo__ast__tests__simple_if_ast.snap b/src/ast/snapshots/nomo__ast__tests__simple_if_ast.snap index 6f99ca6..54438bf 100644 --- a/src/ast/snapshots/nomo__ast__tests__simple_if_ast.snap +++ b/src/ast/snapshots/nomo__ast__tests__simple_if_ast.snap @@ -34,26 +34,26 @@ TemplateAst { [Content]"Hiii" (54..58), ), ], - end_block: Block { - prev_whitespace_content: Some( - [Whitespace]"\n " (58..71), - ), - expression: EndBlock, - post_whitespace_content: Some( - [Whitespace]"\n " (80..89), - ), - }, + }, + Block { + prev_whitespace_content: Some( + [Whitespace]"\n " (58..71), + ), + expression: EndBlock, + post_whitespace_content: Some( + [Whitespace]"\n " (80..89), + ), }, ], }, ], - end_block: Block { - prev_whitespace_content: None, - expression: EndBlock, - post_whitespace_content: Some( - [Whitespace]"\n\n " (98..108), - ), - }, + }, + Block { + prev_whitespace_content: None, + expression: EndBlock, + post_whitespace_content: Some( + [Whitespace]"\n\n " (98..108), + ), }, ], }, diff --git a/src/emit/mod.rs b/src/emit/mod.rs index b7aa055..6928917 100644 --- a/src/emit/mod.rs +++ b/src/emit/mod.rs @@ -93,7 +93,6 @@ fn emit_ast_expr( let Some(TemplateAstExpr::IfConditional { if_block: expression, content, - end_block, }) = chain.next() else { unreachable!("First element in conditional chain should be an IfConditional"); @@ -133,13 +132,13 @@ fn emit_ast_expr( emit_ast_expr(machine, eval, ast); } - let TemplateAstExpr::Block { + let Some(TemplateAstExpr::Block { prev_whitespace_content, post_whitespace_content, .. - } = end_block.as_ref() + }) = chain.last() else { - unreachable!("The end of an IfConditional must be a Block"); + unreachable!("The end of an IfConditional must be a End Block"); }; if let Some(ws) = prev_whitespace_content { diff --git a/tests/cases/2-ast@condition.snap b/tests/cases/2-ast@condition.snap index d1a35fe..90c0914 100644 --- a/tests/cases/2-ast@condition.snap +++ b/tests/cases/2-ast@condition.snap @@ -22,15 +22,15 @@ TemplateAst { [Content]"Hello World!" (18..30), ), ], - end_block: Block { - prev_whitespace_content: Some( - [Whitespace]"\n" (30..31), - ), - expression: EndBlock, - post_whitespace_content: Some( - [Whitespace]"\n\n" (40..42), - ), - }, + }, + Block { + prev_whitespace_content: Some( + [Whitespace]"\n" (30..31), + ), + expression: EndBlock, + post_whitespace_content: Some( + [Whitespace]"\n\n" (40..42), + ), }, ], },