* Clone and return a new ReactElement using element as the starting point. * See https://reactjs.org/docs/react-api.html#cloneelement
(element, config, children)
| 1207 | */ |
| 1208 | |
| 1209 | function cloneElement(element, config, children) { |
| 1210 | if (!!(element === null || element === undefined)) { |
| 1211 | { |
| 1212 | throw Error( "React.cloneElement(...): The argument must be a React element, but you passed " + element + "." ); |
| 1213 | } |
| 1214 | } |
| 1215 | |
| 1216 | var propName; // Original props are copied |
| 1217 | |
| 1218 | var props = _assign({}, element.props); // Reserved names are extracted |
| 1219 | |
| 1220 | |
| 1221 | var key = element.key; |
| 1222 | var ref = element.ref; // Self is preserved since the owner is preserved. |
| 1223 | |
| 1224 | var self = element._self; // Source is preserved since cloneElement is unlikely to be targeted by a |
| 1225 | // transpiler, and the original source is probably a better indicator of the |
| 1226 | // true owner. |
| 1227 | |
| 1228 | var source = element._source; // Owner will be preserved, unless ref is overridden |
| 1229 | |
| 1230 | var owner = element._owner; |
| 1231 | |
| 1232 | if (config != null) { |
| 1233 | if (hasValidRef(config)) { |
| 1234 | // Silently steal the ref from the parent. |
| 1235 | ref = config.ref; |
| 1236 | owner = ReactCurrentOwner.current; |
| 1237 | } |
| 1238 | |
| 1239 | if (hasValidKey(config)) { |
| 1240 | key = '' + config.key; |
| 1241 | } // Remaining properties override existing props |
| 1242 | |
| 1243 | |
| 1244 | var defaultProps; |
| 1245 | |
| 1246 | if (element.type && element.type.defaultProps) { |
| 1247 | defaultProps = element.type.defaultProps; |
| 1248 | } |
| 1249 | |
| 1250 | for (propName in config) { |
| 1251 | if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) { |
| 1252 | if (config[propName] === undefined && defaultProps !== undefined) { |
| 1253 | // Resolve default props |
| 1254 | props[propName] = defaultProps[propName]; |
| 1255 | } else { |
| 1256 | props[propName] = config[propName]; |
| 1257 | } |
| 1258 | } |
| 1259 | } |
| 1260 | } // Children can be more than one argument, and those are transferred onto |
| 1261 | // the newly allocated props object. |
| 1262 | |
| 1263 | |
| 1264 | var childrenLength = arguments.length - 2; |
| 1265 | |
| 1266 | if (childrenLength === 1) { |
nothing calls this directly
no test coverage detected