]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): should keep template nodes with no content (#2468)
authormeteorlxy <meteor.lxy@foxmail.com>
Fri, 4 Dec 2020 23:23:01 +0000 (07:23 +0800)
committerGitHub <noreply@github.com>
Fri, 4 Dec 2020 23:23:01 +0000 (18:23 -0500)
close #2463

packages/compiler-sfc/__tests__/parse.spec.ts
packages/compiler-sfc/src/parse.ts

index dd16251e220ee7965459fdd2fc1bd2a1481ef5db..dc25c848c4163ff1aa8c3cb37a5ab6c394a747f8 100644 (file)
@@ -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)
index dcdd720c3de058e81ae0bed494a55fbe9da0014c..ac3456e645bd54a9fdc9d9c070b9d4733f39bedc 100644 (file)
@@ -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) {