]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
feat(runtime): support rendering comment nodes
authorEvan You <yyx990803@gmail.com>
Tue, 24 Sep 2019 18:37:14 +0000 (14:37 -0400)
committerEvan You <yyx990803@gmail.com>
Tue, 24 Sep 2019 18:37:14 +0000 (14:37 -0400)
packages/runtime-core/src/componentRenderUtils.ts
packages/runtime-core/src/createRenderer.ts
packages/runtime-core/src/index.ts
packages/runtime-core/src/vnode.ts

index 0534183cd443ea531c5f660ee471c11a004ffcc9..0a617effcf726cf8858367be9c01f5858d1aa70c 100644 (file)
@@ -3,7 +3,7 @@ import {
   FunctionalComponent,
   Data
 } from './component'
-import { VNode, normalizeVNode, createVNode, Empty } from './vnode'
+import { VNode, normalizeVNode, createVNode, Comment } from './vnode'
 import { ShapeFlags } from './shapeFlags'
 import { handleError, ErrorCodes } from './errorHandling'
 import { PatchFlags } from './patchFlags'
@@ -45,7 +45,7 @@ export function renderComponentRoot(
     }
   } catch (err) {
     handleError(err, instance, ErrorCodes.RENDER_FUNCTION)
-    result = createVNode(Empty)
+    result = createVNode(Comment)
   }
   currentRenderingInstance = null
   return result
index f294f941a982e41306868f509a678716db94b45d..90fb8524c93d94b8d3d544c8547e98118cb503f7 100644 (file)
@@ -1,7 +1,7 @@
 import {
   Text,
   Fragment,
-  Empty,
+  Comment,
   Portal,
   normalizeVNode,
   VNode,
@@ -191,8 +191,8 @@ export function createRenderer<
       case Text:
         processText(n1, n2, container, anchor)
         break
-      case Empty:
-        processEmptyNode(n1, n2, container, anchor)
+      case Comment:
+        processCommentNode(n1, n2, container, anchor)
         break
       case Fragment:
         processFragment(
@@ -283,15 +283,20 @@ export function createRenderer<
     }
   }
 
-  function processEmptyNode(
+  function processCommentNode(
     n1: HostVNode | null,
     n2: HostVNode,
     container: HostElement,
     anchor: HostNode | null
   ) {
     if (n1 == null) {
-      hostInsert((n2.el = hostCreateComment('')), container, anchor)
+      hostInsert(
+        (n2.el = hostCreateComment((n2.children as string) || '')),
+        container,
+        anchor
+      )
     } else {
+      // there's no support for dynamic comments
       n2.el = n1.el
     }
   }
@@ -677,7 +682,7 @@ export function createRenderer<
       }
     }
     // insert an empty node as the placeholder for the portal
-    processEmptyNode(n1, n2, container, anchor)
+    processCommentNode(n1, n2, container, anchor)
   }
 
   function processSuspense(
@@ -1057,8 +1062,8 @@ export function createRenderer<
         })
 
       // give it a placeholder
-      const placeholder = (instance.subTree = createVNode(Empty))
-      processEmptyNode(null, placeholder, container, anchor)
+      const placeholder = (instance.subTree = createVNode(Comment))
+      processCommentNode(null, placeholder, container, anchor)
       initialVNode.el = placeholder.el
       return
     }
index 4d42f3acf39464ff2caa37bcf95d65d230ed31ea..fe9b519cfe48dd6960660d8c67243b040ac56d60 100644 (file)
@@ -19,7 +19,7 @@ export {
   createBlock
 } from './vnode'
 // VNode type symbols
-export { Text, Empty, Fragment, Portal, Suspense } from './vnode'
+export { Text, Comment, Fragment, Portal, Suspense } from './vnode'
 // VNode flags
 export { PublicPatchFlags as PatchFlags } from './patchFlags'
 export { PublicShapeFlags as ShapeFlags } from './shapeFlags'
index 589042ec3af4280e3f453da8ac4ba08fef8f5390..ca3670c3df8d682884f3f7fd9ce9726f8397e8c9 100644 (file)
@@ -16,7 +16,7 @@ import { SuspenseBoundary } from './suspense'
 
 export const Fragment = __DEV__ ? Symbol('Fragment') : Symbol()
 export const Text = __DEV__ ? Symbol('Text') : Symbol()
-export const Empty = __DEV__ ? Symbol('Empty') : Symbol()
+export const Comment = __DEV__ ? Symbol('Empty') : Symbol()
 export const Portal = __DEV__ ? Symbol('Portal') : Symbol()
 export const Suspense = __DEV__ ? Symbol('Suspense') : Symbol()
 
@@ -27,7 +27,7 @@ export type VNodeTypes =
   | typeof Fragment
   | typeof Portal
   | typeof Text
-  | typeof Empty
+  | typeof Comment
   | typeof Suspense
 
 type VNodeChildAtom<HostNode, HostElement> =
@@ -245,7 +245,7 @@ export function cloneVNode(vnode: VNode): VNode {
 export function normalizeVNode(child: VNodeChild): VNode {
   if (child == null) {
     // empty placeholder
-    return createVNode(Empty)
+    return createVNode(Comment)
   } else if (isArray(child)) {
     // fragment
     return createVNode(Fragment, null, child)