1 |
|
2 | 'use strict'
|
3 | const formatChildren = require('./base-format-children')
|
4 |
|
5 | function applyChildren (key/*: string */, element/*: any */, children/*: ?mixed[] */) {
|
6 | if (process.env.NODE_ENV !== 'production' && !element.flags) {
|
7 | throw new Error(JSON.stringify(element) + ' is not a valid element')
|
8 | }
|
9 | if (children) {
|
10 | children = children.map(function (child) {
|
11 | return typeof child !== 'string' ? child : {
|
12 | childFlags: 1,
|
13 | children: child,
|
14 | className: null,
|
15 | dom: null,
|
16 | flags: 16,
|
17 | isValidated: false,
|
18 | key: null,
|
19 | parentVNode: null,
|
20 | props: null,
|
21 | ref: null,
|
22 | type: null
|
23 | }
|
24 | })
|
25 | element.childFlags = 2
|
26 | element.children = children.length === 1 ? children[0] : children
|
27 | }
|
28 | return element
|
29 | }
|
30 |
|
31 | exports.formatChildren = formatChildren.bind(null, applyChildren)
|