diff options
author | René Kijewski <rene.kijewski@fu-berlin.de> | 2023-08-01 03:38:56 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-08-01 13:04:41 +0200 |
commit | 26f598c0d189769952b11ea9fe6168718f403590 (patch) | |
tree | b8cab7749e993fd24c8d7abc7a126a1862a87c76 /askama_derive/src/generator.rs | |
parent | 108c4a6a33a9eeda3ecf76e5e09da5ccb9b188e8 (diff) | |
download | askama-26f598c0d189769952b11ea9fe6168718f403590.tar.gz askama-26f598c0d189769952b11ea9fe6168718f403590.tar.bz2 askama-26f598c0d189769952b11ea9fe6168718f403590.zip |
parser: add type for `Node::BlockDef`
Diffstat (limited to '')
-rw-r--r-- | askama_derive/src/generator.rs | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 60ffa27..beb3c49 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -650,8 +650,8 @@ impl<'a> Generator<'a> { Node::Loop(ref loop_block) => { size_hint += self.write_loop(ctx, buf, loop_block)?; } - Node::BlockDef(ws1, name, _, ws2) => { - size_hint += self.write_block(buf, Some(name), Ws(ws1.0, ws2.1))?; + Node::BlockDef(ref b) => { + size_hint += self.write_block(buf, Some(b.name), Ws(b.ws1.0, b.ws2.1))?; } Node::Include(ws, path) => { size_hint += self.handle_include(ctx, buf, ws, path)?; @@ -1163,26 +1163,18 @@ impl<'a> Generator<'a> { // Get the block definition from the heritage chain let heritage = self .heritage - .as_ref() .ok_or_else(|| CompileError::from("no block ancestors available"))?; - let (ctx, def) = heritage.blocks[cur.0].get(cur.1).ok_or_else(|| { + let (ctx, def) = *heritage.blocks[cur.0].get(cur.1).ok_or_else(|| { CompileError::from(match name { None => format!("no super() block found for block '{}'", cur.0), Some(name) => format!("no block found for name '{name}'"), }) })?; - // Get the nodes and whitespace suppression data from the block definition - let (ws1, nodes, ws2) = if let Node::BlockDef(ws1, _, nodes, ws2) = def { - (ws1, nodes, ws2) - } else { - unreachable!() - }; - // Handle inner whitespace suppression spec and process block nodes - self.prepare_ws(*ws1); + self.prepare_ws(def.ws1); self.locals.push(); - let size_hint = self.handle(ctx, nodes, buf, AstLevel::Block)?; + let size_hint = self.handle(ctx, &def.nodes, buf, AstLevel::Block)?; if !self.locals.is_current_empty() { // Need to flush the buffer before popping the variable stack @@ -1190,7 +1182,7 @@ impl<'a> Generator<'a> { } self.locals.pop(); - self.flush_ws(*ws2); + self.flush_ws(def.ws2); // Restore original block context and set whitespace suppression for // succeeding whitespace according to the outer WS spec |