Skip to content

Commit 1efb35e

Browse files
underfinyyx990803
authored andcommitted
fix(compiler-sfc): should ignore nodes with no children (#464)
1 parent f87dbea commit 1efb35e

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 ignore nodes with no content', () => {
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
@@ -81,6 +81,9 @@ export function parse(
8181
if (node.type !== NodeTypes.ELEMENT) {
8282
return
8383
}
84+
if (!node.children.length) {
85+
return
86+
}
8487
switch (node.tag) {
8588
case 'template':
8689
if (!sfc.template) {

0 commit comments

Comments
 (0)