fix: build template bug for same field names
This commit is contained in:
4
examples/demo/views/mixins/input_text.pug
Normal file
4
examples/demo/views/mixins/input_text.pug
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
mixin input_text(name, label, placeholder)
|
||||||
|
fieldset.fieldset
|
||||||
|
legend.fieldset-legend= label
|
||||||
|
input(type="text" name=name class="input" placeholder=placeholder)
|
||||||
@@ -19,3 +19,8 @@ block content
|
|||||||
"data": true
|
"data": true
|
||||||
}
|
}
|
||||||
`)
|
`)
|
||||||
|
form(method="post")
|
||||||
|
+input_text("firstName", "First Name", "first name")
|
||||||
|
br
|
||||||
|
+input_text("lastName", "Last Name", "last name")
|
||||||
|
submit sumit
|
||||||
|
|||||||
@@ -1309,7 +1309,7 @@ const Compiler = struct {
|
|||||||
|
|
||||||
fn emitMixinCallWithDef(self: *Compiler, call: ast.MixinCall, mixin_def: ast.MixinDef) anyerror!void {
|
fn emitMixinCallWithDef(self: *Compiler, call: ast.MixinCall, mixin_def: ast.MixinDef) anyerror!void {
|
||||||
// For each mixin parameter, we need to create a local binding
|
// For each mixin parameter, we need to create a local binding
|
||||||
// This is complex in compiled mode - we inline the mixin body
|
// Wrap in a scope block to avoid variable name collisions when mixin is called multiple times
|
||||||
|
|
||||||
// Save current mixin params
|
// Save current mixin params
|
||||||
const prev_params_len = self.mixin_params.items.len;
|
const prev_params_len = self.mixin_params.items.len;
|
||||||
@@ -1324,6 +1324,11 @@ const Compiler = struct {
|
|||||||
// Emit local variable declarations for mixin parameters
|
// Emit local variable declarations for mixin parameters
|
||||||
try self.flush();
|
try self.flush();
|
||||||
|
|
||||||
|
// Open scope block for mixin variables
|
||||||
|
try self.writeIndent();
|
||||||
|
try self.writer.writeAll("{\n");
|
||||||
|
self.depth += 1;
|
||||||
|
|
||||||
for (mixin_def.params[0..regular_params], 0..) |param, i| {
|
for (mixin_def.params[0..regular_params], 0..) |param, i| {
|
||||||
try self.mixin_params.append(self.allocator, param);
|
try self.mixin_params.append(self.allocator, param);
|
||||||
|
|
||||||
@@ -1386,6 +1391,12 @@ const Compiler = struct {
|
|||||||
try self.emitNode(child);
|
try self.emitNode(child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Close scope block
|
||||||
|
try self.flush();
|
||||||
|
self.depth -= 1;
|
||||||
|
try self.writeIndent();
|
||||||
|
try self.writer.writeAll("}\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Try to load a mixin from the mixins directory
|
/// Try to load a mixin from the mixins directory
|
||||||
|
|||||||
Reference in New Issue
Block a user