From 5b01e605914a49f0b9e71e7dbe7c17ef1de2c522 Mon Sep 17 00:00:00 2001 From: Christian Vallentin Date: Thu, 3 Dec 2020 21:48:14 +0100 Subject: Fixed whitespace issue when generating if statement (#394) * Fixed #377 --- askama_shared/src/generator.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'askama_shared') diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index ad086a3..6a185c1 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -505,8 +505,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { let mut has_else = false; for (i, &(cws, ref cond, ref nodes)) in conds.iter().enumerate() { self.handle_ws(cws); - if arm_sizes.is_empty() { - flushed += self.write_buf_writable(buf)?; + flushed += self.write_buf_writable(buf)?; + if i > 0 { + self.locals.pop(); } let mut arm_size = 0; @@ -539,14 +540,14 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { self.locals.push(); arm_size += self.handle(ctx, nodes, buf, AstLevel::Nested)?; - arm_size += self.write_buf_writable(buf)?; arm_sizes.push(arm_size); - - self.locals.pop(); } self.handle_ws(ws); + flushed += self.write_buf_writable(buf)?; buf.writeln("}")?; + self.locals.pop(); + if !has_else { arm_sizes.push(0); } -- cgit