Skip to content

Commit 9f75f9c

Browse files
committed
fix(compiler-sfc): should judgment if not children
1 parent 2780e0d commit 9f75f9c

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,14 @@ import { mockWarn } from '@vue/runtime-test'
33

44
describe('compiler:sfc', () => {
55
mockWarn()
6+
7+
test('should not process if not children', () => {
8+
expect(parse(`<template/>`).template).toBe(null)
9+
expect(parse(`<script/>`).script).toBe(null)
10+
expect(parse(`<style/>`).styles.length).toBe(0)
11+
expect(parse(`<custom/>`).customBlocks.length).toBe(0)
12+
})
13+
614
describe('error', () => {
715
test('should only allow single template element', () => {
816
parse(`<template><div/></template><template><div/></template>`)

packages/compiler-sfc/src/parse.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export function parse(
7474
if (node.type !== NodeTypes.ELEMENT) {
7575
return
7676
}
77+
if (!node.children.length) {
78+
return
79+
}
7780
switch (node.tag) {
7881
case 'template':
7982
if (!sfc.template) {

0 commit comments

Comments
 (0)