mirror of
https://github.com/morluto/rea
synced 2026-10-26 22:28:27 -04:00
perf(javascript): skip nested callables during fingerprint traversal (#1871)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import * as t from "@babel/types";
|
||||
|
||||
/**
|
||||
* Visit every Babel AST node in deterministic source-tree order.
|
||||
* Visit Babel AST nodes in deterministic source-tree order, excluding skipped subtrees.
|
||||
*
|
||||
* `readAncestors` returns a snapshot during `enter`, outermost-first and
|
||||
* ending with the direct parent. Callers
|
||||
@@ -17,6 +17,8 @@ export const traverseJavaScriptAst = (
|
||||
|
||||
/** Callbacks for one deterministic AST traversal. */
|
||||
export interface JavaScriptAstVisitor {
|
||||
/** Omit a child and its subtree without entering or exiting it. */
|
||||
readonly skip?: (node: t.Node) => boolean;
|
||||
readonly enter: (
|
||||
node: t.Node,
|
||||
parent: t.Node | null,
|
||||
@@ -50,6 +52,7 @@ export function* traverseJavaScriptAstSteps(
|
||||
current.nextIndex += 1;
|
||||
if (visited % 1024 === 0) yield;
|
||||
visited += 1;
|
||||
if (visitor.skip?.(child) === true) continue;
|
||||
pending.push(enter(child, current.node));
|
||||
} else {
|
||||
visitor.exit?.(current.node, current.parent);
|
||||
|
||||
Reference in New Issue
Block a user