1
1
/* @flow */
2
2
3
3
import VNode , { createTextVNode } from 'core/vdom/vnode'
4
- import { isDef , isUndef , isPrimitive } from 'shared/util'
4
+ import { isDef , isUndef , isPrimitive , isObject } from 'shared/util'
5
5
6
6
// The template compiler attempts to minimize the need for normalization by
7
7
// statically analyzing the template at compile time.
@@ -45,7 +45,11 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
45
45
last = res [ res . length - 1 ]
46
46
// nested
47
47
if ( Array . isArray ( c ) ) {
48
- res . push . apply ( res , normalizeArrayChildren ( c , `${ nestedIndex || '' } _${ i } ` ) )
48
+ if ( hasNestedIndex ( c ) ) {
49
+ res . push . apply ( res , normalizeArrayChildren ( c , `${ nestedIndex || '' } _${ i } ` ) )
50
+ } else {
51
+ res . push . apply ( res , normalizeArrayChildren ( c ) )
52
+ }
49
53
} else if ( isPrimitive ( c ) ) {
50
54
if ( isDef ( last ) && isDef ( last . text ) ) {
51
55
last . text += String ( c )
@@ -67,3 +71,21 @@ function normalizeArrayChildren (children: any, nestedIndex?: string): Array<VNo
67
71
}
68
72
return res
69
73
}
74
+
75
+ function hasNestedIndex ( children : any ) : boolean {
76
+ const length = children . length
77
+ if ( length <= 1 ) return true
78
+ if ( isObject ( children [ 0 ] ) === false || isUndef ( children [ 0 ] . tag ) || isDef ( children [ 0 ] . key ) ) return false
79
+ let i
80
+ for ( i = 1 ; i < length ; i ++ ) {
81
+ if ( isObject ( children [ i ] ) === false || similarVNode ( children [ 0 ] , children [ i ] ) === false ) return false
82
+ }
83
+ return true
84
+ }
85
+
86
+ function similarVNode ( a : VNode , b : VNode ) : boolean {
87
+ return (
88
+ a . tag === b . tag &&
89
+ a . key === b . key
90
+ )
91
+ }
0 commit comments