* Clone and return a new ReactElement using element as the starting point. * See https://reactjs.org/docs/react-api.html#cloneelement
(element, config, children)
| 18976 | * See https://reactjs.org/docs/react-api.html#cloneelement |
| 18977 | */ |
| 18978 | function cloneElement(element, config, children) { |
| 18979 | var propName = void 0; |
| 18980 | |
| 18981 | // Original props are copied |
| 18982 | var props = _assign({}, element.props); |
| 18983 | |
| 18984 | // Reserved names are extracted |
| 18985 | var key = element.key; |
| 18986 | var ref = element.ref; |
| 18987 | // Self is preserved since the owner is preserved. |
| 18988 | var self = element._self; |
| 18989 | // Source is preserved since cloneElement is unlikely to be targeted by a |
| 18990 | // transpiler, and the original source is probably a better indicator of the |
| 18991 | // true owner. |
| 18992 | var source = element._source; |
| 18993 | |
| 18994 | // Owner will be preserved, unless ref is overridden |
| 18995 | var owner = element._owner; |
| 18996 | |
| 18997 | if (config != null) { |
| 18998 | if (hasValidRef(config)) { |
| 18999 | // Silently steal the ref from the parent. |
| 19000 | ref = config.ref; |
| 19001 | owner = ReactCurrentOwner.current; |
| 19002 | } |
| 19003 | if (hasValidKey(config)) { |
| 19004 | key = '' + config.key; |
| 19005 | } |
| 19006 | |
| 19007 | // Remaining properties override existing props |
| 19008 | var defaultProps = void 0; |
| 19009 | if (element.type && element.type.defaultProps) { |
| 19010 | defaultProps = element.type.defaultProps; |
| 19011 | } |
| 19012 | for (propName in config) { |
| 19013 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) { |
| 19014 | if (config[propName] === undefined && defaultProps !== undefined) { |
| 19015 | // Resolve default props |
| 19016 | props[propName] = defaultProps[propName]; |
| 19017 | } else { |
| 19018 | props[propName] = config[propName]; |
| 19019 | } |
| 19020 | } |
| 19021 | } |
| 19022 | } |
| 19023 | |
| 19024 | // Children can be more than one argument, and those are transferred onto |
| 19025 | // the newly allocated props object. |
| 19026 | var childrenLength = arguments.length - 2; |
| 19027 | if (childrenLength === 1) { |
| 19028 | props.children = children; |
| 19029 | } else if (childrenLength > 1) { |
| 19030 | var childArray = Array(childrenLength); |
| 19031 | for (var i = 0; i < childrenLength; i++) { |
| 19032 | childArray[i] = arguments[i + 2]; |
| 19033 | } |
| 19034 | props.children = childArray; |
| 19035 | } |
nothing calls this directly
no test coverage detected