Skip to content

Commit

Permalink
tweak noramlizeArrayChildren
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 9, 2017
1 parent f2bd882 commit ec70b44
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/core/vdom/helpers/normalize-children.js
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit ec70b44

Please sign in to comment.