-
Notifications
You must be signed in to change notification settings - Fork 173
Description
Describe the bug
It looks like vg-template doesn't scope variables correctly - at least for some HTML tags. I've come across this while attempting to build a vg-template example.
The .vugu file looks like this:
<!-- A templated select control that contains a random number of options, each of which is a random number -->
<div id=randomnumbers>
<div >
<label for="randomnumbers">Choose a number:</label>
<!-- When the value changes we call the 'Change' method to read the new value -->
<select name="randomnumbers" id="randomnumbers" @change='c.Change(event)'>
<div id="failure">
<!-- un-comment these three lines to see the failure - see below... -->
<!-- <vg-template vg-for='j:=0; j<c.NumberOfOptions(); j++'> -->
<!-- <option :value='fmt.Sprintf("%d", j)' vg-content='c.Random(j)'></option> -->
<!-- </vg-template> -->
</div>
</select>
</div>
<p>Printing the list as normal...</p><br>
<div id="works">
<!-- this works!?? -->
<vg-template vg-for='j:=0; j<c.NumberOfOptions(); j++'>
<p vg-content='fmt.Sprintf("[%d]=%d", j, c.Random(j))'></p>
</vg-template>
</div>
</div>So this - as above works just fine. Using a vg-template to print a set of <p> tags then all is good.
But, if I un-comment the actual lines that use a vg-template to print a set of <options> I am seeing this:
$ mage singleExample github.com/vugu/vugu/examples/vg-template # github.com/vugu/vugu/examples/vg-template is the module name of the example
....
# github.com/vugu/vugu/examples/vg-template
./templateselect_gen.go:65:53: undefined: j
./templateselect_gen.go:66:31: undefined: j
Error: running "go build -o ./main.wasm github.com/vugu/vugu/examples/vg-template" failed with exit code 1So the error implies that j can't be scoped from the loop in the vg-template to the <option> tag.
But the scoping is clearly OK for <p> tags outside of a <select> tag.
But an <options> tag is only valid inside a <select> tag, so it must be nested.
This is 100% reproducible at code generation time.
Software Versions
Vugu version: All versions as far as I can tell - it is certainly in the current master branch and v0.4.0
Go version: All current Go versions
Browser and version: NA we fail to build.
Expected behavior
We expect j to be scoped in both the <p> tag and <option> tag case.