perf: unroll children
This commit is contained in:
parent
49b3fc3c46
commit
bfdd55e44a
|
@ -37,14 +37,18 @@ export default function traverse(node, visitor) {
|
||||||
throw new Error(`node type ${node.type} not traversable. (${Object.keys(node).join(', ')})`);
|
throw new Error(`node type ${node.type} not traversable. (${Object.keys(node).join(', ')})`);
|
||||||
}
|
}
|
||||||
visitor(node, 'enter');
|
visitor(node, 'enter');
|
||||||
const path = TRAVERSAL_PATH[node.type];
|
for (const key of TRAVERSAL_PATH[node.type]) {
|
||||||
const children = [];
|
if (Array.isArray(node[key])) {
|
||||||
for (const key of path) {
|
for (const child of node[key]) {
|
||||||
children.push(...(Array.isArray(node[key]) ? node[key] : [node[key]]));
|
if (child) {
|
||||||
}
|
traverse(child, visitor);
|
||||||
for (const child of children) {
|
}
|
||||||
if (child) {
|
}
|
||||||
traverse(child, visitor);
|
}
|
||||||
|
else {
|
||||||
|
if (node[key]) {
|
||||||
|
traverse(node[key], visitor);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
visitor(node, 'exit');
|
visitor(node, 'exit');
|
||||||
|
|
Loading…
Reference in New Issue
Block a user