Skip to content

Commit

Permalink
fix(compiler-sfc): should ignore nodes with no children (#464)
Browse files Browse the repository at this point in the history
  • Loading branch information
underfin authored and yyx990803 committed Nov 19, 2019
1 parent f87dbea commit 1efb35e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/compiler-sfc/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ import { mockWarn } from '@vue/runtime-test'

describe('compiler:sfc', () => {
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', () => {
test('should only allow single template element', () => {
parse(`<template><div/></template><template><div/></template>`)
Expand Down
3 changes: 3 additions & 0 deletions packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 1efb35e

Please sign in to comment.