fix(compiler-sfc): should ignore nodes with no children (#464)
This commit is contained in:
parent
f87dbea1f8
commit
1efb35e324
@ -3,6 +3,14 @@ import { mockWarn } from '@vue/runtime-test'
|
|||||||
|
|
||||||
describe('compiler:sfc', () => {
|
describe('compiler:sfc', () => {
|
||||||
mockWarn()
|
mockWarn()
|
||||||
|
|
||||||
|
test('should ignore nodes with no content', () => {
|
||||||
|
expect(parse(`<template/>`).template).toBe(null)
|
||||||
|
expect(parse(`<script/>`).script).toBe(null)
|
||||||
|
expect(parse(`<style/>`).styles.length).toBe(0)
|
||||||
|
expect(parse(`<custom/>`).customBlocks.length).toBe(0)
|
||||||
|
})
|
||||||
|
|
||||||
describe('error', () => {
|
describe('error', () => {
|
||||||
test('should only allow single template element', () => {
|
test('should only allow single template element', () => {
|
||||||
parse(`<template><div/></template><template><div/></template>`)
|
parse(`<template><div/></template><template><div/></template>`)
|
||||||
|
@ -81,6 +81,9 @@ export function parse(
|
|||||||
if (node.type !== NodeTypes.ELEMENT) {
|
if (node.type !== NodeTypes.ELEMENT) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if (!node.children.length) {
|
||||||
|
return
|
||||||
|
}
|
||||||
switch (node.tag) {
|
switch (node.tag) {
|
||||||
case 'template':
|
case 'template':
|
||||||
if (!sfc.template) {
|
if (!sfc.template) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user