Skip to content

Instantly share code, notes, and snippets.

@zacharycarter
Last active September 12, 2018 14:51
Show Gist options
  • Save zacharycarter/f2baf9ab5c184254eff489a295879222 to your computer and use it in GitHub Desktop.
Save zacharycarter/f2baf9ab5c184254eff489a295879222 to your computer and use it in GitHub Desktop.
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