]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(compiler-sfc): should ignore nodes with no children (#464)
authorlikui <2218301630@qq.com>
Tue, 19 Nov 2019 14:10:59 +0000 (22:10 +0800)
committerEvan You <yyx990803@gmail.com>
Tue, 19 Nov 2019 14:10:59 +0000 (09:10 -0500)
packages/compiler-sfc/__tests__/parse.spec.ts
packages/compiler-sfc/src/parse.ts

index 14cb9dcc91606761049cd14ee6b0dbc36963aa49..0a3cc457706ae67dad69bd6e4acd4bff99772f7e 100644 (file)
@@ -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>`)
index 7a5828d1277d5742b8037de468255e44c5c3478f..8ad603e6c205163d6fa716e4fc0cd1ce7e6bb4a6 100644 (file)
@@ -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) {