Przeglądaj źródła

tweak noramlizeArrayChildren

Evan You 9 lat temu
rodzic
commit
ec70b44c28
1 zmienionych plików z 7 dodań i 3 usunięć
  1. 7 3
      src/core/vdom/helpers/normalize-children.js

+ 7 - 3
src/core/vdom/helpers/normalize-children.js

@@ -36,6 +36,10 @@ export function normalizeChildren (children: any): ?Array<VNode> {
       : undefined
 }
 
+function isTextNode (node): boolean {
+  return isDef(node) && isDef(node.text) && isFalse(node.isComment)
+}
+
 function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNode> {
   const res = []
   let i, c, last
@@ -47,14 +51,14 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
     if (Array.isArray(c)) {
       res.push.apply(res, normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`))
     } else if (isPrimitive(c)) {
-      if (isDef(last) && isDef(last.text)) {
-        last.text += String(c)
+      if (isTextNode(last)) {
+        (last: any).text += String(c)
       } else if (c !== '') {
         // convert primitive to vnode
         res.push(createTextVNode(c))
       }
     } else {
-      if (isFalse(c.isComment) && isDef(c.text) && isDef(last) && isFalse(last.isComment) && isDef(last.text)) {
+      if (isTextNode(c) && isTextNode(last)) {
         res[res.length - 1] = createTextVNode(last.text + c.text)
       } else {
         // default key for nested array children (likely generated by v-for)