File tree Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Expand file tree Collapse file tree 3 files changed +44
-10
lines changed Original file line number Diff line number Diff line change 1- var parse = require ( './lib/parse' ) ;
2- var stringify = require ( './lib/stringify' ) ;
3-
4-
51module . exports = {
6- parse : parse ,
7- stringify : stringify
2+ parse : require ( './lib/ parse' ) ,
3+ stringify : require ( './lib/ stringify' )
84} ;
Original file line number Diff line number Diff line change @@ -14,9 +14,13 @@ module.exports = function parse(html, options) {
1414 var inComponent = false ;
1515
1616 html . replace ( tagRE , function ( tag , index ) {
17- if ( inComponent && tag !== ( '</' + current . name + '>' ) ) {
18- return ;
19- }
17+ if ( inComponent ) {
18+ if ( tag !== ( '</' + current . name + '>' ) ) {
19+ return ;
20+ } else {
21+ inComponent = false ;
22+ }
23+ }
2024 var isOpen = tag . charAt ( 1 ) !== '/' ;
2125 var start = index + tag . length ;
2226 var nextChar = html . charAt ( start ) ;
@@ -33,7 +37,7 @@ module.exports = function parse(html, options) {
3337 inComponent = true ;
3438 }
3539
36- if ( nextChar !== '<' ) {
40+ if ( ! inComponent && nextChar !== '<' ) {
3741 current . children . push ( {
3842 type : 'text' ,
3943 content : html . slice ( start , html . indexOf ( '<' , start ) )
Original file line number Diff line number Diff line change @@ -158,5 +158,39 @@ test('parse', function (t) {
158158 ]
159159 } , 'should not include children of registered components in AST' ) ;
160160
161+ html = '<div><my-component thing="one">ok</my-component><my-component thing="two">ok</my-component></div>' ;
162+ parsed = HTML . parse ( html , {
163+ components : {
164+ 'my-component' : 'something'
165+ }
166+ } ) ;
167+
168+ t . deepEqual ( parsed , {
169+ type : 'tag' ,
170+ name : 'div' ,
171+ attrs : { } ,
172+ selfClosing : false ,
173+ children : [
174+ {
175+ type : 'component' ,
176+ name : 'my-component' ,
177+ attrs : {
178+ thing : 'one'
179+ } ,
180+ selfClosing : false ,
181+ children : [ ]
182+ } ,
183+ {
184+ type : 'component' ,
185+ name : 'my-component' ,
186+ attrs : {
187+ thing : 'two'
188+ } ,
189+ selfClosing : false ,
190+ children : [ ]
191+ }
192+ ]
193+ } )
194+
161195 t . end ( ) ;
162196} ) ;
You can’t perform that action at this time.
0 commit comments