Skip to content

Commit 9d0bc97

Browse files
committed
fix sfc parser special tag check for nested templates (fix vuejs#4289)
1 parent fa61c00 commit 9d0bc97

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/compiler/parser/html-parser.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ const isSpecialTag = (tag, isSFC, stack) => {
5252
if (isScriptOrStyle(tag)) {
5353
return true
5454
}
55-
if (isSFC) {
55+
if (isSFC && stack.length === 1) {
5656
// top-level template that has no pre-processor
57-
if (tag === 'template' && stack.length === 1 && !stack[0].attrs.some(hasLang)) {
57+
if (tag === 'template' && !stack[0].attrs.some(hasLang)) {
5858
return false
5959
} else {
6060
return true

test/unit/modules/sfc/sfc-parser.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,22 @@ describe('Single File Component parser', () => {
123123
expect(simpleTest.attrs.name).toBe('simple')
124124
expect(simpleTest.attrs.foo).toBe('bar')
125125
})
126+
127+
// Regression #4289
128+
it('accepts nested template tag', () => {
129+
const raw = `<div>
130+
<template v-if="true === true">
131+
<section class="section">
132+
<div class="container">
133+
Should be shown
134+
</div>
135+
</section>
136+
</template>
137+
<template v-else>
138+
<p>Shoud not be shown</p>
139+
</template>
140+
</div>`
141+
const res = parseComponent(`<template>${raw}</template>`)
142+
expect(res.template.content.trim()).toBe(raw)
143+
})
126144
})

0 commit comments

Comments
 (0)