<commit_before>import createStaticNode from './shapes/staticNode';
import isArray from '../util/isArray';
import isStringOrNumber from '../util/isStringOrNumber';
import isVoid from '../util/isVoid';
import DOMRegistry from '../DOM/DOMRegistry';
import quoteAttributeValueForBrowser from './quoteAttributeValueForBrowser';

function countChildren(children) {
	if (!isVoid(children)) {
		if (isArray(children)) {
			return children.length;
		} else {
			return 1;
		}
	} else {
		return 0;
	}
}

/**
 *  WORK IN PROGRESS
 *
 *  Need to run tests for this one!!
 *
 * */
function renderMarkupForStyles(styles, component) {

	let serialized = '';

	for (let styleName in styles) {

		let styleValue = styles[styleName];

		if (styleValue !== null) {
			serialized += styleName + ':';
			serialized += styleValue + ';';
		}
	}
	return serialized || null;
}

function renderMarkupForAttributes(name, value) {

	const propertyInfo = DOMRegistry[name] || null;

	if (propertyInfo) {

		if (isVoid(value) ||
			propertyInfo.hasBooleanValue && !value ||
			propertyInfo.hasNumericValue && (value !== value) ||
			propertyInfo.hasPositiveNumericValue && value < 1 ||
			value.length === 0) {
			return '';
		}
		let attributeName = propertyInfo.attributeName;
		if (propertyInfo.hasBooleanValue) {
			return attributeName + '=""';
		}
		return `${ attributeName }=${ quoteAttributeValueForBrowser(value) }`;
	} else {

		if (isVoid(value)) {
			return '';
		}

		// custom attributes
		return `${ name }=${ quoteAttributeValueForBrowser(value) }`;
	}
}
function createStaticAttributes(node, excludeAttrs) {

	let HTML = '';

	const props = node.attrs;

	for (let propKey in props) {

		var propValue = props[propKey];
		if (propValue == null) {
			continue;
		}
		renderMarkupForStyles
		if (propKey === 'style') {
			propValue = renderMarkupForStyles(propKey, propValue );
		}

		let markup = null;

		markup =  renderMarkupForAttributes(propKey, propValue );

		if (markup) {
			HTML += ' ' + markup;
		}

	}
	return HTML;

 // TODO
	return Object.keys(node.attrs).map(attr => {
		if (attr === 'data-inferno') {
			return `${ attr }`;
		}
		return `${ attr }="${ node.attrs[attr] }"`;
	}).join(' ');
}

function createStaticTreeChildren(children) {
	let isLastChildNode = false;

	if (isArray(children)) {
		return children.map((child, i) => {
			if (isStringOrNumber(child)) {
				if (isLastChildNode) {
					isLastChildNode = true;
					return '<!---->' + child;
				} else {
					isLastChildNode = true;
					return child;
				}
			}
			isLastChildNode = false;
			return createStaticTreeNode(false, child);
		}).join('');
	} else {
		if (isStringOrNumber(children)) {
			return children;
		} else {
			return createStaticTreeNode(false, children);
		}
	}
}

