@@ -25,8 +25,11 @@ export interface AttributeHolder {
2525
2626export class Node extends BaseNode implements ChildrenHolder , AttributeHolder {
2727 name : string ;
28+
2829 attributes : { [ key : string ] : string } ;
30+
2931 children : BaseNode [ ] = [ ] ;
32+
3033 // For simple parameterized values, like [x=y]...[/x]
3134 value ?: string ;
3235
@@ -38,20 +41,25 @@ export class Node extends BaseNode implements ChildrenHolder, AttributeHolder {
3841 }
3942
4043 clone ( ) : Node {
41- const node = new Node ( { name : this . name , attributes : this . attributes , value : this . value } ) ;
42- node . children = this . children . map ( child => child . clone ( ) ) ;
44+ const node = new Node ( {
45+ name : this . name ,
46+ attributes : this . attributes ,
47+ value : this . value ,
48+ } ) ;
49+ node . children = this . children . map ( ( child ) => child . clone ( ) ) ;
4350 return node ;
4451 }
4552
4653 addChild ( child : BaseNode ) : void {
47- if ( child instanceof TextNode ) {
54+ if ( child instanceof TextNode ) {
4855 const previousChild = this . children [ this . children . length - 1 ] ;
49- if ( previousChild instanceof TextNode ) {
56+ if ( previousChild instanceof TextNode ) {
5057 // We flatten the text nodes.
5158 previousChild . text += child . text ;
5259 return ;
5360 }
5461 }
62+
5563 this . children . push ( child . clone ( ) ) ;
5664 }
5765
@@ -63,17 +71,17 @@ export class Node extends BaseNode implements ChildrenHolder, AttributeHolder {
6371 this . attributes [ key ] = value ;
6472 }
6573
66-
6774 toString ( ) : string {
6875 let nodeString = `[${ this . name } ` ;
69- if ( this . value ) {
76+ if ( this . value ) {
7077 nodeString += `=${ this . value } ` ;
7178 }
79+
7280 Object . entries ( this . attributes ) . forEach ( ( [ key , value ] ) => {
7381 nodeString += ` ${ key } =${ value } ` ;
7482 } ) ;
75- nodeString += ']' ;
76- this . children . forEach ( child => {
83+ nodeString += "]" ;
84+ this . children . forEach ( ( child ) => {
7785 nodeString += child . toString ( ) ;
7886 } ) ;
7987 nodeString += `[/${ this . name } ]` ;
@@ -83,7 +91,8 @@ export class Node extends BaseNode implements ChildrenHolder, AttributeHolder {
8391
8492export class TextNode extends BaseNode {
8593 text : string ;
86- name : string = 'TextNode' ;
94+
95+ name = "TextNode" ;
8796
8897 constructor ( text : string ) {
8998 super ( ) ;
@@ -101,6 +110,7 @@ export class TextNode extends BaseNode {
101110
102111export class RootNode extends BaseNode implements ChildrenHolder {
103112 name = "RootNode" ;
113+
104114 children : BaseNode [ ] ;
105115
106116 constructor ( children : BaseNode [ ] = [ ] ) {
@@ -109,34 +119,35 @@ export class RootNode extends BaseNode implements ChildrenHolder {
109119 }
110120
111121 addChild ( child : BaseNode ) : void {
112- if ( child instanceof TextNode ) {
122+ if ( child instanceof TextNode ) {
113123 const previousChild = this . children [ this . children . length - 1 ] ;
114- if ( previousChild instanceof TextNode ) {
124+ if ( previousChild instanceof TextNode ) {
115125 // We flatten the text nodes.
116126 previousChild . text += child . text ;
117127 return ;
118128 }
119129 }
130+
120131 this . children . push ( child . clone ( ) ) ;
121132 }
122133
123134 clone ( ) : RootNode {
124- return new RootNode ( this . children . map ( child => child . clone ( ) ) ) ;
135+ return new RootNode ( this . children . map ( ( child ) => child . clone ( ) ) ) ;
125136 }
126137
127138 toString ( ) : string {
128- return this . children . map ( child => child . toString ( ) ) . join ( '' ) ;
139+ return this . children . map ( ( child ) => child . toString ( ) ) . join ( "" ) ;
129140 }
130141}
131142
132143export class ListItemNode extends RootNode {
133144 name = "*" ;
134145
135146 toString ( ) : string {
136- return " [*]" + super . toString ( ) ;
147+ return ` [*]${ super . toString ( ) } ` ;
137148 }
138149
139150 clone ( ) : ListItemNode {
140- return new ListItemNode ( this . children . map ( child => child . clone ( ) ) ) ;
151+ return new ListItemNode ( this . children . map ( ( child ) => child . clone ( ) ) ) ;
141152 }
142153}
0 commit comments