MCPcopy
hub / github.com/flightcontrolhq/superjson / traverse

Function traverse

src/plainer.ts:30–62  ·  view source on GitHub ↗
(
  tree: MinimisedTree<T>,
  walker: (v: T, path: string[]) => void,
  version: number,
  origin: string[] = []
)

Source from the content-addressed store, hash-verified

28const enableLegacyPaths = (version: number) => version < 1;
29
30function traverse<T>(
31 tree: MinimisedTree<T>,
32 walker: (v: T, path: string[]) => void,
33 version: number,
34 origin: string[] = []
35): void {
36 if (!tree) {
37 return;
38 }
39
40 const legacyPaths = enableLegacyPaths(version);
41 if (!isArray(tree)) {
42 forEach(tree, (subtree, key) =>
43 traverse(subtree, walker, version, [
44 ...origin,
45 ...parsePath(key, legacyPaths),
46 ])
47 );
48 return;
49 }
50
51 const [nodeValue, children] = tree;
52 if (children) {
53 forEach(children, (child, key) => {
54 traverse(child, walker, version, [
55 ...origin,
56 ...parsePath(key, legacyPaths),
57 ]);
58 });
59 }
60
61 walker(nodeValue, origin);
62}
63
64export function applyValueAnnotations(
65 plain: any,

Callers 1

applyValueAnnotationsFunction · 0.85

Calls 5

enableLegacyPathsFunction · 0.85
isArrayFunction · 0.85
forEachFunction · 0.85
parsePathFunction · 0.85
walkerFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…