@@ -3,6 +3,7 @@ var attributesToProps = require('./attributes-to-props');
33var utilities = require ( './utilities' ) ;
44
55var setStyleProp = utilities . setStyleProp ;
6+ var canTextBeChildOfNode = utilities . canTextBeChildOfNode ;
67
78/**
89 * Converts DOM nodes to JSX element(s).
@@ -23,11 +24,11 @@ function domToReact(nodes, options) {
2324
2425 var result = [ ] ;
2526 var node ;
27+ var isWhitespace ;
2628 var hasReplace = typeof options . replace === 'function' ;
2729 var replaceElement ;
2830 var props ;
2931 var children ;
30- var data ;
3132 var trim = options . trim ;
3233
3334 for ( var i = 0 , len = nodes . length ; i < len ; i ++ ) {
@@ -51,15 +52,23 @@ function domToReact(nodes, options) {
5152 }
5253
5354 if ( node . type === 'text' ) {
54- // if trim option is enabled, skip whitespace text nodes
55- if ( trim ) {
56- data = node . data . trim ( ) ;
57- if ( data ) {
58- result . push ( node . data ) ;
59- }
60- } else {
61- result . push ( node . data ) ;
55+ isWhitespace = ! node . data . trim ( ) . length ;
56+
57+ if ( isWhitespace && node . parent && ! canTextBeChildOfNode ( node . parent ) ) {
58+ // We have a whitespace node that can't be nested in it's parent
59+ // so skip it
60+ continue ;
6261 }
62+
63+ if ( trim && isWhitespace ) {
64+ // Trim is enabled and we have a whitespace node
65+ // so skip it
66+ continue ;
67+ }
68+
69+ // We have a text node thats not whitespace and it can be nested
70+ // in its parent so add it to the results
71+ result . push ( node . data ) ;
6372 continue ;
6473 }
6574
0 commit comments