@@ -31,22 +31,22 @@ export function main() {
3131 describe ( 'parse' , ( ) => {
3232 describe ( 'text nodes' , ( ) => {
3333 it ( 'should parse root level text nodes' , ( ) => {
34- expect ( humanizeDom ( parser . parse ( 'a' , 'TestComp' ) ) ) . toEqual ( [ [ HtmlTextAst , 'a' ] ] ) ;
34+ expect ( humanizeDom ( parser . parse ( 'a' , 'TestComp' ) ) ) . toEqual ( [ [ HtmlTextAst , 'a' , 0 ] ] ) ;
3535 } ) ;
3636
3737 it ( 'should parse text nodes inside regular elements' , ( ) => {
3838 expect ( humanizeDom ( parser . parse ( '<div>a</div>' , 'TestComp' ) ) )
39- . toEqual ( [ [ HtmlElementAst , 'div' , 0 ] , [ HtmlTextAst , 'a' ] ] ) ;
39+ . toEqual ( [ [ HtmlElementAst , 'div' , 0 ] , [ HtmlTextAst , 'a' , 1 ] ] ) ;
4040 } ) ;
4141
4242 it ( 'should parse text nodes inside template elements' , ( ) => {
4343 expect ( humanizeDom ( parser . parse ( '<template>a</template>' , 'TestComp' ) ) )
44- . toEqual ( [ [ HtmlElementAst , 'template' , 0 ] , [ HtmlTextAst , 'a' ] ] ) ;
44+ . toEqual ( [ [ HtmlElementAst , 'template' , 0 ] , [ HtmlTextAst , 'a' , 1 ] ] ) ;
4545 } ) ;
4646
4747 it ( 'should parse CDATA' , ( ) => {
4848 expect ( humanizeDom ( parser . parse ( '<![CDATA[text]]>' , 'TestComp' ) ) )
49- . toEqual ( [ [ HtmlTextAst , 'text' ] ] ) ;
49+ . toEqual ( [ [ HtmlTextAst , 'text' , 0 ] ] ) ;
5050 } ) ;
5151 } ) ;
5252
@@ -75,14 +75,24 @@ export function main() {
7575 ] ) ;
7676 } ) ;
7777
78+ it ( 'should close void elements on text nodes' , ( ) => {
79+ expect ( humanizeDom ( parser . parse ( '<p>before<br>after</p>' , 'TestComp' ) ) )
80+ . toEqual ( [
81+ [ HtmlElementAst , 'p' , 0 ] ,
82+ [ HtmlTextAst , 'before' , 1 ] ,
83+ [ HtmlElementAst , 'br' , 1 ] ,
84+ [ HtmlTextAst , 'after' , 1 ] ,
85+ ] ) ;
86+ } ) ;
87+
7888 it ( 'should support optional end tags' , ( ) => {
7989 expect ( humanizeDom ( parser . parse ( '<div><p>1<p>2</div>' , 'TestComp' ) ) )
8090 . toEqual ( [
8191 [ HtmlElementAst , 'div' , 0 ] ,
8292 [ HtmlElementAst , 'p' , 1 ] ,
83- [ HtmlTextAst , '1' ] ,
93+ [ HtmlTextAst , '1' , 2 ] ,
8494 [ HtmlElementAst , 'p' , 1 ] ,
85- [ HtmlTextAst , '2' ] ,
95+ [ HtmlTextAst , '2' , 2 ] ,
8696 ] ) ;
8797 } ) ;
8898
@@ -187,7 +197,7 @@ export function main() {
187197 [ HtmlAttrAst , '(e)' , 'do()' , '(e)="do()"' ] ,
188198 [ HtmlAttrAst , 'attr' , 'v2' , 'attr="v2"' ] ,
189199 [ HtmlAttrAst , 'noValue' , '' , 'noValue' ] ,
190- [ HtmlTextAst , '\na\n' , '\na\n' ] ,
200+ [ HtmlTextAst , '\na\n' , 1 , '\na\n' ] ,
191201 ] ) ;
192202 } ) ;
193203 } ) ;
@@ -272,7 +282,7 @@ class Humanizer implements HtmlAstVisitor {
272282 }
273283
274284 visitText ( ast : HtmlTextAst , context : any ) : any {
275- var res = this . _appendContext ( ast , [ HtmlTextAst , ast . value ] ) ;
285+ var res = this . _appendContext ( ast , [ HtmlTextAst , ast . value , this . elDepth ] ) ;
276286 this . result . push ( res ) ;
277287 return null ;
278288 }
0 commit comments