(type, props, children)
| 14 | * @returns {import('./internal').VNode} |
| 15 | */ |
| 16 | export function createElement(type, props, children) { |
| 17 | let normalizedProps = {}, |
| 18 | key, |
| 19 | ref, |
| 20 | i; |
| 21 | for (i in props) { |
| 22 | if (i == 'key') key = props[i]; |
| 23 | else if (i == 'ref') ref = props[i]; |
| 24 | else normalizedProps[i] = props[i]; |
| 25 | } |
| 26 | |
| 27 | if (arguments.length > 2) { |
| 28 | normalizedProps.children = |
| 29 | arguments.length > 3 ? slice.call(arguments, 2) : children; |
| 30 | } |
| 31 | |
| 32 | // If a Component VNode, check for and apply defaultProps |
| 33 | // Note: type may be undefined in development, must never error here. |
| 34 | if (typeof type == 'function' && type.defaultProps != NULL) { |
| 35 | for (i in type.defaultProps) { |
| 36 | if (normalizedProps[i] === UNDEFINED) { |
| 37 | normalizedProps[i] = type.defaultProps[i]; |
| 38 | } |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | return createVNode(type, normalizedProps, key, ref, NULL); |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Create a VNode (used internally by Preact) |
searching dependent graphs…