@@ -31,6 +31,10 @@ export class Node {
3131 nodeType : number ;
3232 nodeName: string ;
3333 nodeValue: string ;
34+ childNodes: ?Array < Node > ;
35+ toString ( isXHTML : ?boolean ) : string {
36+ return isXHTML ? '' : '' ;
37+ }
3438}
3539
3640export class TextNode extends Node {
@@ -41,7 +45,8 @@ export class TextNode extends Node {
4145 this . nodeValue = value ;
4246 }
4347
44- toString ( ) : string {
48+ // eslint-disable-next-line no-unused-vars
49+ toString ( isXHTML : ?boolean ) : string {
4550 return escape ( this . nodeValue ) ;
4651 }
4752}
@@ -50,7 +55,7 @@ export class ElementNode extends Node {
5055 _name : string ;
5156 _attrMap : Map < string , Attr > ;
5257 _isSelfClosing : boolean ;
53- childNodes : Array < Node > ;
58+ childNodes : ? Array < Node > ;
5459 attributes : AttrList ;
5560
5661 constructor ( name : string , attributes : ?AttrList , childNodes : ?Array < Node > ) {
@@ -72,14 +77,10 @@ export class ElementNode extends Node {
7277 }
7378
7479 appendChild ( node : Node ) {
75- if ( node . nodeType === NODE_TYPE_FRAGMENT ) {
76- if ( node . childNodes != null ) {
77- // $FlowIssue - Flow doesn't realize that node is a FragmentNode.
78- let childNodes : Array < Node > = node . childNodes ;
79- this . childNodes . push ( ...childNodes ) ;
80- }
80+ if ( node . nodeType === NODE_TYPE_FRAGMENT && node . childNodes ) {
81+ this . childNodes && this . childNodes . push ( ...node . childNodes ) ;
8182 } else {
82- this . childNodes . push ( node ) ;
83+ this . childNodes && this . childNodes . push ( node ) ;
8384 }
8485 }
8586
@@ -108,23 +109,16 @@ export class ElementNode extends Node {
108109 return '<' + this . _name + attrString + ( isXHTML ? '/>' : '>' ) ;
109110 }
110111 let childNodes = this . childNodes
111- . map ( ( node ) => node . toString ( isXHTML ) )
112- . join ( '' ) ;
112+ ? this . childNodes . map ( ( node ) => node . toString ( isXHTML ) ) . join ( '' )
113+ : '' ;
113114 return (
114- '<' +
115- this . _name +
116- attrString +
117- '>' +
118- childNodes +
119- '</' +
120- this . _name +
121- '>'
115+ '<' + this . _name + attrString + '>' + childNodes + '</' + this . _name + '>'
122116 ) ;
123117 }
124118}
125119
126120export class FragmentNode extends Node {
127- childNodes : Array < Node > ;
121+ childNodes : ? Array < Node > ;
128122
129123 constructor ( childNodes : Array < Node > ) {
130124 super ( ...arguments ) ;
@@ -136,19 +130,18 @@ export class FragmentNode extends Node {
136130 }
137131
138132 appendChild ( node : Node ) {
139- if ( node . nodeType === NODE_TYPE_FRAGMENT ) {
140- if ( node . childNodes != null ) {
141- // $FlowIssue - Flow doesn't realize that node is a FragmentNode.
142- let childNodes : Array < Node > = node . childNodes ;
143- this . childNodes . push ( ...childNodes ) ;
144- }
133+ if ( node . nodeType === NODE_TYPE_FRAGMENT && node . childNodes ) {
134+ this . childNodes && this . childNodes . push ( ...node . childNodes ) ;
145135 } else {
146- this . childNodes . push ( node ) ;
136+ this . childNodes && this . childNodes . push ( node ) ;
147137 }
148138 }
149139
150140 toString ( isXHTML : ?boolean ) : string {
151- return this . childNodes . map ( ( node ) => node . toString ( isXHTML ) ) . join ( '' ) ;
141+ let childNodes = this . childNodes ;
142+ return childNodes
143+ ? childNodes . map ( ( node ) => node . toString ( isXHTML ) ) . join ( '' )
144+ : '' ;
152145 }
153146}
154147
0 commit comments