diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index fe42881fd..5230a6d7a 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -133,21 +133,30 @@ impl TemplateInput<'_> { .into()); } dependency_graph.push(dependency_path); - let source = get_template_source(&extends)?; - check.push((extends, source)); + if !map.contains_key(&extends) { + map.insert(extends.clone(), Parsed::default()); + let source = get_template_source(&extends)?; + check.push((extends, source)); + } } Node::Macro(m) if top => { nested.push(&m.nodes); } Node::Import(import) if top => { let import = self.config.find_template(import.path, Some(&path))?; - let source = get_template_source(&import)?; - check.push((import, source)); + if !map.contains_key(&import) { + map.insert(import.clone(), Parsed::default()); + let source = get_template_source(&import)?; + check.push((import, source)); + } } Node::Include(include) => { let include = self.config.find_template(include.path, Some(&path))?; - let source = get_template_source(&include)?; - check.push((include, source)); + if !map.contains_key(&include) { + map.insert(include.clone(), Parsed::default()); + let source = get_template_source(&include)?; + check.push((include, source)); + } } Node::BlockDef(b) => { nested.push(&b.nodes); diff --git a/askama_parser/src/lib.rs b/askama_parser/src/lib.rs index 4d27d7028..e6f133c37 100644 --- a/askama_parser/src/lib.rs +++ b/askama_parser/src/lib.rs @@ -28,6 +28,7 @@ mod _parsed { use super::node::Node; use super::{Ast, ParseError, Syntax}; + #[derive(Default)] pub struct Parsed { // `source` must outlive `ast`, so `ast` must be declared before `source` ast: Ast<'static>, @@ -68,7 +69,7 @@ mod _parsed { pub use _parsed::Parsed; -#[derive(Debug)] +#[derive(Debug, Default)] pub struct Ast<'a> { nodes: Vec>, }