Skip to content

Commit 539b9b8

Browse files
NekRdevelopit
authored andcommitted
Fix softof components use children without args (#4)
1 parent f7489d9 commit 539b9b8

2 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/vhtml.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default function h(name, attrs) {
1515

1616
// Sortof component support!
1717
if (typeof name==='function') {
18-
if (attrs) attrs.children = stack.reverse();
18+
(attrs || (attrs = {})).children = stack.reverse();
1919
return name(attrs);
2020
// return name(attrs, stack.reverse());
2121
}

test/vhtml.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,57 @@ describe('vhtml', () => {
7878
);
7979
});
8080

81+
it('should support sortof components without args', () => {
82+
let items = ['one', 'two'];
83+
84+
const Item = () => (
85+
<li>
86+
<h4></h4>
87+
</li>
88+
);
89+
90+
expect(
91+
<div class="foo">
92+
<h1>Hi!</h1>
93+
<ul>
94+
{ items.map( (item, index) => (
95+
<Item>
96+
This is item {item}!
97+
</Item>
98+
)) }
99+
</ul>
100+
</div>
101+
).to.equal(
102+
`<div class="foo"><h1>Hi!</h1><ul><li><h4></h4></li><li><h4></h4></li></ul></div>`
103+
);
104+
});
105+
106+
it('should support sortof components without args but with children', () => {
107+
let items = ['one', 'two'];
108+
109+
const Item = ({ children }) => (
110+
<li>
111+
<h4></h4>
112+
{children}
113+
</li>
114+
);
115+
116+
expect(
117+
<div class="foo">
118+
<h1>Hi!</h1>
119+
<ul>
120+
{ items.map( (item, index) => (
121+
<Item>
122+
This is item {item}!
123+
</Item>
124+
)) }
125+
</ul>
126+
</div>
127+
).to.equal(
128+
`<div class="foo"><h1>Hi!</h1><ul><li><h4></h4>This is item one!</li><li><h4></h4>This is item two!</li></ul></div>`
129+
);
130+
});
131+
81132
it('should support empty (void) tags', () => {
82133
expect(
83134
<div>

0 commit comments

Comments
 (0)