File tree Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Expand file tree Collapse file tree 2 files changed +17
-9
lines changed Original file line number Diff line number Diff line change @@ -36,16 +36,14 @@ module.exports = function parse(html, options) {
36
36
inComponent = false ;
37
37
}
38
38
}
39
- // check if this is a comment tag. if so, just return.
40
- if ( tag . indexOf ( '<!--' ) === 0 ) {
41
- return ;
42
- }
39
+
43
40
var isOpen = tag . charAt ( 1 ) !== '/' ;
41
+ var isComment = tag . indexOf ( '<!--' ) === 0 ;
44
42
var start = index + tag . length ;
45
43
var nextChar = html . charAt ( start ) ;
46
44
var parent ;
47
45
48
- if ( isOpen ) {
46
+ if ( isOpen && ! isComment ) {
49
47
level ++ ;
50
48
51
49
current = parseTag ( tag ) ;
@@ -74,8 +72,10 @@ module.exports = function parse(html, options) {
74
72
arr [ level ] = current ;
75
73
}
76
74
77
- if ( ! isOpen || current . voidElement ) {
78
- level -- ;
75
+ if ( isComment || ! isOpen || current . voidElement ) {
76
+ if ( ! isComment ) {
77
+ level -- ;
78
+ }
79
79
if ( ! inComponent && nextChar !== '<' && nextChar ) {
80
80
// trailing text node
81
81
// if we're at the root, push a base text node. otherwise add as
Original file line number Diff line number Diff line change @@ -385,15 +385,23 @@ test('parse', function (t) {
385
385
]
386
386
} ] , 'should ignore HTML comments' ) ;
387
387
388
- html = '<div>Hi <!-- I\'m a nested comment! with a <span></span> --></div><span><!--test--></span>' ;
388
+ html = '<div>Hi <!-- I\'m a nested comment! with a <span></span> -->there<strong>!</strong> </div><span><!--test--></span>' ;
389
389
parsed = HTML . parse ( html ) ;
390
390
t . deepEqual ( parsed , [ {
391
391
type : 'tag' ,
392
392
name : 'div' ,
393
393
attrs : { } ,
394
394
voidElement : false ,
395
395
children : [
396
- { type : 'text' , content : 'Hi ' }
396
+ { type : 'text' , content : 'Hi ' } ,
397
+ { type : 'text' , content : 'there' } ,
398
+ {
399
+ type : 'tag' ,
400
+ name : 'strong' ,
401
+ attrs : { } ,
402
+ voidElement : false ,
403
+ children : [ { type : 'text' , content : '!' } ]
404
+ }
397
405
]
398
406
} , {
399
407
type : 'tag' ,
You can’t perform that action at this time.
0 commit comments