Ignore captures with name _

This commit is contained in:
jaina heartles 2022-12-08 02:54:36 -08:00
parent 06b8483a8a
commit 5924c257e0
2 changed files with 3 additions and 0 deletions

View file

@ -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;

View file

@ -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}
<template>{#template test_tmpl .bar}</template>