* Clone and return a new ReactElement using element as the starting point. * See https://reactjs.org/docs/react-api.html#cloneelement
(element, config, children)
| 20227 | * See https://reactjs.org/docs/react-api.html#cloneelement |
| 20228 | */ |
| 20229 | function cloneElement(element, config, children) { |
| 20230 | var propName = void 0; |
| 20231 | |
| 20232 | // Original props are copied |
| 20233 | var props = _assign({}, element.props); |
| 20234 | |
| 20235 | // Reserved names are extracted |
| 20236 | var key = element.key; |
| 20237 | var ref = element.ref; |
| 20238 | // Self is preserved since the owner is preserved. |
| 20239 | var self = element._self; |
| 20240 | // Source is preserved since cloneElement is unlikely to be targeted by a |
| 20241 | // transpiler, and the original source is probably a better indicator of the |
| 20242 | // true owner. |
| 20243 | var source = element._source; |
| 20244 | |
| 20245 | // Owner will be preserved, unless ref is overridden |
| 20246 | var owner = element._owner; |
| 20247 | |
| 20248 | if (config != null) { |
| 20249 | if (hasValidRef(config)) { |
| 20250 | // Silently steal the ref from the parent. |
| 20251 | ref = config.ref; |
| 20252 | owner = ReactCurrentOwner.current; |
| 20253 | } |
| 20254 | if (hasValidKey(config)) { |
| 20255 | key = '' + config.key; |
| 20256 | } |
| 20257 | |
| 20258 | // Remaining properties override existing props |
| 20259 | var defaultProps = void 0; |
| 20260 | if (element.type && element.type.defaultProps) { |
| 20261 | defaultProps = element.type.defaultProps; |
| 20262 | } |
| 20263 | for (propName in config) { |
| 20264 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) { |
| 20265 | if (config[propName] === undefined && defaultProps !== undefined) { |
| 20266 | // Resolve default props |
| 20267 | props[propName] = defaultProps[propName]; |
| 20268 | } else { |
| 20269 | props[propName] = config[propName]; |
| 20270 | } |
| 20271 | } |
| 20272 | } |
| 20273 | } |
| 20274 | |
| 20275 | // Children can be more than one argument, and those are transferred onto |
| 20276 | // the newly allocated props object. |
| 20277 | var childrenLength = arguments.length - 2; |
| 20278 | if (childrenLength === 1) { |
| 20279 | props.children = children; |
| 20280 | } else if (childrenLength > 1) { |
| 20281 | var childArray = Array(childrenLength); |
| 20282 | for (var i = 0; i < childrenLength; i++) { |
| 20283 | childArray[i] = arguments[i + 2]; |
| 20284 | } |
| 20285 | props.children = childArray; |
| 20286 | } |
nothing calls this directly
no test coverage detected