Browse Source

tweak noramlizeArrayChildren

dev
Evan You 8 years ago
parent
commit
ec70b44c28
  1. 10
      src/core/vdom/helpers/normalize-children.js

10
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)

Loading…
Cancel
Save