(
children,
nestedIndex
)
| 3332 | |
| 3333 | |
| 3334 | function normalizeArrayChildren( |
| 3335 | children, |
| 3336 | nestedIndex |
| 3337 | ) { |
| 3338 | var res = []; |
| 3339 | var i, c, lastIndex, last; |
| 3340 | |
| 3341 | for (i = 0; i < children.length; i++) { //循环数组子节点children |
| 3342 | c = children[i]; |
| 3343 | //判断是否是空 并且 c是一个布尔值的时候 |
| 3344 | if (isUndef(c) || typeof c === 'boolean') { |
| 3345 | continue |
| 3346 | } |
| 3347 | // 获取 res 数组的长度 |
| 3348 | lastIndex = res.length - 1; |
| 3349 | //获取res 最后一个数据 |
| 3350 | last = res[lastIndex]; |
| 3351 | // nested |
| 3352 | if (Array.isArray(c)) { //如果c 子节点还是一个数组 |
| 3353 | if (c.length > 0) { //并且 长度 不为0 |
| 3354 | //数组则用递归 nestedIndex 有可能是 0_0 0_0_0 0_0_1 0_0_2 0_1 0_1_0 0_1_1 0_1_2 |
| 3355 | //如果含有子节点,则递归,把所有子节点变成文本节点 |
| 3356 | c = normalizeArrayChildren(c, ((nestedIndex || '') + "_" + i)); |
| 3357 | // merge adjacent text nodes 合并相邻文本节点 |
| 3358 | //如果c[0] 中的第一个是文本节点 并且 res 最后一个节点是 文本节点 |
| 3359 | if (isTextNode(c[0]) && isTextNode(last)) { |
| 3360 | //创建一个文本节点 并且是合并他们的文本内容 |
| 3361 | res[lastIndex] = createTextVNode(last.text + (c[0]).text); |
| 3362 | //从c 出栈第一个数据 |
| 3363 | c.shift(); |
| 3364 | } |
| 3365 | //res 添加 数据 相当于 concat 链接数组 |
| 3366 | res.push.apply(res, c); |
| 3367 | } |
| 3368 | } else if (isPrimitive(c)) { //判断数据类型是否是string,number,symbol,boolean |
| 3369 | //如果res最后数据一个是文本节点 |
| 3370 | if (isTextNode(last)) { |
| 3371 | // merge adjacent text nodes 合并相邻文本节点 |
| 3372 | // this is necessary for SSR hydration because text nodes are 这对于SSR水化是必要的,因为文本节点是 |
| 3373 | // essentially merged when rendered to HTML strings 当呈现到HTML字符串时本质上合并 |
| 3374 | // 创建文本节点 |
| 3375 | res[lastIndex] = createTextVNode(last.text + c); |
| 3376 | } else if (c !== '') { //c不等于空 |
| 3377 | // convert primitive to vnode |
| 3378 | //转换成 vnode 创建 文本节点 |
| 3379 | res.push(createTextVNode(c)); |
| 3380 | } |
| 3381 | } else { |
| 3382 | //如果c 中的第一个是文本节点 并且 res 最后一个节点是 文本节点 |
| 3383 | if (isTextNode(c) && isTextNode(last)) { |
| 3384 | // merge adjacent text nodes 合并相邻文本节点 |
| 3385 | //创建文本节点 |
| 3386 | res[lastIndex] = createTextVNode(last.text + c.text); |
| 3387 | } else { |
| 3388 | // default key for nested array children (likely generated by v-for) |
| 3389 | //嵌套数组子的默认键 可能v-for产生的 |
| 3390 | |
| 3391 | if ( |
no test coverage detected