I know of this type of thing:
<https://github.com/karaxnim/karax/blob/master/tests/nativehtmlgen.nim>
I covered it in one of my videos; IIRC. The catch is that you are not compiling
to html/js; but compiling to an executable that, in turn, generates the html.
Using the above file as an example. Can you think of a way that line 24 could
be rewritten from
a(href = "#/", onclick = "javascript:myFunc()"):
text"haha"
Run
To something like:
a(href = "#/", onclick = myFunc(1, 2, 3)):
text"haha"
Run
And then in the somehow let the system know about the JS nim file; something
like
includelib "myfunctions.nim"
Run
And then in `myfunctions.nim`:
export myFunc
proc myFunc(int a, int b, int c) =
var answer = a + b + c
if answer > 20:
document.getElementById(otherPlace).style.color = "red"
Run
And the scripting / compiler / macros would verify that the `onclick` is
correctly calling the function with three integers. And the function is using a
legit element id (`otherPlace`)?
A pipe dream? Or is it perhaps possible with lots of work and a very meta set
of libraries and utilities?