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
-
5
1
module . exports = {
6
- parse : parse ,
7
- stringify : stringify
2
+ parse : require ( './lib/ parse' ) ,
3
+ stringify : require ( './lib/ stringify' )
8
4
} ;
Original file line number Diff line number Diff line change @@ -14,9 +14,13 @@ module.exports = function parse(html, options) {
14
14
var inComponent = false ;
15
15
16
16
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
+ }
20
24
var isOpen = tag . charAt ( 1 ) !== '/' ;
21
25
var start = index + tag . length ;
22
26
var nextChar = html . charAt ( start ) ;
@@ -33,7 +37,7 @@ module.exports = function parse(html, options) {
33
37
inComponent = true ;
34
38
}
35
39
36
- if ( nextChar !== '<' ) {
40
+ if ( ! inComponent && nextChar !== '<' ) {
37
41
current . children . push ( {
38
42
type : 'text' ,
39
43
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) {
158
158
]
159
159
} , 'should not include children of registered components in AST' ) ;
160
160
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
+
161
195
t . end ( ) ;
162
196
} ) ;
You can’t perform that action at this time.
0 commit comments