diff --git a/packages/compiler-sfc/__tests__/parse.spec.ts b/packages/compiler-sfc/__tests__/parse.spec.ts
index 14cb9dcc916..0a3cc457706 100644
--- a/packages/compiler-sfc/__tests__/parse.spec.ts
+++ b/packages/compiler-sfc/__tests__/parse.spec.ts
@@ -3,6 +3,14 @@ import { mockWarn } from '@vue/runtime-test'
describe('compiler:sfc', () => {
mockWarn()
+
+ test('should ignore nodes with no content', () => {
+ expect(parse(``).template).toBe(null)
+ expect(parse(``).script).toBe(null)
+ expect(parse(``).styles.length).toBe(0)
+ expect(parse(``).customBlocks.length).toBe(0)
+ })
+
describe('error', () => {
test('should only allow single template element', () => {
parse(``)
diff --git a/packages/compiler-sfc/src/parse.ts b/packages/compiler-sfc/src/parse.ts
index 7a5828d1277..8ad603e6c20 100644
--- a/packages/compiler-sfc/src/parse.ts
+++ b/packages/compiler-sfc/src/parse.ts
@@ -81,6 +81,9 @@ export function parse(
if (node.type !== NodeTypes.ELEMENT) {
return
}
+ if (!node.children.length) {
+ return
+ }
switch (node.tag) {
case 'template':
if (!sfc.template) {