diff --git a/graph/__snapshots__/top_decl_deps_test.ts.snap b/graph/__snapshots__/top_decl_deps_test.ts.snap index 7d89633..9a65ec1 100644 --- a/graph/__snapshots__/top_decl_deps_test.ts.snap +++ b/graph/__snapshots__/top_decl_deps_test.ts.snap @@ -2,18 +2,18 @@ export const snapshot = {}; snapshot[`getTopDeclDeps() converts graph into valid TopDeclDeps 1`] = ` { - "AliasedImport (/d.tsx:8:14)": [ - "a (/a.ts:1:14)", + "vscode://file/b.tsx:5:14?kind=VariableDeclaration&name=CompAAA": [ + "vscode://file/a.ts:3:14?kind=VariableDeclaration&name=aaa", + "vscode://file/a.ts:1:14?kind=VariableDeclaration&name=a", ], - "CompAAA (/b.tsx:5:14)": [ - "aaa (/a.ts:3:14)", - "a (/a.ts:1:14)", + "vscode://file/d.tsx:4:14?kind=VariableDeclaration&name=InnerImport": [ + "vscode://file/b.tsx:4:14?kind=VariableDeclaration&name=Comp", + "vscode://file/a.ts:1:14?kind=VariableDeclaration&name=a", + "vscode://file/c.tsx:7:14?kind=VariableDeclaration&name=Page", + "vscode://file/b.tsx:8:14?kind=VariableDeclaration&name=Unrelated", ], - "InnerImport (/d.tsx:4:14)": [ - "Comp (/b.tsx:4:14)", - "a (/a.ts:1:14)", - "Page (/c.tsx:7:14)", - "Unrelated (/b.tsx:8:14)", + "vscode://file/d.tsx:8:14?kind=VariableDeclaration&name=AliasedImport": [ + "vscode://file/a.ts:1:14?kind=VariableDeclaration&name=a", ], } `; diff --git a/graph/_format.ts b/graph/_format.ts index afa3f21..52b653f 100644 --- a/graph/_format.ts +++ b/graph/_format.ts @@ -2,7 +2,6 @@ import { Reducer, Stream } from "https://deno.land/x/rimbu@1.2.0/stream/mod.ts" import { encodeVSCodeURI, prettyPrintURI } from "./vscode_uri.ts" import type { Declaration, DeclDeps } from "./decl_deps.ts" -import type { TopDeclDeps } from "./top_decl_deps.ts" export const serializeNoColor = (x: unknown) => Deno.inspect(x, { @@ -28,14 +27,3 @@ export const declDepsSerializer = (declDeps: DeclDeps) => serializeNoColor( asRecord((x) => prettyPrintURI(encodeVSCodeURI(x)))(declDeps), ) - -export const topDeclDepsSerializer = (topDeclDeps: TopDeclDeps): string => - serializeNoColor(Object.fromEntries( - Array.from(topDeclDeps.entries()) - .map(([decl, deps]) => - [ - prettyPrintURI(decl), - Array.from(deps).map(prettyPrintURI), - ] as const - ), - )) diff --git a/graph/graph_descendants.ts b/graph/graph_descendants.ts index 69bb9c5..5303c13 100644 --- a/graph/graph_descendants.ts +++ b/graph/graph_descendants.ts @@ -44,7 +44,10 @@ export const graphDescendantsRaw = ( * TOP2 <- B, a, c * ``` */ -export const graphDescendants = (graph: ArrowGraph): Map> => +// deno-lint-ignore no-explicit-any +export const graphDescendants = ( + graph: ArrowGraph, +): Record => graphDescendantsRaw(graph).stream() - .map(([k, v]) => [k, v.stream().reduce(Reducer.toJSSet())] as const) - .reduce(Reducer.toJSMap()) + .map(([k, v]) => [k, [...v.stream().reduce(Reducer.toJSSet())]] as [T, T[]]) + .reduce(Reducer.toJSObject()) diff --git a/graph/graph_descendants_test.ts b/graph/graph_descendants_test.ts index d4271e9..57ae87d 100644 --- a/graph/graph_descendants_test.ts +++ b/graph/graph_descendants_test.ts @@ -15,10 +15,10 @@ Deno.test("graphDescendants() gets all valid path of directed graph", () => { const result = graphDescendants(graph) - const expected = new Map([ - ["TOP1", new Set(["A", "a", "b"])], - ["TOP2", new Set(["B", "a", "c"])], - ]) + const expected = { + TOP1: ["b", "A", "a"], + TOP2: ["a", "B", "c"], + } assertEquals(result, expected) }) diff --git a/graph/top_decl_deps.ts b/graph/top_decl_deps.ts index 1852b0f..1080aa1 100644 --- a/graph/top_decl_deps.ts +++ b/graph/top_decl_deps.ts @@ -3,7 +3,7 @@ import type { Graph } from "./graph.ts" import { VSCodeURI } from "./vscode_uri.ts" import { graphDescendants } from "./graph_descendants.ts" -export type TopDeclDeps = Map> +export type TopDeclDeps = Record /** * Flattens graph of references into top-level links. diff --git a/graph/top_decl_deps_test.ts b/graph/top_decl_deps_test.ts index 96ff872..a05404f 100644 --- a/graph/top_decl_deps_test.ts +++ b/graph/top_decl_deps_test.ts @@ -7,7 +7,6 @@ import { getAllDecls } from "./decls.ts" import { declDepsToGraph } from "./graph.ts" import { getTopDeclDeps } from "./top_decl_deps.ts" import { snapshotTest } from "./_snapshot.ts" -import { topDeclDepsSerializer } from "./_format.ts" snapshotTest( "getTopDeclDeps() converts graph into valid TopDeclDeps", @@ -20,6 +19,6 @@ snapshotTest( const topDeclDeps = getTopDeclDeps(graph) - await assertSnapshot(t, topDeclDeps, { serializer: topDeclDepsSerializer }) + await assertSnapshot(t, topDeclDeps) }, )