Skip to content

Commit 5b9b37f

Browse files
authored
fix(compiler-sfc): should keep template nodes with no content (#2468)
close #2463
1 parent db786b1 commit 5b9b37f

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

packages/compiler-sfc/__tests__/parse.spec.ts

+7-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ h1 { color: red }
111111
)
112112
})
113113

114-
test('should ignore nodes with no content', () => {
115-
expect(parse(`<template/>`).descriptor.template).toBe(null)
114+
test('should keep template nodes with no content', () => {
115+
const { descriptor } = parse(`<template/>`)
116+
expect(descriptor.template).toBeTruthy()
117+
expect(descriptor.template!.content).toBeFalsy()
118+
})
119+
120+
test('should ignore other nodes with no content', () => {
116121
expect(parse(`<script/>`).descriptor.script).toBe(null)
117122
expect(parse(`<style/>`).descriptor.styles.length).toBe(0)
118123
expect(parse(`<custom/>`).descriptor.customBlocks.length).toBe(0)

packages/compiler-sfc/src/parse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ export function parse(
138138
if (node.type !== NodeTypes.ELEMENT) {
139139
return
140140
}
141-
if (!node.children.length && !hasSrc(node)) {
141+
if (!node.children.length && !hasSrc(node) && node.tag !== 'template') {
142142
return
143143
}
144144
switch (node.tag) {

0 commit comments

Comments
 (0)