universal-ast-mapper 1.3.0 → 1.5.0
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 +2 -0
- package/dist/extractors/typescript.js +86 -0
- package/dist/html.js +1 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -605,6 +605,8 @@ Not part of the public API: the internal `src/` module layout and the generated
|
|
|
605
605
|
|
|
606
606
|
| Version | What changed |
|
|
607
607
|
|---------|--------------|
|
|
608
|
+
| **1.5.0** | **`.d.ts` / ambient declarations** — `declare function/const/class`, `declare module "x"`, and `declare namespace` (and plain `namespace`) are now extracted (previously a `.d.ts` yielded 0 symbols). Adds a `namespace` symbol kind; declared APIs surface as exported, nested under their module/namespace. |
|
|
609
|
+
| **1.4.0** | **Dynamic import tracking** — dynamic `import("...")` and CommonJS `require("...")` calls (anywhere in a file) are now captured as imports with an `isDynamic` flag. Relative dynamic imports resolve and draw graph edges like static ones, so lazy-loaded routes/modules show up in the dependency graph. |
|
|
608
610
|
| **1.3.0** | **TS/JS decorators** — class and method symbols now carry a `decorators` field (`@Component({...})`, `@Injectable()`, `@Get("/x")`), in skeletons and `get_call_graph`. Extends the Python decorator support (v0.8.7) to TypeScript/JavaScript — traces Angular/NestJS-style framework wiring to its class/handler. |
|
|
609
611
|
| **1.2.0** | **File-level cross-package resolution** — in a monorepo, bare imports of a workspace package (`@org/utils`, `@org/utils/sub`) now resolve to the actual source file (preferring `src/` over built `dist/`), so `resolve_imports` marks them in-project and `build_symbol_graph` draws cross-package edges. Builds on the v1.1.0 workspace discovery. |
|
|
610
612
|
| **1.1.0** | **Monorepo support** — new `analyze_workspace` MCP tool + `ast-map workspace` (alias `ws`) CLI: discovers packages from npm/yarn `workspaces`, `pnpm-workspace.yaml`, or `lerna.json`, maps internal package dependencies, and flags circular package deps. **19 MCP tools**. |
|
|
@@ -147,6 +147,38 @@ function handle(node, exported, typeIndex) {
|
|
|
147
147
|
}
|
|
148
148
|
return null;
|
|
149
149
|
}
|
|
150
|
+
case "ambient_declaration":
|
|
151
|
+
// `.d.ts` / `declare ...` — surface the declared API as exported.
|
|
152
|
+
return collect(namedChildren(node), true, typeIndex);
|
|
153
|
+
case "function_signature": {
|
|
154
|
+
const name = nameOf(node) ?? "(function)";
|
|
155
|
+
return makeSymbol({
|
|
156
|
+
name,
|
|
157
|
+
kind: "function",
|
|
158
|
+
node,
|
|
159
|
+
rawKind: node.type,
|
|
160
|
+
signature: node.text.replace(/\s+/g, " ").replace(/;\s*$/, "").trim(),
|
|
161
|
+
exported,
|
|
162
|
+
doc: leadingComment(node),
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
case "module": // declare module "name" { ... }
|
|
166
|
+
case "internal_module": { // namespace Name { ... }
|
|
167
|
+
const nameNode = node.childForFieldName("name");
|
|
168
|
+
const rawName = nameNode ? nameNode.text : "(namespace)";
|
|
169
|
+
const name = rawName.replace(/^['"`]|['"`]$/g, "");
|
|
170
|
+
const body = node.childForFieldName("body");
|
|
171
|
+
const children = body ? collect(namedChildren(body), false, typeIndex) : [];
|
|
172
|
+
return makeSymbol({
|
|
173
|
+
name,
|
|
174
|
+
kind: "namespace",
|
|
175
|
+
node,
|
|
176
|
+
rawKind: node.type,
|
|
177
|
+
exported,
|
|
178
|
+
doc: leadingComment(node),
|
|
179
|
+
children,
|
|
180
|
+
});
|
|
181
|
+
}
|
|
150
182
|
default:
|
|
151
183
|
return null;
|
|
152
184
|
}
|
|
@@ -200,6 +232,18 @@ function fromVariableDeclaration(node, exported, typeIndex) {
|
|
|
200
232
|
doc: leadingComment(node),
|
|
201
233
|
}));
|
|
202
234
|
}
|
|
235
|
+
else if (exported && !value && decl.childForFieldName("type")) {
|
|
236
|
+
// Ambient `declare const X: T` — no initializer, but part of the typed API.
|
|
237
|
+
out.push(makeSymbol({
|
|
238
|
+
name,
|
|
239
|
+
kind: "const",
|
|
240
|
+
node: decl,
|
|
241
|
+
rawKind: `${node.type}>declare`,
|
|
242
|
+
signature: decl.text.replace(/\s+/g, " ").trim().slice(0, 120),
|
|
243
|
+
exported: true,
|
|
244
|
+
doc: leadingComment(node),
|
|
245
|
+
}));
|
|
246
|
+
}
|
|
203
247
|
}
|
|
204
248
|
return out;
|
|
205
249
|
}
|
|
@@ -213,8 +257,50 @@ export function extractImportsTS(root, _source) {
|
|
|
213
257
|
else if (child.type === "export_statement")
|
|
214
258
|
parseReExportStatement(child, imports);
|
|
215
259
|
}
|
|
260
|
+
collectDynamicImports(root, imports);
|
|
216
261
|
return imports;
|
|
217
262
|
}
|
|
263
|
+
/** First string-literal argument of a call's `arguments` node, or null. */
|
|
264
|
+
function firstStringArg(args) {
|
|
265
|
+
for (let i = 0; i < args.namedChildCount; i++) {
|
|
266
|
+
const a = args.namedChild(i);
|
|
267
|
+
if (a && a.type === "string") {
|
|
268
|
+
for (let j = 0; j < a.namedChildCount; j++) {
|
|
269
|
+
const frag = a.namedChild(j);
|
|
270
|
+
if (frag && frag.type === "string_fragment")
|
|
271
|
+
return frag.text;
|
|
272
|
+
}
|
|
273
|
+
return a.text.replace(/^['"`]|['"`]$/g, "");
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Walk the whole tree for dynamic `import("...")` and CommonJS `require("...")`
|
|
280
|
+
* calls (they can appear anywhere, not just at the top level). Only string-literal
|
|
281
|
+
* specifiers are captured; computed requires are skipped.
|
|
282
|
+
*/
|
|
283
|
+
function collectDynamicImports(node, out) {
|
|
284
|
+
if (node.type === "call_expression") {
|
|
285
|
+
const fn = node.childForFieldName("function");
|
|
286
|
+
const args = node.childForFieldName("arguments");
|
|
287
|
+
if (fn && args) {
|
|
288
|
+
const isImport = fn.type === "import";
|
|
289
|
+
const isRequire = fn.type === "identifier" && fn.text === "require";
|
|
290
|
+
if (isImport || isRequire) {
|
|
291
|
+
const spec = firstStringArg(args);
|
|
292
|
+
if (spec !== null) {
|
|
293
|
+
out.push({ symbol: "*", from: spec, isNamespaceImport: true, isDynamic: true });
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
299
|
+
const c = node.namedChild(i);
|
|
300
|
+
if (c)
|
|
301
|
+
collectDynamicImports(c, out);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
218
304
|
function parseReExportStatement(node, out) {
|
|
219
305
|
const source = extractModulePath(node.text);
|
|
220
306
|
if (!source)
|
package/dist/html.js
CHANGED
package/package.json
CHANGED