From dfb7cea03794ead892527e19f883dc8a3e784bc7 Mon Sep 17 00:00:00 2001 From: bott Date: Sun, 2 Sep 2018 18:46:45 +0200 Subject: Fix multiple nesting in macro calls into different scopes --- askama_derive/src/generator.rs | 8 +++++--- testing/templates/nested-macro.html | 8 ++++++-- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index b771234..81c0e27 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -427,13 +427,15 @@ impl<'a> Generator<'a> { return; } - let def = if let Some(s) = match scope { + let own_scope = match scope { None => match level { AstLevel::Nested(s) => s, _ => None, }, s => s, - } { + }; + + let def = if let Some(s) = own_scope { let path = ctx .imports .get(s) @@ -464,7 +466,7 @@ impl<'a> Generator<'a> { buf.writeln(&format!("let {} = &{};", arg, expr_code)); self.locals.insert(arg); } - self.handle(ctx, &def.nodes, buf, AstLevel::Nested(scope)); + self.handle(ctx, &def.nodes, buf, AstLevel::Nested(own_scope)); self.flush_ws(buf, def.ws2); buf.writeln("}"); diff --git a/testing/templates/nested-macro.html b/testing/templates/nested-macro.html index 4a40cd9..5030d59 100644 --- a/testing/templates/nested-macro.html +++ b/testing/templates/nested-macro.html @@ -1,7 +1,11 @@ -{%- macro child() -%} +{%- macro child0() -%} foo {%- endmacro -%} +{%- macro child1() -%} + {% call child0() %} +{%- endmacro -%} + {%- macro parent() -%} - {% call child() %} + {% call child1() %} {%- endmacro -%} -- cgit