Skip to content

Commit

Permalink
solve some issues of .hpx files
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Dec 3, 2023
1 parent b755613 commit 4b1e7f2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 0 additions & 2 deletions src/happyx/hpx.nim.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
--noNimblePath
--opt:speed
--app:console
--passC:"-flto"
--passL:"-flto"
-d:release
-w:off
-x:off
Expand Down
23 changes: 22 additions & 1 deletion src/happyx/spa/components.nim
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,8 @@ macro importComponent*(body: untyped): untyped =
proc handle(tag: TagRef, parent: var NimNode) =
var ifStartIndex = -1
for child in tag.children:
# @click, @event, etc
var eventHandlers = newStmtList()
if child.onlyChildren:
child.handle(parent)
elif child.isText:
Expand Down Expand Up @@ -922,7 +924,20 @@ macro importComponent*(body: untyped): untyped =
call.add(newNimNode(nnkExprEqExpr).add(newStrLitNode(key), newStrLitNode(val)))
else:
if call.kind in [nnkElifBranch, nnkOfBranch, nnkElse, nnkForStmt, nnkWhileStmt]:
call[^1][^1].add(newNimNode(nnkExprEqExpr).add(newStrLitNode(key), newStrLitNode(val)))
if key.startsWith("h-on"):
eventHandlers.add(newCall(
newNimNode(nnkPrefix).add(ident"@", ident(key[4..^1])), ident"event", newStmtList(
parseExpr(val)
)
))
else:
call[^1][^1].add(newNimNode(nnkExprEqExpr).add(newStrLitNode(key), newStrLitNode(val)))
elif key.startsWith("h-on"):
eventHandlers.add(newCall(
newNimNode(nnkPrefix).add(ident"@", ident(key[4..^1])), ident"event", newStmtList(
parseExpr(val)
)
))
else:
call.add(newNimNode(nnkExprEqExpr).add(newStrLitNode(key), newStrLitNode(val)))
elif name.len > 0:
Expand Down Expand Up @@ -954,6 +969,12 @@ macro importComponent*(body: untyped): untyped =
raise newException(ValueError, "script language can be javascript or nim only")
else:
call.add(stmts)
if eventHandlers.len > 0:
var stmts = newStmtList()
if call[^1].kind != nnkStmtList:
call.add(newStmtList())
for handler in eventHandlers:
call[^1].add(handler)
if isIfStmt:
if ifStartIndex == -1:
parent.add(newNimNode(nnkIfStmt).add(call))
Expand Down

0 comments on commit 4b1e7f2

Please sign in to comment.