@@ -47,22 +47,6 @@ let IS_REGEX_CAPTURING_BROKEN = false
47
47
48
48
// Special Elements (can contain anything)
49
49
const isScriptOrStyle = makeMap ( 'script,style' , true )
50
- const hasLang = attr => attr . name === 'lang' && attr . value !== 'html'
51
- const isSpecialTag = ( tag , isSFC , stack ) => {
52
- if ( isScriptOrStyle ( tag ) ) {
53
- return true
54
- }
55
- if ( isSFC && stack . length === 1 ) {
56
- // top-level template that has no pre-processor
57
- if ( tag === 'template' && ! stack [ 0 ] . attrs . some ( hasLang ) ) {
58
- return false
59
- } else {
60
- return true
61
- }
62
- }
63
- return false
64
- }
65
-
66
50
const reCache = { }
67
51
68
52
const ltRE = / & l t ; / g
@@ -91,7 +75,7 @@ export function parseHTML (html, options) {
91
75
while ( html ) {
92
76
last = html
93
77
// Make sure we're not in a script or style element
94
- if ( ! lastTag || ! isSpecialTag ( lastTag , options . sfc , stack ) ) {
78
+ if ( ! lastTag || ! isScriptOrStyle ( lastTag ) ) {
95
79
let textEnd = html . indexOf ( '<' )
96
80
if ( textEnd === 0 ) {
97
81
// Comment:
@@ -126,7 +110,7 @@ export function parseHTML (html, options) {
126
110
if ( endTagMatch ) {
127
111
const curIndex = index
128
112
advance ( endTagMatch [ 0 ] . length )
129
- parseEndTag ( endTagMatch [ 0 ] , endTagMatch [ 1 ] , curIndex , index )
113
+ parseEndTag ( endTagMatch [ 1 ] , curIndex , index )
130
114
continue
131
115
}
132
116
@@ -183,7 +167,7 @@ export function parseHTML (html, options) {
183
167
} )
184
168
index += html . length - rest . length
185
169
html = rest
186
- parseEndTag ( '</' + stackedTag + '>' , stackedTag , index - endTagLength , index )
170
+ parseEndTag ( stackedTag , index - endTagLength , index )
187
171
}
188
172
189
173
if ( html === last && options . chars ) {
@@ -229,10 +213,10 @@ export function parseHTML (html, options) {
229
213
230
214
if ( expectHTML ) {
231
215
if ( lastTag === 'p' && isNonPhrasingTag ( tagName ) ) {
232
- parseEndTag ( '' , lastTag )
216
+ parseEndTag ( lastTag )
233
217
}
234
218
if ( canBeLeftOpenTag ( tagName ) && lastTag === tagName ) {
235
- parseEndTag ( '' , tagName )
219
+ parseEndTag ( tagName )
236
220
}
237
221
}
238
222
@@ -259,7 +243,7 @@ export function parseHTML (html, options) {
259
243
}
260
244
261
245
if ( ! unary ) {
262
- stack . push ( { tag : tagName , attrs : attrs } )
246
+ stack . push ( { tag : tagName , lowerCasedTag : tagName . toLowerCase ( ) , attrs : attrs } )
263
247
lastTag = tagName
264
248
unarySlash = ''
265
249
}
@@ -269,16 +253,19 @@ export function parseHTML (html, options) {
269
253
}
270
254
}
271
255
272
- function parseEndTag ( tag , tagName , start , end ) {
273
- let pos
256
+ function parseEndTag ( tagName , start , end ) {
257
+ let pos , lowerCasedTagName
274
258
if ( start == null ) start = index
275
259
if ( end == null ) end = index
276
260
261
+ if ( tagName ) {
262
+ lowerCasedTagName = tagName . toLowerCase ( )
263
+ }
264
+
277
265
// Find the closest opened tag of the same type
278
266
if ( tagName ) {
279
- const needle = tagName . toLowerCase ( )
280
267
for ( pos = stack . length - 1 ; pos >= 0 ; pos -- ) {
281
- if ( stack [ pos ] . tag . toLowerCase ( ) === needle ) {
268
+ if ( stack [ pos ] . lowerCasedTag === lowerCasedTagName ) {
282
269
break
283
270
}
284
271
}
@@ -298,11 +285,11 @@ export function parseHTML (html, options) {
298
285
// Remove the open elements from the stack
299
286
stack . length = pos
300
287
lastTag = pos && stack [ pos - 1 ] . tag
301
- } else if ( tagName . toLowerCase ( ) === 'br' ) {
288
+ } else if ( lowerCasedTagName === 'br' ) {
302
289
if ( options . start ) {
303
290
options . start ( tagName , [ ] , true , start , end )
304
291
}
305
- } else if ( tagName . toLowerCase ( ) === 'p' ) {
292
+ } else if ( lowerCasedTagName === 'p' ) {
306
293
if ( options . start ) {
307
294
options . start ( tagName , [ ] , false , start , end )
308
295
}
0 commit comments