<commit_before>import React from 'react'
import generate from 'babel-generator'
import BasicElements from './elements'

export function reduce(element) {
    if (element instanceof RegExp) {
        return (
            <regExp value={element} />
        );
    } else if (element === null) {
        return (
            <null />
        );
    } else if (typeof element === 'string') {
        return (
            <string value={element} />
        );
    } else if (typeof element === 'boolean') {
        return (
            <boolean value={element} />
        );
    } else if (typeof element === 'number') {
        return (
            <number value={element} />
        );
    } else if (Array.isArray(element)) {
        return element.map(reduce);
    } else if (typeof element.type === 'function') {
        return reduce(element.type(element.props));
    } else if (typeof element === 'undefined') {
        return undefined;
    }

    let reducedChildren = [];

    if (Array.isArray(element.props.children)) {
        reducedChildren = element.props.children.map(reduce);
    } else if (element !== null) {
        reducedChildren = [reduce(element.props.children)];
    }

    let flattenedChildren = flatten(reducedChildren);

    return {
        ...element,
        props: {
            ...element.props,
            children: flattenedChildren
        }
    };
}

export function flatten(array) {
    return array.reduce(function (accumulator, currentValue) {
        let currentValueArray;
        
        if (Array.isArray(currentValue)) {
            currentValueArray = flatten(currentValue);
        } else if (typeof currentValue !== 'undefined') {
            currentValueArray = [currentValue];
        } else {
            currentValueArray = [];
        }

        return accumulator.concat(currentValueArray);
    }, []);
}

export function generateAST(element) {
    let children;

    if (Array.isArray(element.props.children)) {
        children = element.props.children.map(generateAST);
    } else if (typeof element.props.children === 'object') {
        children = [generateAST(element.props.children)];
    } else {
        children = [];
    }

    return BasicElements[element.type](element, element.props, children);
}

const render = (element) => generate(generateAST(reduce(element))).code;
export default render;
export { render };<commit_msg>More concise code, some things are const now.<commit_after>import React from 'react'
import generate from 'babel-generator'
import BasicElements from './elements'

export function reduce(element) {
    if (element instanceof RegExp) {
        return (
            <regExp value={element} />
        );
    } else if (element === null) {
        return (
            <null />
        );
    } else if (typeof element === 'string') {
        return (
            <string value={element} />
        );
    } else if (typeof element === 'boolean') {
        return (
            <boolean value={element} />
        );
    } else if (typeof element === 'number') {
        return (
            <number value={element} />
        );
    } else if (Array.isArray(element)) {
        return element.map(reduce);
    } else if (typeof element.type === 'function') {
        return reduce(element.type(element.props));
    } else if (typeof element === 'undefined') {
        return undefined;
    }

    let reducedChildren = [];

    if (Array.isArray(element.props.children)) {
        reducedChildren = element.props.children.map(reduce);
    } else if (element !== null) {
        reducedChildren = [reduce(element.props.children)];
    }

    const flattenedChildren = flatten(reducedChildren);

    return {
        ...element,
        props: {
            ...element.props,
            children: flattenedChildren
        }
    };
}

export function flatten(array) {
    return array.reduce(function (accumulator, currentValue) {
        let currentValueArray = [];
        
        if (Array.isArray(currentValue)) {
            currentValueArray = flatten(currentValue);
        } else if (typeof currentValue !== 'undefined') {
            currentValueArray = [currentValue];
        }

        return accumulator.concat(currentValueArray);
    }, []);
}

export function generateAST(element) {
    let children = [];

    if (Array.isArray(element.props.children)) {
        children = element.props.children.map(generateAST);
    } else if (typeof element.props.children === 'object') {
        children = [generateAST(element.props.children)];
    }

    return BasicElements[element.type](element, element.props, children);
}

const render = (element) => generate(generateAST(reduce(element))).code;
export default render;
export { render };
{'fraction_non_alphanumeric': 0.13088452607135317, 'fraction_numerical': 0.0, 'mean_word_length': 2.3249122807017546, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5362767', 'n_tokens_mistral': 1256, 'n_tokens_neox': 1228, 'n_words': 297}