<commit_before>import {
	isArray,
	isNull,
	isStringOrNumber,
	isString,
	isInvalid,
	isStatefulComponent,
	throwError,
	isObject
} from '../shared';
import {
	replaceChild,
	normaliseChild,
	createStatelessComponentInput,
	createStatefulComponentInstance
} from './utils';
import {
	mountVText,
	mountStatelessComponentCallbacks,
	mountStatefulComponentCallbacks
} from './mounting';
import {
	isVPlaceholder,
	isVFragment,
	isVText,
	isVElement,
	isVComponent,
	isOptVElement
} from '../core/shapes';
import {
	ValueTypes,
	isKeyedListChildrenType,
	isTextChildrenType,
	isNodeChildrenType,
	isNonKeyedListChildrenType,
	isUnknownChildrenType
} from '../core/constants';
import { componentToDOMNodeMap } from './rendering';
import { svgNS } from './constants';

function hydrateChild(child, childNodes, counter, parentDom, lifecycle, context) {
	const domNode = childNodes[counter.i];

	if (isVText(child)) {
		const text = child.text;

		child.dom = domNode;
		if (domNode.nodeType === 3 && text !== '') {
			domNode.nodeValue = text;
		} else {
			const newDomNode = mountVText(text, null);

			replaceChild(parentDom, newDomNode, domNode);
			childNodes.splice(childNodes.indexOf(domNode), 1, newDomNode);
			child.dom = newDomNode;
		}
	} else if (isVPlaceholder(child)) {
		child.dom = domNode;
	} else if (isVFragment(child)) {
		const items = child.items;

		// this doesn't really matter, as it won't be used again, but it's what it should be given the purpose of VList
		child.dom = document.createDocumentFragment();
		for (let i = 0; i < items.length; i++) {
			const rebuild = hydrateChild(normaliseChild(items, i), childNodes, counter, parentDom, lifecycle, context);

			if (rebuild) {
				return true;
			}
		}
		// at the end of every VList, there should be a "pointer". It's an empty TextNode used for tracking the VList
		const pointer = childNodes[counter.i++];

		if (pointer && pointer.nodeType === 3) {
			child.pointer = pointer;
		} else {
			// there is a problem, we need to rebuild this tree
			return true;
		}
	} else {
		const rebuild = hydrate(child, domNode, lifecycle, context);

		if (rebuild) {
			return true;
		}
	}
	counter.i++;
}

export function normaliseChildNodes(dom) {
	const rawChildNodes = dom.childNodes;
	let length = rawChildNodes.length;
	let i = 0;

	while (i < length) {
		const rawChild = rawChildNodes[i];

		if (rawChild.nodeType === 8) {
			if (rawChild.data === '!') {
				const placeholder = document.createTextNode('');

				dom.replaceChild(placeholder, rawChild);
				i++;
			} else {
				dom.removeChild(rawChild);
				length--;
			}
		} else {
			i++;
		}
	}
}

function hydrateVComponent(vComponent, dom, lifecycle, context) {
	const component = vComponent.component;
	const props = vComponent.props;
	const hooks = vComponent.hooks;
	const ref = vComponent.ref;

	vComponent.dom = dom;
	if (isStatefulComponent(vComponent)) {
		const isSVG = dom.namespaceURI === svgNS;
		const instance = createStatefulComponentInstance(component, props, context, isSVG);
		const input = instance._lastInput;

		instance._vComponent = vComponent;
		hydrate(input, dom, lifecycle, context);
		mountStatefulComponentCallbacks(ref, instance, lifecycle);
		componentToDOMNodeMap.set(instance, dom);
		vComponent.instance = instance;
	} else {
		const input = createStatelessComponentInput(component, props, context);
<commit_msg>Pass context when hydrating<commit_after>import {
	isArray,
	isNull,
	isStringOrNumber,
	isString,
	isInvalid,
	isStatefulComponent,
	throwError,
	isObject
} from '../shared';
import {
	replaceChild,
	normaliseChild,
	createStatelessComponentInput,
	createStatefulComponentInstance
} from './utils';
import {
	mountVText,
	mountStatelessComponentCallbacks,
	mountStatefulComponentCallbacks
} from './mounting';
import {
	isVPlaceholder,
	isVFragment,
	isVText,
	isVElement,
	isVComponent,
	isOptVElement
} from '../core/shapes';
import {
	ValueTypes,
	isKeyedListChildrenType,
	isTextChildrenType,
	isNodeChildrenType,
	isNonKeyedListChildrenType,
	isUnknownChildrenType
} from '../core/constants';
import { componentToDOMNodeMap } from './rendering';
import { svgNS } from './constants';

function hydrateChild(child, childNodes, counter, parentDom, lifecycle, context) {
	const domNode = childNodes[counter.i];

	if (isVText(child)) {
		const text = child.text;

		child.dom = domNode;
		if (domNode.nodeType === 3 && text !== '') {
			domNode.nodeValue = text;
		} else {
			const newDomNode = mountVText(text, null);

			replaceChild(parentDom, newDomNode, domNode);
			childNodes.splice(childNodes.indexOf(domNode), 1, newDomNode);
			child.dom = newDomNode;
		}
	} else if (isVPlaceholder(child)) {
		child.dom = domNode;
	} else if (isVFragment(child)) {
		const items = child.items;

		// this doesn't really matter, as it won't be used again, but it's what it should be given the purpose of VList
		child.dom = document.createDocumentFragment();
		for (let i = 0; i < items.length; i++) {
			const rebuild = hydrateChild(normaliseChild(items, i), childNodes, counter, parentDom, lifecycle, context);

			if (rebuild) {
				return true;
			}
		}
		// at the end of every VList, there should be a "pointer". It's an empty TextNode used for tracking the VList
		const pointer = childNodes[counter.i++];

		if (pointer && pointer.nodeType === 3) {
			child.pointer = pointer;
		} else {
			// there is a problem, we need to rebuild this tree
			return true;
		}
	} else {
		const rebuild = hydrate(child, domNode, lifecycle, context);

		if (rebuild) {
			return true;
		}
	}
	counter.i++;
}

export function normaliseChildNodes(dom) {
	const rawChildNodes = dom.childNodes;
	let length = rawChildNodes.length;
	let i = 0;

	while (i < length) {
		const rawChild = rawChildNodes[i];

		if (rawChild.nodeType === 8) {
			if (rawChild.data === '!') {
				const placeholder = document.createTextNode('');

				dom.replaceChild(placeholder, rawChild);
				i++;
			} else {
				dom.removeChild(rawChild);
				length--;
			}
		} else {
			i++;
		}
	}
}

function hydrateVComponent(vComponent, dom, lifecycle, context) {
	const component = vComponent.component;
	const props = vComponent.props;
	const hooks = vComponent.hooks;
	const ref = vComponent.ref;

	vComponent.dom = dom;
	if (isStatefulComponent(vComponent)) {
		const isSVG = dom.namespaceURI === svgNS;
		const instance = createStatefulComponentInstance(component, props, context, isSVG);
		const input = instance._lastInput;

		instance._vComponent = vComponent;
		hydrate(input, dom, lifecycle, instance._childContext);
		mountStatefulComponentCallbacks(ref, instance, lifecycle);
		componentToDOMNodeMap.set(instance, dom);
		vComponent.instance = instance;
	} else {
		const input = createStatelessComponentInput(component, props, context);

{'fraction_non_alphanumeric': 0.11753428697832179, 'fraction_numerical': 0.0017696504940274296, 'mean_word_length': 4.286048324240062, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '878876', 'n_tokens_mistral': 2397, 'n_tokens_neox': 2179, 'n_words': 565}