Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
case ClassComponent:
return {
nodeType: 'class',
type: node.type,
props: {...node.memoizedProps},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: node.stateNode,
rendered: childrenToTree(node.child)
};
case FunctionalComponent: // 1
return {
nodeType: 'function',
type: node.type,
props: {...node.memoizedProps},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child)
};
case HostComponent: {
// 5
let renderedNodes = flatten(nodeAndSiblingsArray(node.child).map(toTree));
if (renderedNodes.length === 0) {
renderedNodes = [node.memoizedProps.children];
}
return {
nodeType: 'host',
type: node.type,
props: {...node.memoizedProps},
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
// somewhere else. Should talk to sebastian about this perhaps
const node = findCurrentFiberUsingSlowPath(vnode);
switch (node.tag) {
case HostRoot: // 3
return childrenToTree(node.child);
case HostPortal: { // 4
const {
stateNode: { containerInfo },
memoizedProps: children,
} = node;
const props = { containerInfo, children };
return {
nodeType: 'portal',
type: Portal,
props,
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
}
case ClassComponent:
return {
nodeType: 'class',
type: node.type,
props: { ...node.memoizedProps },
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: node.stateNode,
rendered: childrenToTree(node.child),
};
case FunctionalComponent: // 1
props: { ...node.memoizedProps },
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: null,
rendered: childrenToTree(node.child),
};
case HostComponent: { // 5
let renderedNodes = flatten(nodeAndSiblingsArray(node.child).map(toTree));
if (renderedNodes.length === 0) {
renderedNodes = [node.memoizedProps.children];
}
return {
nodeType: 'host',
type: node.type,
props: { ...node.memoizedProps },
key: ensureKeyOrUndefined(node.key),
ref: node.ref,
instance: node.stateNode,
rendered: renderedNodes,
};
}
case HostText: // 6
return node.memoizedProps;
case FragmentType: // 10
case Mode: // 11
return childrenToTree(node.child);
default:
throw new Error(`Enzyme Internal Error: unknown node with tag ${node.tag}`);
}
}
const nodeType = nodeTypeFromType(type);
if (nodeType === 'host' && props.dangerouslySetInnerHTML) {
if (props.children != null) {
const error = new Error('Can only set one of `children` or `props.dangerouslySetInnerHTML`.');
error.name = 'Invariant Violation';
throw error;
}
}
return {
nodeType,
type,
props,
key: ensureKeyOrUndefined(key),
ref,
instance: null,
rendered,
};
}
return {
nodeType: 'host',
type: el.type,
props: el._store.props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
instance: inst._instance.getDOMNode(),
rendered: values(children).map(instanceToTree),
};
}
if (inst._renderedComponent) {
return {
nodeType: 'class',
type: el.type,
props: el._store.props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
};
}
throw new Error('Enzyme Internal Error: unknown instance encountered');
}
function elementToTree(el) {
if (!isPortal(el)) {
return utilElementToTree(el, elementToTree);
}
const { children, containerInfo } = el;
const props = { children, containerInfo };
return {
nodeType: 'portal',
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
}
getNode() {
if (isDOM) {
return elementToTree(cachedNode);
}
const output = renderer.getRenderOutput();
return {
nodeType: compositeTypeToNodeType(renderer._instance._compositeType),
type: cachedNode.type,
props: cachedNode.props,
key: ensureKeyOrUndefined(cachedNode.key),
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
};
},
simulateEvent(node, event, ...args) {
function elementToTree(el) {
if (!isPortal(el)) {
return utilElementToTree(el, elementToTree);
}
const { children, containerInfo } = el;
const props = { children, containerInfo };
return {
nodeType: 'portal',
type: Portal,
props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref || null,
instance: null,
rendered: elementToTree(el.children),
};
}
if (inst._renderedComponent) {
return {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
instance: inst._instance || inst._hostNode || null,
rendered: instanceToTree(inst._renderedComponent),
};
}
return {
nodeType: nodeType(inst),
type: el.type,
props: el.props,
key: ensureKeyOrUndefined(el.key),
ref: el.ref,
instance: inst._instance || null,
rendered: childrenFromInst(inst, el).map(instanceToTree),
};
}
getNode() {
if (isDOM) {
return elementToTree(cachedNode);
}
const output = renderer.getRenderOutput();
return {
nodeType: typeToNodeType(cachedNode.type),
type: cachedNode.type,
props: cachedNode.props,
key: ensureKeyOrUndefined(cachedNode.key),
ref: cachedNode.ref,
instance: renderer._instance._instance,
rendered: elementToTree(output),
};
},
simulateEvent(node, event, ...args) {