diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts
index dd16251e..dc25c848 100644
--- a/packages/compiler-sfc/__tests__/parse.spec.ts
+++ b/packages/compiler-sfc/__tests__/parse.spec.ts
@@ -111,8 +111,13 @@ h1 { color: red }
)
})
- test('should ignore nodes with no content', () => {
- expect(parse(``).descriptor.template).toBe(null)
+ test('should keep template nodes with no content', () => {
+ const { descriptor } = parse(``)
+ expect(descriptor.template).toBeTruthy()
+ expect(descriptor.template!.content).toBeFalsy()
+ })
+
+ test('should ignore other nodes with no content', () => {
expect(parse(``).descriptor.script).toBe(null)
expect(parse(``).descriptor.styles.length).toBe(0)
expect(parse(``).descriptor.customBlocks.length).toBe(0)
diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts
index dcdd720c..ac3456e6 100644
--- a/packages/compiler-sfc/src/parse.ts
+++ b/packages/compiler-sfc/src/parse.ts
@@ -138,7 +138,7 @@ export function parse(
if (node.type !== NodeTypes.ELEMENT) {
return
}
- if (!node.children.length && !hasSrc(node)) {
+ if (!node.children.length && !hasSrc(node) && node.tag !== 'template') {
return
}
switch (node.tag) {