From 5924c257e012bfafc6839bb7f82786611df93d21 Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Thu, 8 Dec 2022 02:54:36 -0800 Subject: [PATCH] Ignore captures with name _ --- src/template/lib.zig | 2 ++ src/template/test.tmp.html | 1 + 2 files changed, 3 insertions(+) diff --git a/src/template/lib.zig b/src/template/lib.zig index 1c33d22..029d921 100644 --- a/src/template/lib.zig +++ b/src/template/lib.zig @@ -184,6 +184,7 @@ fn evaluateExpression( } fn AddCapture(comptime Root: type, comptime name: []const u8, comptime Val: type) type { + if (std.mem.eql(u8, name, "_")) return Root; var fields = std.meta.fields(Root) ++ [_]std.builtin.Type.StructField{.{ .name = name, .field_type = Val, @@ -201,6 +202,7 @@ fn AddCapture(comptime Root: type, comptime name: []const u8, comptime Val: type } fn addCapture(root: anytype, comptime name: []const u8, val: anytype) AddCapture(@TypeOf(root), name, @TypeOf(val)) { + if (comptime std.mem.eql(u8, name, "_")) return root; var result = std.mem.zeroInit(AddCapture(@TypeOf(root), name, @TypeOf(val)), root); @field(result, name) = val; return result; diff --git a/src/template/test.tmp.html b/src/template/test.tmp.html index ef41e35..f6e12b3 100644 --- a/src/template/test.tmp.html +++ b/src/template/test.tmp.html @@ -24,6 +24,7 @@ {#if .maybe_foo |$v|}{$v}{#else}null{/if} {#if .maybe_bar |$v|}{$v}{#else}null{/if} + {#if .maybe_foo |$_|}abcd{#else}null{/if}