@@ -32,7 +32,9 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
32
32
let out = `<${ tagName } ` ;
33
33
let props = formatProps ( ReactElement . props ) ;
34
34
let attributes = [ ] ;
35
- let children = ReactElement . props . children ;
35
+ let children = React . Children . toArray ( ReactElement . props . children )
36
+ . filter ( onlyMeaningfulChildren )
37
+ . map ( displayWhitespace ) ;
36
38
37
39
if ( ReactElement . ref !== null ) {
38
40
attributes . push ( getJSXAttribute ( 'ref' , ReactElement . ref ) ) ;
@@ -60,7 +62,7 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
60
62
out += `\n${ spacer ( lvl ) } ` ;
61
63
}
62
64
63
- if ( React . Children . count ( children ) > 0 ) {
65
+ if ( children . length > 0 ) {
64
66
out += `>` ;
65
67
lvl ++ ;
66
68
if ( ! inline ) {
@@ -71,8 +73,7 @@ function toJSXString({ReactElement = null, lvl = 0, inline = false}) {
71
73
if ( typeof children === 'string' ) {
72
74
out += children ;
73
75
} else {
74
- out += React . Children
75
- . toArray ( children )
76
+ out += children
76
77
. reduce ( mergePlainStringChildren , [ ] )
77
78
. map (
78
79
recurse ( { lvl, inline} )
@@ -187,3 +188,15 @@ function spacer(times) {
187
188
function noChildren ( propName ) {
188
189
return propName !== 'children' ;
189
190
}
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