@@ -57,6 +57,10 @@ export default function renderToString(vnode, context, opts, inner) {
5757 let pretty = opts . pretty ,
5858 indentChar = typeof pretty === 'string' ? pretty : '\t' ;
5959
60+ if ( vnode == null ) {
61+ return '<!---->' ;
62+ }
63+
6064 // #text nodes
6165 if ( ! nodeName ) {
6266 return encodeEntities ( vnode ) ;
@@ -153,31 +157,31 @@ export default function renderToString(vnode, context, opts, inner) {
153157 s += html ;
154158 }
155159 else {
156- let len = children && children . length ;
157- if ( len ) {
158- let pieces = [ ] ,
159- hasLarge = ~ s . indexOf ( '\n' ) ;
160- for ( let i = 0 ; i < len ; i ++ ) {
161- let child = children [ i ] ;
162- if ( ! falsey ( child ) ) {
163- let ret = renderToString ( child , context , opts , true ) ;
164- if ( ! hasLarge && pretty && isLargeString ( ret ) ) hasLarge = true ;
165- pieces . push ( ret ) ;
166- }
160+ let len = children && children . length ,
161+ pieces = [ ] ,
162+ hasLarge = ~ s . indexOf ( '\n' ) ;
163+ for ( let i = 0 ; i < len ; i ++ ) {
164+ let child = children [ i ] ;
165+ if ( ! falsey ( child ) ) {
166+ let ret = renderToString ( child , context , opts , true ) ;
167+ if ( ! hasLarge && pretty && isLargeString ( ret ) ) hasLarge = true ;
168+ pieces . push ( ret ) ;
167169 }
168- if ( hasLarge ) {
169- for ( let i = pieces . length ; i -- ; ) {
170- pieces [ i ] = '\n' + indentChar + indent ( pieces [ i ] , indentChar ) ;
171- }
170+ }
171+ if ( hasLarge ) {
172+ for ( let i = pieces . length ; i -- ; ) {
173+ pieces [ i ] = '\n' + indentChar + indent ( pieces [ i ] , indentChar ) ;
172174 }
175+ }
176+ if ( pieces . length ) {
173177 s += pieces . join ( '' ) ;
174178 }
175179 else if ( opts && opts . xml ) {
176180 return s . substring ( 0 , s . length - 1 ) + ' />' ;
177181 }
178182 }
179183
180- if ( VOID_ELEMENTS . indexOf ( nodeName ) === - 1 ) {
184+ if ( opts . jsx || VOID_ELEMENTS . indexOf ( nodeName ) === - 1 ) {
181185 if ( pretty && ~ s . indexOf ( '\n' ) ) s += '\n' ;
182186 s += `</${ nodeName } >` ;
183187 }
0 commit comments