Hey, I have this html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src="bug.js"></script>
</head>
<body onload="onLoad()">
<div>
<input id="b1" type="button" onclick="setLabel('idp1', 'foo')">
<p id="p1"></p>
</div>
<div>
<input id="b2" type="button">
<p id="p2"></p>
</div>
<div>
<input id="b3" type="button">
<p id="p3"></p>
</div>
</body>
</html>
and the following nim file bugjs.nim:
import dom, sugar
{.push exportc.}
proc setLabel(target: cstring, value: cstring) =
document.getElementById($target).innerHTML = value
proc onLoad() =
for elem in document.getElementsByTagName("input"):
let targetID = "p" & elem.id[1]
capture targetID:
elem.onclick = proc(e: Event) =
document.getElementById(targetID).innerHtml = targetID
{.pop.}
I compile it with nim js -o:bug.js bugjs.nim which produces no errors. But when I open the html in Firefox, I see in the console:
Uncaught SyntaxError: function statement requires a name bug.js:1778:21 > Uncaught ReferenceError: onLoad is not defined > onload file://///wsl$/Ubuntu/home/felix/git/nim_tests/jsbug/example.html:1
It seems like capture and js don't go well together. Is it supposed to be like that? Should I open an issue on Github? Is there a work around?
PS: I use nim 1.4.0