Add string concatenation in attributes, lazy mixin loading, and benchmarks

Features:
- Fix string concatenation in attribute values (e.g., class="btn btn-" + type)
- Lexer now properly captures full expressions with operators
- Runtime evaluates expressions for class attributes

ViewEngine improvements:
- Change mixin loading from eager to lazy (on-demand)
- Mixins are now loaded from mixins directory only when first called
- Template-defined mixins take precedence over directory mixins

Benchmarks:
- Add src/benchmark.zig with three template complexity levels
- Simple: ~150k renders/sec, 6KB memory
- Medium: ~70k renders/sec, 45KB memory
- Complex: ~32k renders/sec, 94KB memory
- Memory leak detection confirms no leaks

Documentation:
- Update CLAUDE.md with lazy mixin loading details
- Document mixin resolution order
This commit is contained in:
2026-01-17 20:01:37 +05:30
parent 05bbad64a4
commit 1fff91d7d9
7 changed files with 606 additions and 117 deletions

View File

@@ -715,3 +715,26 @@ test "Explicit self-closing tag with attributes" {
\\<foo bar="baz" />
);
}
// ─────────────────────────────────────────────────────────────────────────────
// String concatenation in attributes
// ─────────────────────────────────────────────────────────────────────────────
test "Attribute with string concatenation" {
try expectOutput(
\\button(class="btn btn-" + btnType) Click
, .{ .btnType = "secondary" },
\\<button class="btn btn-secondary">Click</button>
);
}
test "Mixin with string concatenation in class" {
try expectOutput(
\\mixin btn(text, btnType="primary")
\\ button(class="btn btn-" + btnType)= text
\\+btn("Click me", "secondary")
, .{},
\\<button class="btn btn-secondary">Click me</button>
);
}