-
-
Save zacharycarter/f2baf9ab5c184254eff489a295879222 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
proc wire(...) = # declared somewhere else | |
macro class(name, definition: untyped): untyped = | |
... | |
var | |
this = genSym(nskVar, "this") | |
toInject = quote do: | |
var `this` {.importc, nodecl.}: JsObject | |
wire(`this`) # I'm just hardcoding this for now | |
let jsClassDef = """ | |
class Rectangle { | |
constructor(width, height) { | |
this.width = width; | |
this.height = height; | |
} | |
render() { | |
$1 | |
} | |
}; | |
""" | |
var ls = genSym(nskLet) | |
result = newStmtList.add( | |
newLetStmt( | |
ls, | |
newCall( | |
bindSym"%", | |
newStrLitNode(jsClassDef.unindent()), | |
toStrLit(toInject) | |
) | |
), | |
nnkPragma.newTree( | |
nnkExprColonExpr.newTree( | |
ident"emit", | |
# How do I place the value assigned to ls here?!?!?!? | |
) | |
) | |
) | |
when isMainModule: | |
class Rectangle: | |
width: int | |
height: int | |
constructor: | |
this.width = width | |
this.height = height | |
proc render(): Element = | |
return ${wire(this)}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment