1. export function createElement(type, config, children) {
    2. let propName;
    3. // Reserved names are extracted
    4. const props = {};
    5. let key = null;
    6. let ref = null;
    7. let self = null;
    8. let source = null;
    9. if (config != null) {
    10. if (hasValidRef(config)) {
    11. ref = config.ref;
    12. }
    13. if (hasValidKey(config)) {
    14. key = '' + config.key;
    15. }
    16. // Remaining properties are added to a new props object
    17. for (propName in config) {
    18. if (
    19. hasOwnProperty.call(config, propName) &&
    20. !RESERVED_PROPS.hasOwnProperty(propName)
    21. ) {
    22. props[propName] = config[propName];
    23. }
    24. }
    25. }
    26. // Children can be more than one argument, and those are transferred onto
    27. // the newly allocated props object.
    28. const childrenLength = arguments.length - 2;
    29. if (childrenLength === 1) {
    30. props.children = children;
    31. } else if (childrenLength > 1) {
    32. const childArray = Array(childrenLength);
    33. for (let i = 0; i < childrenLength; i++) {
    34. childArray[i] = arguments[i + 2];
    35. }
    36. props.children = childArray;
    37. }
    38. // Resolve default props
    39. if (type && type.defaultProps) {
    40. const defaultProps = type.defaultProps;
    41. for (propName in defaultProps) {
    42. if (props[propName] === undefined) {
    43. props[propName] = defaultProps[propName];
    44. }
    45. }
    46. }
    47. return ReactElement(
    48. type,
    49. key,
    50. ref,
    51. self,
    52. source,
    53. ReactCurrentOwner.current,
    54. props,
    55. );
    56. }