universal-ast-mapper 0.8.0 → 0.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/dist/callgraph.js +24 -2
- package/dist/crosslang.js +79 -2
- package/dist/graph.js +4 -1
- package/dist/resolver.js +2 -2
- package/dist/skeleton.js +8 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -480,6 +480,7 @@ src/
|
|
|
480
480
|
|
|
481
481
|
| Version | What changed |
|
|
482
482
|
|---------|--------------|
|
|
483
|
+
| **0.8.1** | **Cross-file graph wiring for Kotlin & C/C++** — Kotlin FQCN/package index + C/C++ `#include` resolution (with header↔impl pairing) wired into `build_symbol_graph`, `resolve_imports`, and `get_call_graph`. Fixes a parse-cache rel-path leak (stale `.file` poisoned the cross-lang index → doubled paths) and Kotlin call-graph extraction (`function_declaration` name + field-less `call_expression`). |
|
|
483
484
|
| **0.8.0** | **4 new languages: C · C++ · Kotlin · Swift** — symbol extraction + imports parsing. C++ tracks access_specifier through class bodies. Kotlin handles `package`/`object`/`data class`. Swift handles `class`/`struct`/`enum` (all under `class_declaration`) and `protocol_declaration`. Ruby grammar in tree-sitter-wasms@0.1.13 is unstable — skipped. |
|
|
484
485
|
| **0.7.0** | Go full resolution (reads `go.mod`, resolves package-as-directory) · C# reverse `calledBy` via call-site scanning · `csharpTypes` index lets `using` directives resolve to specific types · 4-suite test harness (smoke + graph-smoke + resolver-smoke + callgraph-smoke) |
|
|
485
486
|
| **0.6.0** | **3 new languages: Rust · Java · C#** (extractors + import parsing) · cross-language resolver in `crosslang.ts` (Java FQCN index, C# namespace index, Rust `crate::` module walk) · symbol-graph `imports` edges + `resolveFileImports` enrichment + `get_call_graph` callee resolution rewired through it · Java `package` and C# `namespace` captured as directives |
|
package/dist/callgraph.js
CHANGED
|
@@ -6,7 +6,7 @@ import { resolveOptions, loadProjectConfig } from "./config.js";
|
|
|
6
6
|
import { detectLanguage } from "./registry.js";
|
|
7
7
|
import { resolveImportPath, getOrBuildCrossLangIndex } from "./resolver.js";
|
|
8
8
|
import { resolveCrossLangTarget } from "./crosslang.js";
|
|
9
|
-
const CROSS_LANG = new Set(["java", "csharp", "rust", "go"]);
|
|
9
|
+
const CROSS_LANG = new Set(["java", "csharp", "rust", "go", "kotlin", "c", "cpp"]);
|
|
10
10
|
function pushCall(out, callee, anchor) {
|
|
11
11
|
if (callee && anchor)
|
|
12
12
|
out.push({ callee, line: anchor.startPosition.row + 1 });
|
|
@@ -54,6 +54,20 @@ function collectCalls(node, out) {
|
|
|
54
54
|
}
|
|
55
55
|
pushCall(out, callee, fn);
|
|
56
56
|
}
|
|
57
|
+
else {
|
|
58
|
+
// Kotlin: call_expression has no `function` field — the callee is the
|
|
59
|
+
// first named child (a simple_identifier for `Foo(...)` / a bare call,
|
|
60
|
+
// or a navigation_expression for `obj.method(...)`).
|
|
61
|
+
const callee0 = node.namedChild(0);
|
|
62
|
+
if (callee0) {
|
|
63
|
+
if (callee0.type === "simple_identifier" || callee0.type === "identifier") {
|
|
64
|
+
pushCall(out, callee0.text, callee0);
|
|
65
|
+
}
|
|
66
|
+
else if (callee0.type === "navigation_expression") {
|
|
67
|
+
pushCall(out, callee0.text.replace(/\s+/g, ""), callee0);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
// ── Java method invocation
|
|
59
73
|
else if (t === "method_invocation") {
|
|
@@ -110,8 +124,16 @@ const FUNCTION_NODE_TYPES = new Set([
|
|
|
110
124
|
function findFunctionNode(root, name) {
|
|
111
125
|
function walk(node) {
|
|
112
126
|
if (FUNCTION_NODE_TYPES.has(node.type)) {
|
|
113
|
-
|
|
127
|
+
const named = node.childForFieldName("name");
|
|
128
|
+
if (named?.text === name)
|
|
114
129
|
return node;
|
|
130
|
+
// Kotlin: function_declaration exposes its name as a simple_identifier
|
|
131
|
+
// child, not via a `name` field.
|
|
132
|
+
if (!named && node.type === "function_declaration") {
|
|
133
|
+
const id = node.namedChild(0);
|
|
134
|
+
if (id?.type === "simple_identifier" && id.text === name)
|
|
135
|
+
return node;
|
|
136
|
+
}
|
|
115
137
|
}
|
|
116
138
|
// const foo = () => ... | const foo = function() ...
|
|
117
139
|
if (node.type === "variable_declarator") {
|
package/dist/crosslang.js
CHANGED
|
@@ -24,6 +24,8 @@ export function buildCrossLangIndex(skeletons) {
|
|
|
24
24
|
javaPackages: new Map(),
|
|
25
25
|
csharpNamespaces: new Map(),
|
|
26
26
|
csharpTypes: new Map(),
|
|
27
|
+
kotlinFqcn: new Map(),
|
|
28
|
+
kotlinPackages: new Map(),
|
|
27
29
|
};
|
|
28
30
|
for (const skel of skeletons) {
|
|
29
31
|
if (skel.language === "java") {
|
|
@@ -55,6 +57,17 @@ export function buildCrossLangIndex(skeletons) {
|
|
|
55
57
|
}
|
|
56
58
|
}
|
|
57
59
|
}
|
|
60
|
+
else if (skel.language === "kotlin") {
|
|
61
|
+
const pkg = getDirectiveValue(skel, "package:");
|
|
62
|
+
if (!pkg)
|
|
63
|
+
continue;
|
|
64
|
+
const pkgFiles = index.kotlinPackages.get(pkg) ?? [];
|
|
65
|
+
pkgFiles.push(skel.file);
|
|
66
|
+
index.kotlinPackages.set(pkg, pkgFiles);
|
|
67
|
+
for (const sym of topTypeSymbols(skel.symbols)) {
|
|
68
|
+
index.kotlinFqcn.set(`${pkg}.${sym.name}`, skel.file);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
58
71
|
}
|
|
59
72
|
return index;
|
|
60
73
|
}
|
|
@@ -262,6 +275,47 @@ export function resolveGoImport(importFrom, fromAbs, projectRoot) {
|
|
|
262
275
|
export function clearGoModuleCache() {
|
|
263
276
|
goModuleCache.clear();
|
|
264
277
|
}
|
|
278
|
+
/* ─── C / C++ #include resolution ─────────────────────────────────────────── */
|
|
279
|
+
const HEADER_EXTS = [".h", ".hpp", ".hxx", ".hh"];
|
|
280
|
+
const IMPL_EXTS = [".c", ".cpp", ".cc", ".cxx"];
|
|
281
|
+
/**
|
|
282
|
+
* Resolve a C/C++ `#include "foo.h"` to in-project files.
|
|
283
|
+
* Convention: also pair foo.h with foo.c/.cpp in the same directory so the
|
|
284
|
+
* graph captures the header → impl relationship.
|
|
285
|
+
* `#include <foo.h>` (system headers) returns null (external).
|
|
286
|
+
*/
|
|
287
|
+
export function resolveCInclude(importFrom, fromAbs, projectRoot) {
|
|
288
|
+
// System headers like stdio.h, vector, etc. — leave to external.
|
|
289
|
+
const isSystemHeader = !importFrom.includes("/") && !importFrom.includes(".") ||
|
|
290
|
+
/^(stdio|stdlib|string|vector|memory|cstdint|cstdlib|cstring|iostream)/.test(importFrom);
|
|
291
|
+
// We only check the actual filesystem; if a system header happens to exist
|
|
292
|
+
// locally we still link it, otherwise it falls through to null.
|
|
293
|
+
const fromDir = path.dirname(fromAbs);
|
|
294
|
+
const headerAbs = path.resolve(fromDir, importFrom);
|
|
295
|
+
const out = [];
|
|
296
|
+
if (existsFile(headerAbs)) {
|
|
297
|
+
const rel = path.relative(projectRoot, headerAbs).split(path.sep).join("/");
|
|
298
|
+
// Reject paths that escape the project root.
|
|
299
|
+
if (!rel.startsWith(".."))
|
|
300
|
+
out.push(rel);
|
|
301
|
+
// Pair foo.h with foo.{c,cpp,cc,cxx} in the same directory.
|
|
302
|
+
const ext = path.extname(headerAbs).toLowerCase();
|
|
303
|
+
if (HEADER_EXTS.includes(ext)) {
|
|
304
|
+
const base = headerAbs.slice(0, -ext.length);
|
|
305
|
+
for (const implExt of IMPL_EXTS) {
|
|
306
|
+
const implAbs = base + implExt;
|
|
307
|
+
if (existsFile(implAbs)) {
|
|
308
|
+
const implRel = path.relative(projectRoot, implAbs).split(path.sep).join("/");
|
|
309
|
+
if (!implRel.startsWith(".."))
|
|
310
|
+
out.push(implRel);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (isSystemHeader && out.length === 0)
|
|
316
|
+
return null;
|
|
317
|
+
return out.length > 0 ? out : null;
|
|
318
|
+
}
|
|
265
319
|
/**
|
|
266
320
|
* Resolve an ImportRef in a non-relative-path language to a graph target.
|
|
267
321
|
* Returns null for unresolvable / external imports.
|
|
@@ -301,8 +355,31 @@ export function resolveCrossLangTarget(imp, skel, fromAbs, projectRoot, index) {
|
|
|
301
355
|
const files = resolveGoImport(imp.from, fromAbs, projectRoot);
|
|
302
356
|
if (!files || files.length === 0)
|
|
303
357
|
return null;
|
|
304
|
-
|
|
305
|
-
|
|
358
|
+
const filtered = files.filter((f) => f !== skel.file);
|
|
359
|
+
if (filtered.length === 0)
|
|
360
|
+
return null;
|
|
361
|
+
return { kind: "file", files: filtered };
|
|
362
|
+
}
|
|
363
|
+
if (skel.language === "kotlin") {
|
|
364
|
+
if (imp.symbol === "*") {
|
|
365
|
+
const files = index.kotlinPackages.get(imp.from);
|
|
366
|
+
if (files && files.length > 0) {
|
|
367
|
+
const filtered = files.filter((f) => f !== skel.file);
|
|
368
|
+
if (filtered.length > 0)
|
|
369
|
+
return { kind: "file", files: filtered };
|
|
370
|
+
}
|
|
371
|
+
return null;
|
|
372
|
+
}
|
|
373
|
+
const targetFile = index.kotlinFqcn.get(imp.from);
|
|
374
|
+
if (targetFile && targetFile !== skel.file) {
|
|
375
|
+
return { kind: "symbol", file: targetFile, symbol: imp.symbol };
|
|
376
|
+
}
|
|
377
|
+
return null;
|
|
378
|
+
}
|
|
379
|
+
if (skel.language === "c" || skel.language === "cpp") {
|
|
380
|
+
const files = resolveCInclude(imp.from, fromAbs, projectRoot);
|
|
381
|
+
if (!files || files.length === 0)
|
|
382
|
+
return null;
|
|
306
383
|
const filtered = files.filter((f) => f !== skel.file);
|
|
307
384
|
if (filtered.length === 0)
|
|
308
385
|
return null;
|
package/dist/graph.js
CHANGED
|
@@ -139,7 +139,10 @@ export function buildSymbolGraph(skeletons, root) {
|
|
|
139
139
|
else if (skel.language === "java" ||
|
|
140
140
|
skel.language === "csharp" ||
|
|
141
141
|
skel.language === "rust" ||
|
|
142
|
-
skel.language === "go"
|
|
142
|
+
skel.language === "go" ||
|
|
143
|
+
skel.language === "kotlin" ||
|
|
144
|
+
skel.language === "c" ||
|
|
145
|
+
skel.language === "cpp") {
|
|
143
146
|
wireCrossLangImport(skel, imp, fromFileAbs, root, crossIndex, exportedSymbolMap, edges);
|
|
144
147
|
}
|
|
145
148
|
}
|
package/dist/resolver.js
CHANGED
|
@@ -81,7 +81,7 @@ export async function getOrBuildCrossLangIndex(root) {
|
|
|
81
81
|
const ext = path.extname(abs).toLowerCase();
|
|
82
82
|
// Only Java/C# contribute to the index (Rust resolves via direct
|
|
83
83
|
// module-path walk against the filesystem, no index needed).
|
|
84
|
-
if (ext !== ".java" && ext !== ".cs")
|
|
84
|
+
if (ext !== ".java" && ext !== ".cs" && ext !== ".kt" && ext !== ".kts")
|
|
85
85
|
continue;
|
|
86
86
|
const rel = path.relative(key, abs).split(path.sep).join("/");
|
|
87
87
|
try {
|
|
@@ -168,7 +168,7 @@ function assembleResolved(imp, resolvedAbs, resolvedRel, isExternal, enrichment)
|
|
|
168
168
|
return out;
|
|
169
169
|
}
|
|
170
170
|
/* ─── Public entry point ──────────────────────────────────────────────────── */
|
|
171
|
-
const CROSS_LANG = new Set(["java", "csharp", "rust", "go"]);
|
|
171
|
+
const CROSS_LANG = new Set(["java", "csharp", "rust", "go", "kotlin", "c", "cpp"]);
|
|
172
172
|
export async function resolveFileImports(skel, absPath, root) {
|
|
173
173
|
if (!skel.imports || skel.imports.length === 0)
|
|
174
174
|
return [];
|
package/dist/skeleton.js
CHANGED
|
@@ -48,10 +48,15 @@ export async function buildSkeleton(absPath, relPath, opts) {
|
|
|
48
48
|
if (stat.size > opts.maxFileBytes) {
|
|
49
49
|
throw new Error(`File is ${stat.size} bytes, exceeds maxFileBytes (${opts.maxFileBytes}). Increase the limit to parse it.`);
|
|
50
50
|
}
|
|
51
|
-
// Return cached result if file hasn't changed
|
|
51
|
+
// Return cached result if file hasn't changed. The cached SkeletonFile's
|
|
52
|
+
// `.file` is whatever relPath the first caller used; the same absolute file
|
|
53
|
+
// can be requested under a different root (different relPath), so override
|
|
54
|
+
// `.file` per call to avoid leaking a stale rel path into callers/indexes.
|
|
52
55
|
const cached = getCached(absPath, opts.detail);
|
|
53
|
-
if (cached)
|
|
54
|
-
|
|
56
|
+
if (cached) {
|
|
57
|
+
const wantFile = relPath.split(path.sep).join("/");
|
|
58
|
+
return cached.file === wantFile ? cached : { ...cached, file: wantFile };
|
|
59
|
+
}
|
|
55
60
|
const source = fs.readFileSync(absPath, "utf8");
|
|
56
61
|
const root = await parseSource(entry.grammar, source);
|
|
57
62
|
let symbols = entry.extract(root, source);
|
package/package.json
CHANGED