File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 >
You can’t perform that action at this time.
0 commit comments