@@ -32,7 +32,9 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
3232 let out = `<${ tagName } ` ;
3333 let props = formatProps ( ReactElement . props ) ;
3434 let attributes = [ ] ;
35- let children = ReactElement . props . children ;
35+ let children = React . Children . toArray ( ReactElement . props . children )
36+ . filter ( onlyMeaningfulChildren )
37+ . map ( displayWhitespace ) ;
3638
3739 if ( ReactElement . ref !== null ) {
3840 attributes . push ( getJSXAttribute ( 'ref' , ReactElement . ref ) ) ;
@@ -60,7 +62,7 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
6062 out += `\n${ spacer ( lvl ) } ` ;
6163 }
6264
63- if ( React . Children . count ( children ) > 0 ) {
65+ if ( children . length > 0 ) {
6466 out += `>` ;
6567 lvl ++ ;
6668 if ( ! inline ) {
@@ -71,8 +73,7 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
7173 if ( typeof children === 'string' ) {
7274 out += children ;
7375 } else {
74- out += React . Children
75- . toArray ( children )
76+ out += children
7677 . reduce ( mergePlainStringChildren , [ ] )
7778 . map (
7879 recurse ( { lvl, inline} )
@@ -187,3 +188,15 @@ function spacer(times) {
187188function noChildren ( propName ) {
188189 return propName !== 'children' ;
189190}
191+
192+ function onlyMeaningfulChildren ( children ) {
193+ return children !== true && children !== false && children !== null ;
194+ }
195+
196+ function displayWhitespace ( children ) {
197+ if ( children === ' ' ) {
198+ return '<whitespace>' ;
199+ }
200+
201+ return children ;
202+ }
0 commit comments