<commit_before>/* eslint new-cap:0 */
import isVoid from '../../util/isVoid';
import { getValueWithIndex, getValueForProps } from '../../core/variables';
import recreateNode from '../recreateNode';
import updateComponent from '../../core/updateComponent';

export default function createNodeWithComponent( componentIndex, props ) {
	let domNode;
	let currentItem;
	let statelessRender;
	const node = {
		overrideItem: null,
		instance: null,
		create( item, treeLifecycle, context ) {
			let toUseItem = item;
			let instance = node.instance;

			if ( node.overrideItem !== null ) {
				toUseItem = node.overrideItem;
			}
			const Component = getValueWithIndex( toUseItem, componentIndex );

			currentItem = item;
			if ( isVoid( Component ) ) {
				domNode = document.createTextNode( '' );
				return domNode;
			} else if ( typeof Component === 'function' ) {
				// stateless component
				if ( !Component.prototype.render ) {
					const nextRender = Component( getValueForProps( props, toUseItem ), context );

					nextRender.parent = item;
					domNode = nextRender.tree.dom.create( nextRender, treeLifecycle, context );
					statelessRender = nextRender;
				} else {
					instance = new Component( getValueForProps( props, toUseItem ) );
					instance.context = context;
					instance.componentWillMount();
					const nextRender = instance.render();
					const childContext = instance.getChildContext();
					let fragmentFirstChild;

					if ( childContext ) {
						context = { ...context, ...childContext };
					}
					nextRender.parent = item;
					domNode = nextRender.tree.dom.create( nextRender, treeLifecycle, context );
					instance._lastRender = nextRender;

					if ( domNode instanceof DocumentFragment ) {
						fragmentFirstChild = domNode.childNodes[0];
					}
					treeLifecycle.addTreeSuccessListener( () => {
						if ( fragmentFirstChild ) {
							domNode = fragmentFirstChild.parentNode;
						}
						instance.componentDidMount();
					} );
					instance.forceUpdate = function () {
						instance.context = context;
						const nextRender = instance.render.call( instance );
						const childContext = instance.getChildContext();

						if ( childContext ) {
							context = { ...context, ...childContext };
						}
						nextRender.parent = currentItem;
						const newDomNode = nextRender.tree.dom.update( instance._lastRender, nextRender, treeLifecycle, context );

						if ( newDomNode ) {
							domNode = newDomNode;
							instance._lastRender.rootNode = domNode;
							instance._lastRender = nextRender;
							return domNode;
						} else {
							instance._lastRender = nextRender;
						}
					}.bind( instance );
				}
			}
			return domNode;
		},
		update( lastItem, nextItem, treeLifecycle, context ) {
			const Component = getValueWithIndex( nextItem, componentIndex );
			let instance = node.instance;

			currentItem = nextItem;
			if ( !Component ) {
				recreateNode( domNode, nextItem, node, treeLifecycle, context );
				if ( instance ) {
					instance._lastRender.rootNode = domNode;
				}
				return domNode;
			}
			if ( typeof Component === 'function' ) {
				// stateless component
				if ( !Component.prototype.render ) {
					const nextRender = Component( getValueForProps( props, nextItem ), context );

					nextRender.parent = currentItem;

					// Edge case. If we update from a stateless component with a null value, we need to re-create it, not update it
					// E.g. start with 'render(template(null), container); ' will cause this.
					if ( !isVoid( node.instance ) ) {
						const newDomNode = nextRender.tree.dom.update( statelessRender || node.instance._lastRender, nextRender, treeLifecycle, context );
					} else {
						//
						// TODO Create the stateless component
					}

					statelessRender = nextRender;
					if ( newDomNode ) {
						if ( domNode.parentNode ) {
							domNode.parentNode.replaceChild( newDomNode, domNode );
						}
						domNode = newDomNode;
						return domNode;
					}
				} else {
					if ( !instance || Component !== instance.constructor ) {
						recreateNode( domNode, nextItem, node, treeLifecycle, context );
						return domNode;
					}
					const prevProps = instance.props;
					const prevState = instance.state;
					const nextState = instance.state;
					const nextProps = getValueForProps( props, nextItem );

					return updateComponent( instance, prevState, nextState, prevProps, nextProps, instance.forceUpdate );
				}
			}
		},
		remove( item, treeLifecycle ) {
			let instance = node.instance;

			if ( instance ) {

				instance._lastRender.tree.dom.remove( instance._lastRender, treeLifecycle );
				instance.componentWillUnmount();
			}
		}
	};

	return node;
}
<commit_msg>corrected a mistake<commit_after>/* eslint new-cap:0 */
import isVoid from '../../util/isVoid';
import { getValueWithIndex, getValueForProps } from '../../core/variables';
import recreateNode from '../recreateNode';
import updateComponent from '../../core/updateComponent';

export default function createNodeWithComponent( componentIndex, props ) {
	let domNode;
	let currentItem;
	let statelessRender;
	const node = {
		overrideItem: null,
		instance: null,
		create( item, treeLifecycle, context ) {
			let toUseItem = item;
			let instance = node.instance;

			if ( node.overrideItem !== null ) {
				toUseItem = node.overrideItem;
			}
			const Component = getValueWithIndex( toUseItem, componentIndex );

			currentItem = item;
			if ( isVoid( Component ) ) {
				domNode = document.createTextNode( '' );
				return domNode;
			} else if ( typeof Component === 'function' ) {
				// stateless component
				if ( !Component.prototype.render ) {
					const nextRender = Component( getValueForProps( props, toUseItem ), context );

					nextRender.parent = item;
					domNode = nextRender.tree.dom.create( nextRender, treeLifecycle, context );
					statelessRender = nextRender;
				} else {
					instance = new Component( getValueForProps( props, toUseItem ) );
					instance.context = context;
					instance.componentWillMount();
					const nextRender = instance.render();
					const childContext = instance.getChildContext();
					let fragmentFirstChild;

					if ( childContext ) {
						context = { ...context, ...childContext };
					}
					nextRender.parent = item;
					domNode = nextRender.tree.dom.create( nextRender, treeLifecycle, context );
					instance._lastRender = nextRender;

					if ( domNode instanceof DocumentFragment ) {
						fragmentFirstChild = domNode.childNodes[0];
					}
					treeLifecycle.addTreeSuccessListener( () => {
						if ( fragmentFirstChild ) {
							domNode = fragmentFirstChild.parentNode;
						}
						instance.componentDidMount();
					} );
					instance.forceUpdate = function () {
						instance.context = context;
						const nextRender = instance.render.call( instance );
						const childContext = instance.getChildContext();

						if ( childContext ) {
							context = { ...context, ...childContext };
						}
						nextRender.parent = currentItem;
						const newDomNode = nextRender.tree.dom.update( instance._lastRender, nextRender, treeLifecycle, context );

						if ( newDomNode ) {
							domNode = newDomNode;
							instance._lastRender.rootNode = domNode;
							instance._lastRender = nextRender;
							return domNode;
						} else {
							instance._lastRender = nextRender;
						}
					}.bind( instance );
				}
			}
			return domNode;
		},
		update( lastItem, nextItem, treeLifecycle, context ) {
			const Component = getValueWithIndex( nextItem, componentIndex );
			let instance = node.instance;

			currentItem = nextItem;
			if ( !Component ) {
				recreateNode( domNode, nextItem, node, treeLifecycle, context );
				if ( instance ) {
					instance._lastRender.rootNode = domNode;
				}
				return domNode;
			}
			if ( typeof Component === 'function' ) {
				// stateless component
				if ( !Component.prototype.render ) {
					const nextRender = Component( getValueForProps( props, nextItem ), context );

					nextRender.parent = currentItem;

					let newDomNode;

					// Edge case. If we update from a stateless component with a null value, we need to re-create it, not update it
					// E.g. start with 'render(template(null), container); ' will cause this.
					if ( !isVoid( node.instance ) ) {
						newDomNode = nextRender.tree.dom.update( statelessRender || node.instance._lastRender, nextRender, treeLifecycle, context );
					} else {
						// newDomNode =
						// TODO Create the stateless component
					}

					statelessRender = nextRender;
					if ( !isVoid ( newDomNode ) ) {
						if ( domNode.parentNode ) {
							domNode.parentNode.replaceChild( newDomNode, domNode );
						}
						domNode = newDomNode;
						return domNode;
					}
				} else {
					if ( !instance || Component !== instance.constructor ) {
						recreateNode( domNode, nextItem, node, treeLifecycle, context );
						return domNode;
					}
					const prevProps = instance.props;
					const prevState = instance.state;
					const nextState = instance.state;
					const nextProps = getValueForProps( props, nextItem );

					return updateComponent( instance, prevState, nextState, prevProps, nextProps, instance.forceUpdate );
				}
			}
		},
		remove( item, treeLifecycle ) {
			let instance = node.instance;

			if ( instance ) {

				instance._lastRender.tree.dom.remove( instance._lastRender, treeLifecycle );
				instance.componentWillUnmount();
			}
		}
	};

	return node;
}

{'fraction_non_alphanumeric': 0.10901977371259385, 'fraction_numerical': 0.00042296711430686265, 'mean_word_length': 2.9002061855670105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6942047', 'n_tokens_mistral': 3491, 'n_tokens_neox': 2630, 'n_words': 669}