Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// Regular element with content
} else {
// Element has children, build them in
const childFlags = vNode.childFlags;
if (childFlags === ChildFlags.HasVNodeChildren) {
this.addToQueue(renderedString, position);
this.renderVNodeToQueue(children, context, position);
this.addToQueue('', position);
return;
} else if (childFlags === ChildFlags.HasTextChildren) {
this.addToQueue(renderedString, position);
this.addToQueue(children === '' ? ' ' : escapeText(children + ''), position);
this.addToQueue('', position);
return;
} else if (childFlags & ChildFlags.MultipleChildren) {
this.addToQueue(renderedString, position);
for (let i = 0, len = children.length; i < len; ++i) {
this.renderVNodeToQueue(children[i], context, position);
}
this.addToQueue('', position);
return;
}
if (html) {
this.addToQueue(renderedString + html + '', position);
return;
}
// Close element if it's not void
if (!isVoidElement) {
this.addToQueue(renderedString + '', position);
}
}
} else {
currentNode = hydrateVNode(children as VNode, parentNode, currentNode as Element, context, isSVG, lifecycle);
currentNode = currentNode ? currentNode.nextSibling : null;
}
} else if (childFlags === ChildFlags.HasTextChildren) {
if (isNull(currentNode)) {
parentNode.appendChild(document.createTextNode(children as string));
} else if (parentNode.childNodes.length !== 1 || currentNode.nodeType !== 3) {
parentNode.textContent = children as string;
} else {
if (currentNode.nodeValue !== children) {
currentNode.nodeValue = children as string;
}
}
currentNode = null;
} else if (childFlags & ChildFlags.MultipleChildren) {
let prevVNodeIsTextNode = false;
for (let i = 0, len = (children as VNode[]).length; i < len; ++i) {
const child = (children as VNode[])[i];
if (isNull(currentNode) || (prevVNodeIsTextNode && (child.flags & VNodeFlags.Text) > 0)) {
_M(child as VNode, parentNode, context, isSVG, currentNode, lifecycle);
} else {
currentNode = hydrateVNode(child as VNode, parentNode, currentNode as Element, context, isSVG, lifecycle);
currentNode = currentNode ? currentNode.nextSibling : null;
}
prevVNodeIsTextNode = (child.flags & VNodeFlags.Text) > 0;
}
}
}
}
if (String(type).match(/[\s\n\/='"\0<>]/)) {
throw renderedString;
}
return renderedString;
} else if ((flags & VNodeFlags.Text) !== 0) {
return children === '' ? ' ' : escapeText(children);
} else if ((flags & VNodeFlags.Fragment) !== 0) {
const childFlags = vNode.childFlags;
if (childFlags === ChildFlags.HasVNodeChildren) {
return '';
} else if (childFlags & ChildFlags.MultipleChildren) {
let renderedString = '';
for (let i = 0, len = children.length; i < len; ++i) {
renderedString += renderVNodeToString(children[i], vNode, context);
}
return renderedString;
}
} else {
if (process.env.NODE_ENV !== 'production') {
if (typeof vNode === 'object') {
throwError(`renderToString() received an object that's not a valid VNode, you should stringify it first. Object: "${JSON.stringify(vNode)}".`);
} else {
throwError(`renderToString() expects a valid VNode, instead it received an object with the type "${typeof vNode}".`);
}
}
if (_vNode.dom === DOM) {
return true;
}
flags = _vNode.flags;
children = _vNode.children;
if (flags & VNodeFlags.ComponentClass) {
stack.push(children.$LI);
} else if (flags & VNodeFlags.ComponentFunction) {
stack.push(children);
} else {
flags = _vNode.childFlags;
if (flags & ChildFlags.MultipleChildren) {
let i = children.length;
while (i--) {
stack.push(children[i]);
}
} else if (flags & ChildFlags.HasVNodeChildren) {
stack.push(children);
}
}
}
return false;
}
public renderChildren(children: VNode[] | VNode | string, context: any, childFlags: ChildFlags) {
if (childFlags === ChildFlags.HasVNodeChildren) {
return this.renderNode(children, context);
}
if (childFlags === ChildFlags.HasTextChildren) {
return this.push(children === '' ? ' ' : escapeText(children + ''));
}
if (childFlags & ChildFlags.MultipleChildren) {
return (children as VNode[]).reduce((p, child) => {
return p.then(() => {
return Promise.resolve(this.renderNode(child, context)).then(() => !!(child.flags & VNodeFlags.Text));
});
}, Promise.resolve(false));
}
}