Skip to content

Commit

Permalink
fix(compiler-sfc): should keep template nodes with no content (#2468)
Browse files Browse the repository at this point in the history
close #2463
  • Loading branch information
meteorlxy committed Dec 4, 2020
1 parent db786b1 commit 5b9b37f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions packages/compiler-sfc/__tests__/parse.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,13 @@ h1 { color: red }
)
})

test('should ignore nodes with no content', () => {
expect(parse(`<template/>`).descriptor.template).toBe(null)
test('should keep template nodes with no content', () => {
const { descriptor } = parse(`<template/>`)
expect(descriptor.template).toBeTruthy()
expect(descriptor.template!.content).toBeFalsy()
})

test('should ignore other nodes with no content', () => {
expect(parse(`<script/>`).descriptor.script).toBe(null)
expect(parse(`<style/>`).descriptor.styles.length).toBe(0)
expect(parse(`<custom/>`).descriptor.customBlocks.length).toBe(0)
Expand Down
2 changes: 1 addition & 1 deletion packages/compiler-sfc/src/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export function parse(
if (node.type !== NodeTypes.ELEMENT) {
return
}
if (!node.children.length && !hasSrc(node)) {
if (!node.children.length && !hasSrc(node) && node.tag !== 'template') {
return
}
switch (node.tag) {
Expand Down

0 comments on commit 5b9b37f

Please sign in to comment.