|
|
@@ -1,7 +1,7 @@
|
|
|
/* @flow */
|
|
|
|
|
|
-import { isPrimitive } from 'core/util/index'
|
|
|
import VNode, { createTextVNode } from 'core/vdom/vnode'
|
|
|
+import { isDef, isUndef, isPrimitive } from 'shared/util'
|
|
|
|
|
|
// The template compiler attempts to minimize the need for normalization by
|
|
|
// statically analyzing the template at compile time.
|
|
|
@@ -41,25 +41,25 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
|
|
|
let i, c, last
|
|
|
for (i = 0; i < children.length; i++) {
|
|
|
c = children[i]
|
|
|
- if (c == null || typeof c === 'boolean') continue
|
|
|
+ if (isUndef(c) || typeof c === 'boolean') continue
|
|
|
last = res[res.length - 1]
|
|
|
// nested
|
|
|
if (Array.isArray(c)) {
|
|
|
res.push.apply(res, normalizeArrayChildren(c, `${nestedIndex || ''}_${i}`))
|
|
|
} else if (isPrimitive(c)) {
|
|
|
- if (last && last.text) {
|
|
|
- last.text += String(c)
|
|
|
+ if (isDef(last) && isDef(last.text)) {
|
|
|
+ (last: any).text += String(c)
|
|
|
} else if (c !== '') {
|
|
|
// convert primitive to vnode
|
|
|
res.push(createTextVNode(c))
|
|
|
}
|
|
|
} else {
|
|
|
- if (c.text && last && last.text) {
|
|
|
+ if (isDef(c.text) && isDef(last) && isDef(last.text)) {
|
|
|
res[res.length - 1] = createTextVNode(last.text + c.text)
|
|
|
} else {
|
|
|
// default key for nested array children (likely generated by v-for)
|
|
|
- if (c.tag && c.key == null && nestedIndex != null) {
|
|
|
- c.key = `__vlist${nestedIndex}_${i}__`
|
|
|
+ if (isDef(c.tag) && isUndef(c.key) && isDef(nestedIndex)) {
|
|
|
+ c.key = `__vlist${(nestedIndex: any)}_${i}__`
|
|
|
}
|
|
|
res.push(c)
|
|
|
}
|