File tree Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Expand file tree Collapse file tree 2 files changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,7 @@ function isRealTemplate (node) {
76
76
77
77
const tagRE = / < ( [ \w : - ] + ) /
78
78
const entityRE = / & # ? \w + ?; /
79
+ const commentRE = / < ! - - /
79
80
80
81
/**
81
82
* Convert a string template to a DocumentFragment.
@@ -100,8 +101,9 @@ function stringToFragment (templateString, raw) {
100
101
var frag = document . createDocumentFragment ( )
101
102
var tagMatch = templateString . match ( tagRE )
102
103
var entityMatch = entityRE . test ( templateString )
104
+ var commentMatch = commentRE . test ( templateString )
103
105
104
- if ( ! tagMatch && ! entityMatch ) {
106
+ if ( ! tagMatch && ! entityMatch && ! commentMatch ) {
105
107
// text only, return a single text node.
106
108
frag . appendChild (
107
109
document . createTextNode ( templateString )
Original file line number Diff line number Diff line change @@ -23,6 +23,13 @@ describe('Template Parser', function () {
23
23
expect ( res . firstChild . nodeType ) . toBe ( 3 ) // Text node
24
24
} )
25
25
26
+ it ( 'should work if the template string doesn\'t contain tags but contains comments' , function ( ) {
27
+ var res = parse ( '<!-- yo -->hello<!-- yo -->' )
28
+ expect ( res . childNodes . length ) . toBe ( 1 )
29
+ expect ( res . firstChild . nodeType ) . toBe ( 3 ) // text node
30
+ expect ( res . firstChild . nodeValue ) . toBe ( 'hello' )
31
+ } )
32
+
26
33
it ( 'should handle string that contains html entities' , function ( ) {
27
34
var res = parse ( 'foo<bar' )
28
35
expect ( res . nodeType ) . toBe ( 11 )
You can’t perform that action at this time.
0 commit comments