bugfix: resolve with macro with call after caller

https://github.com/askama-rs/askama/issues/467

Signed-off-by: Michael Pollind <mpollind@gmail.com>
This commit is contained in:
Michael Pollind 2025-06-01 11:16:06 -07:00 committed by René Kijewski
parent 0e30499f59
commit df54534ae6
2 changed files with 22 additions and 1 deletions

View File

@ -779,7 +779,7 @@ impl<'a> Generator<'a, '_> {
})?;
self.prepare_ws(ws2);
self.seen_callers.pop();
self.active_caller = None;
self.active_caller = self.seen_callers.last().map(|v| v.0);
Ok(size_hint)
}

View File

@ -254,6 +254,27 @@ fn test_caller_expr() {
assert_eq!(MacroCallerExpr.render().unwrap(), "20 1 35\n");
}
#[test]
fn test_caller_in_macro_call_before_caller() {
#[derive(Template)]
#[template(
source = r#"
{%- macro test2() -%}
a
{{- caller() -}}
{%- endmacro -%}
{%- macro test() -%}
{%- call test2() -%}b{%- endcall -%}
{{- caller() -}}
{%- endmacro -%}
{%- call test() -%}{%- call test2() -%}b{%- endcall -%}{%- endcall -%}
"#,
ext = "txt"
)]
struct CallerWithMacro;
assert_eq!(CallerWithMacro.render().unwrap(), "abab");
}
#[test]
fn test_caller_in_caller() {
#[derive(Template)]