function createStaticTreeNode(isRoot, node) {
	let staticNode;

	if (isVoid(node)) {
		return '';
	}
	if (node.tag) {
		if (isRoot) {
			if (!node.attrs) {
				node.attrs = {};
			}
			node.attrs['data-inferno'] = true;
		}
		staticNode = `<${ node.tag }`;
		if (node.attrs) {
			staticNode += ' ' + createStaticAttributes(node, null);
		}
		staticNode += `>`;
		if (!isVoid(node.children)) {
			staticNode += createStaticTreeChildren(node.children);
		} else if (!isVoid(node.text)) {
			staticNode += node.text;
		}
		// check if node is self closing?
		staticNode += `</${ node.tag }>`;
	}

	return staticNode;<commit_msg>fixed data-inferno<commit_after>import createStaticNode from './shapes/staticNode';
import isArray from '../util/isArray';
import isStringOrNumber from '../util/isStringOrNumber';
import isVoid from '../util/isVoid';
import DOMRegistry from '../DOM/DOMRegistry';
import quoteAttributeValueForBrowser from './quoteAttributeValueForBrowser';

function countChildren(children) {
	if (!isVoid(children)) {
		if (isArray(children)) {
			return children.length;
		} else {
			return 1;
		}
	} else {
		return 0;
	}
}

/**
 *  WORK IN PROGRESS
 *
 *  Need to run tests for this one!!
 *
 * */
function renderMarkupForStyles(styles, component) {

	let serialized = '';

	for (let styleName in styles) {

		let styleValue = styles[styleName];

		if (styleValue !== null) {
			serialized += styleName + ':';
			serialized += styleValue + ';';
		}
	}
	return serialized || null;
}

function renderMarkupForAttributes(name, value) {

	if (name === 'data-inferno') {
		return `${ name }`;
	}

	const propertyInfo = DOMRegistry[name] || null;

	if (propertyInfo) {

		if (isVoid(value) ||
			propertyInfo.hasBooleanValue && !value ||
			propertyInfo.hasNumericValue && (value !== value) ||
			propertyInfo.hasPositiveNumericValue && value < 1 ||
			value.length === 0) {
			return '';
		}
		let attributeName = propertyInfo.attributeName;
		if (propertyInfo.hasBooleanValue) {
			return attributeName + '=""';
		}
		return `${ attributeName }=${ quoteAttributeValueForBrowser(value) }`;
	} else {

		if (isVoid(value)) {
			return '';
		}

		// custom attributes
		return `${ name }=${ quoteAttributeValueForBrowser(value) }`;
	}
}
function createStaticAttributes(node, excludeAttrs) {

	let HTML = '';

	const props = node.attrs;

	for (let propKey in props) {

		var propValue = props[propKey];

		if (propValue == null) {
			continue;
		}

		if (propKey === 'style') {
			propValue = renderMarkupForStyles(propKey, propValue );
		}

		let markup = null;

		markup =  renderMarkupForAttributes(propKey, propValue );

		if (markup) {
			HTML += ' ' + markup;
		}

	}
	return HTML;

 // TODO
	return Object.keys(node.attrs).map(attr => {
		if (attr === 'data-inferno') {
			return `${ attr }`;
		}
		return `${ attr }="${ node.attrs[attr] }"`;
	}).join(' ');
}

function createStaticTreeChildren(children) {
	let isLastChildNode = false;

	if (isArray(children)) {
		return children.map((child, i) => {
			if (isStringOrNumber(child)) {
				if (isLastChildNode) {
					isLastChildNode = true;
					return '<!---->' + child;
				} else {
					isLastChildNode = true;
					return child;
				}
			}
			isLastChildNode = false;
			return createStaticTreeNode(false, child);
		}).join('');
	} else {
		if (isStringOrNumber(children)) {
			return children;
		} else {
			return createStaticTreeNode(false, children);
		}
	}
}

function createStaticTreeNode(isRoot, node) {
	let staticNode;

	if (isVoid(node)) {
		return '';
	}
	if (node.tag) {
		if (isRoot) {
			if (!node.attrs) {
				node.attrs = {};
			}
			node.attrs['data-inferno'] = true;
		}
		staticNode = `<${ node.tag }`;
		if (node.attrs) {
			staticNode += createStaticAttributes(node, null);
		}
		staticNode += `>`;
		if (!isVoid(node.children)) {
			staticNode += createStaticTreeChildren(node.children);
		} else if (!isVoid(node.text)) {
			staticNode += node.text;
		}
		// check if node is self closing?
		staticNode += `</${ node.tag }>`;
	}

	return staticNode;
{'fraction_non_alphanumeric': 0.156042985426174, 'fraction_numerical': 0.001177682908876785, 'mean_word_length': 3.5142857142857142, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, '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': '4790214', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2263, 'n_words': 494}