@@ -23,7 +23,7 @@ function postHTMLParser(html, options) {
2323
2424 function isDirective ( { name} , tag ) {
2525 if ( name instanceof RegExp ) {
26- const regex = RegExp ( name . source , 'i' ) ;
26+ const regex = new RegExp ( name . source , 'i' ) ;
2727
2828 return regex . test ( tag ) ;
2929 }
@@ -39,8 +39,7 @@ function postHTMLParser(html, options) {
3939 const directives = [ ] . concat ( defaultDirectives , options . directives || [ ] ) ;
4040 const last = bufArray . last ( ) ;
4141
42- for ( let i = 0 ; i < directives . length ; i ++ ) {
43- const directive = directives [ i ] ;
42+ for ( const directive of directives ) {
4443 const directiveText = directive . start + data + directive . end ;
4544
4645 name = name . toLowerCase ( ) ;
@@ -50,7 +49,10 @@ function postHTMLParser(html, options) {
5049 return ;
5150 }
5251
53- last . content || ( last . content = [ ] ) ;
52+ if ( last . content === undefined ) {
53+ last . content = [ ] ;
54+ }
55+
5456 last . content . push ( directiveText ) ;
5557 }
5658 }
@@ -59,9 +61,9 @@ function postHTMLParser(html, options) {
5961 function normalizeArributes ( attrs ) {
6062 const result = { } ;
6163 Object . keys ( attrs ) . forEach ( key => {
62- const obj = { } ;
63- obj [ key ] = attrs [ key ] . replace ( / & q u o t ; / g, '"' ) ;
64- Object . assign ( result , obj ) ;
64+ const object = { } ;
65+ object [ key ] = attrs [ key ] . replace ( / & q u o t ; / g, '"' ) ;
66+ Object . assign ( result , object ) ;
6567 } ) ;
6668
6769 return result ;
@@ -78,13 +80,16 @@ function postHTMLParser(html, options) {
7880 return ;
7981 }
8082
81- last . content || ( last . content = [ ] ) ;
83+ if ( last . content === undefined ) {
84+ last . content = [ ] ;
85+ }
86+
8287 last . content . push ( comment ) ;
8388 } ,
8489 onopentag ( tag , attrs ) {
8590 const buf = { tag} ;
8691
87- if ( Object . keys ( attrs ) . length ) {
92+ if ( Object . keys ( attrs ) . length > 0 ) {
8893 buf . attrs = normalizeArributes ( attrs ) ;
8994 }
9095
@@ -93,7 +98,7 @@ function postHTMLParser(html, options) {
9398 onclosetag ( ) {
9499 const buf = bufArray . pop ( ) ;
95100
96- if ( ! bufArray . length ) {
101+ if ( ! bufArray . length > 0 ) {
97102 results . push ( buf ) ;
98103 return ;
99104 }
@@ -113,13 +118,15 @@ function postHTMLParser(html, options) {
113118 return ;
114119 }
115120
116- if ( last . content && last . content . length && typeof last . content [ last . content . length - 1 ] === 'string' ) {
117- last . content [ last . content . length - 1 ] = `${ last . content [ last . content . length - 1 ] } ${ text } `
118- return
121+ if ( last . content && last . content . length > 0 && typeof last . content [ last . content . length - 1 ] === 'string' ) {
122+ last . content [ last . content . length - 1 ] = `${ last . content [ last . content . length - 1 ] } ${ text } ` ;
123+ return ;
119124 }
120125
126+ if ( last . content === undefined ) {
127+ last . content = [ ] ;
128+ }
121129
122- last . content || ( last . content = [ ] ) ;
123130 last . content . push ( text ) ;
124131 }
125132 } , options || defaultOptions ) ;
@@ -134,7 +141,7 @@ function parserWrapper(...args) {
134141 let option ;
135142
136143 function parser ( html ) {
137- const opt = Object . assign ( { } , defaultOptions , option ) ;
144+ const opt = { ... defaultOptions , ... option } ;
138145 return postHTMLParser ( html , opt ) ;
139146 }
140147
0 commit comments