Closed lvignoli closed 1 year ago
Somehow the for loop is captured by the partial handler, but truncated.
Here is the generated code at line 110 of build/index.up.go
func (up *IndexFooPartial) Respond(w http.ResponseWriter, req *http.Request) error {
// Begin user Go code and HTML
{
//line index.up:1
data := []string{"a", "b", "c"}
//line index.up:2
for a, b := range data {
}
//line index.up:11
io.WriteString(w, "\n\t")
//line index.up:11
//line index.up:11
io.WriteString(w, "<p>")
//line index.up:11
io.WriteString(w, "Hey")
io.WriteString(w, "</p>")
// End user Go code and HTML
}
return nil
}
Codegen for partials is a little janky, I expected something like this. Thanks for this report. I think I know the fix but might take a bit of reorganization or additional support code.
@lvignoli this should be fixed by #92. You'll have a separate (expected) issue which is that the template won't compile because the data
variable declared in the Go code block is not used by the partial. If you use it inside the partial then it should be fine.
^partial foo {
<p>Hey ^data[0]</p>
}
Thank you @paulsmith for the quick fix! 😀
In a fresh project from
pushup new
(on commit72be05b
), the following index.up cannot be built:Output error:
Removing the partial fixes the issue.
Observed on a MacBook Pro 2021 (M1 Pro) with macOS 13.1.