Skip to content

Commit

Permalink
fix(compiler-sfc): should keep template nodes with no content (close v…
Browse files Browse the repository at this point in the history
  • Loading branch information
meteorlxy committed Oct 23, 2020
1 parent f4621ff commit 258bf3a
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 @@ -134,7 +134,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 258bf3a

Please sign in to comment.