Skip to content

Commit 7561567

Browse files
committed
upgrade functional components
1 parent 24f4356 commit 7561567

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

src/happyx/private/macro_utils.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
676676
),
677677
if statement[^1].kind == nnkStmtList:
678678
newStmtList(
679-
newVarStmt(ident"_anonymousTag", newCall("tag", statement[0])),
679+
newVarStmt(ident"_anonymousTag", statement[0]),
680680
newCall(
681681
"add",
682682
ident"_anonymousTag",
@@ -688,7 +688,7 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
688688
ident"_anonymousTag"
689689
)
690690
else:
691-
newCall("tag", statement[0])
691+
statement[0]
692692
),
693693
newNimNode(nnkElifBranch).add(
694694
newCall(
@@ -1159,7 +1159,9 @@ proc buildHtmlProcedure*(root, body: NimNode, inComponent: bool = false,
11591159
"and",
11601160
newCall("declared", statement),
11611161
newCall("is", statement, ident"TagRef")
1162-
), newCall("tag", statement)
1162+
), newStmtList(
1163+
statement
1164+
)
11631165
),
11641166
newNimNode(nnkElifBranch).add(
11651167
newCall(

tests/testjs17.nim

Lines changed: 27 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,46 @@ proc funcComp1(i: State[int], stmt: TagRef): TagRef =
1515
i += 1
1616
stmt
1717

18-
proc funcComp2(i: State[int]): TagRef =
19-
buildHtml:
20-
tDiv:
21-
"comp2, so `i` is {i}"
18+
# proc funcComp2(i: State[int]): TagRef =
19+
# buildHtml:
20+
# tDiv:
21+
# "comp2, so `i` is {i}"
2222

23-
proc funcComp3(): TagRef =
24-
buildHtml:
25-
tDiv:
26-
"comp3 without arguments"
23+
# proc funcComp3(): TagRef =
24+
# buildHtml:
25+
# tDiv:
26+
# "comp3 without arguments"
2727

2828
proc funcComp4(stmt: TagRef): TagRef =
29+
static:
30+
echo declared(stmt) and stmt is TagRef
2931
buildHtml:
3032
tDiv:
3133
"comp4 with body"
3234
stmt
3335

3436

35-
component NormalComp:
36-
i: State[int]
37-
html:
38-
tDiv:
39-
"And this is common component. i is {self.i}"
37+
# component NormalComp:
38+
# i: State[int]
39+
# html:
40+
# tDiv:
41+
# "And this is common component. i is {self.i}"
4042

4143

4244
appRoutes "app":
4345
"/":
4446
tDiv:
45-
"Here is functional components"
46-
funcComp1(someValue):
47-
"This is functional component slot"
48-
funcComp2(someValue)
49-
funcComp3()
50-
funcComp3
47+
# "Here is functional components"
48+
# funcComp1(someValue):
49+
# "This is functional component slot"
50+
# funcComp2(someValue)
51+
# funcComp3()
52+
# funcComp3
5153
funcComp4():
5254
"Hello"
53-
funcComp4:
54-
"world"
55-
NormalComp(someValue)
55+
funcComp1(someValue):
56+
"This is functional component slot"
57+
!debugCurrent
58+
# funcComp4:
59+
# "world"
60+
# NormalComp(someValue)

0 commit comments

Comments
 (0)