@dimassetoid/septum-mcp 0.0.0-stage → 0.3.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/LICENSE +21 -0
- package/README.md +142 -2
- package/bin/septum.ts +4 -0
- package/package.json +70 -4
- package/scripts/postinstall.ts +25 -0
- package/src/cli/commands/check.ts +133 -0
- package/src/cli/commands/hook.ts +205 -0
- package/src/cli/commands/init.ts +570 -0
- package/src/cli/commands/serve.ts +5 -0
- package/src/cli/commands/sync.ts +39 -0
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +124 -0
- package/src/cli/scaffold/harness-config.ts +661 -0
- package/src/cli/templates/hooks.ts +110 -0
- package/src/cli/templates/rules.ts +35 -0
- package/src/cli/templates/skill.ts +55 -0
- package/src/cli/ui/prompts.ts +122 -0
- package/src/core/boundary/evaluator.ts +426 -0
- package/src/core/boundary/staged-auditor.ts +120 -0
- package/src/core/config/domain-ownership.ts +45 -0
- package/src/core/config/loader.ts +174 -0
- package/src/core/config/schema.ts +59 -0
- package/src/core/database/client.ts +60 -0
- package/src/core/database/repositories/dependency.repository.ts +733 -0
- package/src/core/database/repositories/domain.repository.ts +373 -0
- package/src/core/database/repositories/file.repository.ts +117 -0
- package/src/core/database/repositories/meta.repository.ts +33 -0
- package/src/core/database/repositories/symbol.repository.ts +647 -0
- package/src/core/database/repository.ts +358 -0
- package/src/core/database/schema.ts +123 -0
- package/src/core/discovery/navigation.ts +105 -0
- package/src/core/discovery/topology-detector.ts +863 -0
- package/src/core/ingestion/hasher.ts +5 -0
- package/src/core/ingestion/pipeline.ts +590 -0
- package/src/core/parser/behavioral-analyzer.ts +123 -0
- package/src/core/parser/boundary-tracker.ts +458 -0
- package/src/core/parser/extractors/base.ts +71 -0
- package/src/core/parser/extractors/blade.ts +159 -0
- package/src/core/parser/extractors/csharp.ts +248 -0
- package/src/core/parser/extractors/django-semantic.ts +655 -0
- package/src/core/parser/extractors/elysia-semantic.ts +517 -0
- package/src/core/parser/extractors/express-semantic.ts +429 -0
- package/src/core/parser/extractors/fastapi-semantic.ts +702 -0
- package/src/core/parser/extractors/fastify-semantic.ts +759 -0
- package/src/core/parser/extractors/flask-semantic.ts +482 -0
- package/src/core/parser/extractors/frontend.ts +149 -0
- package/src/core/parser/extractors/go-semantic.ts +670 -0
- package/src/core/parser/extractors/go.ts +491 -0
- package/src/core/parser/extractors/hono-semantic.ts +546 -0
- package/src/core/parser/extractors/java.ts +227 -0
- package/src/core/parser/extractors/laravel-semantic.ts +1150 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +367 -0
- package/src/core/parser/extractors/nestjs-semantic.ts +527 -0
- package/src/core/parser/extractors/php.ts +585 -0
- package/src/core/parser/extractors/python.ts +503 -0
- package/src/core/parser/extractors/registry.ts +99 -0
- package/src/core/parser/extractors/ruby.ts +237 -0
- package/src/core/parser/extractors/rust.ts +304 -0
- package/src/core/parser/extractors/semantic-extractor.interface.ts +24 -0
- package/src/core/parser/extractors/symfony-semantic.ts +321 -0
- package/src/core/parser/extractors/typescript.ts +839 -0
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +87 -0
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +239 -0
- package/src/core/parser/schema/schema-provider-registry.ts +41 -0
- package/src/core/parser/schema/schema-provider.interface.ts +34 -0
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/tree-sitter.ts +63 -0
- package/src/core/parser/wasm-assets.ts +25 -0
- package/src/core/parser/wasm-loader.ts +274 -0
- package/src/core/resolver/call-graph-tracer.ts +1033 -0
- package/src/core/resolver/import-resolver.ts +365 -0
- package/src/core/resolver/interpretation-inputs.ts +7 -0
- package/src/core/resolver/languages/go.ts +103 -0
- package/src/core/resolver/languages/managed.ts +200 -0
- package/src/core/resolver/languages/python.ts +115 -0
- package/src/core/resolver/languages/ruby.ts +40 -0
- package/src/core/resolver/languages/rust.ts +127 -0
- package/src/core/resolver/languages/shared.ts +71 -0
- package/src/core/resolver/module-resolver.ts +486 -0
- package/src/core/resolver/path-resolver.ts +200 -0
- package/src/core/resolver/slice-catalog.ts +79 -0
- package/src/core/resolver/slice-format.ts +9 -0
- package/src/core/resolver/symbol-impact.ts +381 -0
- package/src/core/resolver/symbol-locator.ts +276 -0
- package/src/core/resolver/symbol-reference.ts +53 -0
- package/src/core/resolver/vertical-slice-tracer.ts +344 -0
- package/src/core/resources/ignore.ts +144 -0
- package/src/core/resources/limits.ts +14 -0
- package/src/core/resources/source-files.ts +185 -0
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +74 -0
- package/src/core/retrieval/context-page.ts +109 -0
- package/src/core/retrieval/context.ts +320 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +262 -0
- package/src/core/telemetry/telemetry.ts +142 -0
- package/src/index.ts +18 -0
- package/src/mcp/schemas.ts +746 -0
- package/src/mcp/server.ts +600 -0
- package/src/mcp/tools/boundary.ts +17 -0
- package/src/mcp/tools/check-boundary.ts +382 -0
- package/src/mcp/tools/get-domain-catalog.ts +39 -0
- package/src/mcp/tools/get-symbol-impact.ts +104 -0
- package/src/mcp/tools/get-symbol.ts +399 -0
- package/src/mcp/tools/locate-symbol.ts +236 -0
- package/src/mcp/tools/map.ts +26 -0
- package/src/mcp/tools/register-domain.ts +113 -0
- package/src/mcp/tools/slice.ts +16 -0
- package/src/mcp/tools/symbol.ts +95 -0
- package/src/mcp/tools/trace-vertical-slice.ts +106 -0
- package/src/mcp/workspace-manager.ts +170 -0
- package/src/mcp/workspace-watcher.ts +202 -0
- package/src/types/index.ts +438 -0
- package/src/types/wasm.d.ts +4 -0
- package/src/utils/version-check.ts +209 -0
- package/src/version.ts +1 -0
|
@@ -0,0 +1,839 @@
|
|
|
1
|
+
import { getLanguageCapability } from "../language-capabilities.ts";
|
|
2
|
+
import type Parser from "web-tree-sitter";
|
|
3
|
+
import type {
|
|
4
|
+
ExtractedDependency,
|
|
5
|
+
ExtractedSymbol,
|
|
6
|
+
ParsedFileAST,
|
|
7
|
+
SymbolKind,
|
|
8
|
+
Visibility,
|
|
9
|
+
} from "../../../types/index.ts";
|
|
10
|
+
import {
|
|
11
|
+
blankCommentsAndStrings,
|
|
12
|
+
calculateControlFlowNesting,
|
|
13
|
+
findBraceBlockEnd,
|
|
14
|
+
} from "../boundary-tracker.ts";
|
|
15
|
+
import { calculateAstControlFlowNesting, getNodeHeader, parseSourceWithTreeSitter } from "../wasm-loader.ts";
|
|
16
|
+
import type { CodeExtractor } from "./base.ts";
|
|
17
|
+
|
|
18
|
+
const TS_CONTROL_FLOW_NODES = new Set([
|
|
19
|
+
"if_statement",
|
|
20
|
+
"for_statement",
|
|
21
|
+
"for_in_statement",
|
|
22
|
+
"while_statement",
|
|
23
|
+
"do_statement",
|
|
24
|
+
"switch_statement",
|
|
25
|
+
"try_statement",
|
|
26
|
+
"catch_clause",
|
|
27
|
+
"ternary_expression",
|
|
28
|
+
]);
|
|
29
|
+
|
|
30
|
+
const TS_FUNCTION_BOUNDARY_NODES = new Set([
|
|
31
|
+
"function_declaration",
|
|
32
|
+
"generator_function_declaration",
|
|
33
|
+
"function_expression",
|
|
34
|
+
"arrow_function",
|
|
35
|
+
"method_definition",
|
|
36
|
+
]);
|
|
37
|
+
|
|
38
|
+
export class TypeScriptExtractor implements CodeExtractor {
|
|
39
|
+
public canHandle(filePath: string): boolean {
|
|
40
|
+
return getLanguageCapability(filePath)?.extractor === "typescript";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async extract(filePath: string, content: string): Promise<ParsedFileAST> {
|
|
44
|
+
const langKey = filePath;
|
|
45
|
+
const treeSitterResult = await parseSourceWithTreeSitter(langKey, content, (rootNode) =>
|
|
46
|
+
this.extractFromAst(rootNode, content),
|
|
47
|
+
() => this.extractFallback(content)
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
if (treeSitterResult) {
|
|
51
|
+
return treeSitterResult;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return { ...this.extractFallback(content), status: "degraded" };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
private extractFallback(content: string): ParsedFileAST {
|
|
58
|
+
const symbols: ExtractedSymbol[] = [];
|
|
59
|
+
const dependencies: ExtractedDependency[] = [];
|
|
60
|
+
|
|
61
|
+
const rawLines = content.split("\n");
|
|
62
|
+
const cleanContent = blankCommentsAndStrings(content);
|
|
63
|
+
const cleanLines = cleanContent.split("\n");
|
|
64
|
+
|
|
65
|
+
const importRegex =
|
|
66
|
+
/^\s*(?:(?:import|export)\s+(?:type\s+)?(?:([\w*\s{},]+)\s+from\s+)?['"]([^'"]+)['"]|(?:const|let|var)\s+([\w\s{},:$]+)\s*=\s*require\s*\(\s*['"]([^'"]+)['"]\s*\)|require\s*\(\s*['"]([^'"]+)['"]\s*\))/;
|
|
67
|
+
|
|
68
|
+
for (let i = 0; i < rawLines.length; i++) {
|
|
69
|
+
if (!cleanLines[i]?.trim()) continue;
|
|
70
|
+
const line = rawLines[i];
|
|
71
|
+
const match = importRegex.exec(line);
|
|
72
|
+
if (match) {
|
|
73
|
+
const target = match[2] || match[4] || match[5];
|
|
74
|
+
const clause = match[1] || match[3] || "";
|
|
75
|
+
if (target) {
|
|
76
|
+
const importedSymbols = clause
|
|
77
|
+
.replace(/[{}*]/g, " ")
|
|
78
|
+
.split(/,|\bas\b/)
|
|
79
|
+
.map((s) => s.trim())
|
|
80
|
+
.filter((s) => /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(s) && s !== "type");
|
|
81
|
+
const isExternal = !target.startsWith(".") && !target.startsWith("/");
|
|
82
|
+
dependencies.push({
|
|
83
|
+
target,
|
|
84
|
+
statement: line.trim(),
|
|
85
|
+
line_number: i + 1,
|
|
86
|
+
is_external: isExternal,
|
|
87
|
+
...(importedSymbols.length > 0 ? { imported_symbols: Array.from(new Set(importedSymbols)) } : {}),
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// 2. Extract Symbols using cleanLines + brace depth tracking
|
|
94
|
+
let currentClass: string | null = null;
|
|
95
|
+
let currentClassDepth = 0;
|
|
96
|
+
let braceDepth = 0;
|
|
97
|
+
|
|
98
|
+
for (let i = 0; i < cleanLines.length; i++) {
|
|
99
|
+
const cleanTrimmed = cleanLines[i].trim();
|
|
100
|
+
const rawTrimmed = rawLines[i].trim();
|
|
101
|
+
const lineNum = i + 1;
|
|
102
|
+
|
|
103
|
+
if (currentClass && braceDepth < currentClassDepth) {
|
|
104
|
+
currentClass = null;
|
|
105
|
+
currentClassDepth = 0;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (cleanTrimmed && braceDepth === 0) {
|
|
109
|
+
const classMatch =
|
|
110
|
+
/^(?:export\s+)?(?:default\s+)?(?:abstract\s+)?\b(class|interface)\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(
|
|
111
|
+
cleanTrimmed
|
|
112
|
+
);
|
|
113
|
+
if (classMatch) {
|
|
114
|
+
currentClass = classMatch[2];
|
|
115
|
+
currentClassDepth = braceDepth + 1;
|
|
116
|
+
const endLine = findBraceBlockEnd(cleanLines, i);
|
|
117
|
+
symbols.push({
|
|
118
|
+
name: classMatch[2],
|
|
119
|
+
kind: classMatch[1] as "class" | "interface",
|
|
120
|
+
signature: rawTrimmed.replace(/\{$/, "").trim(),
|
|
121
|
+
visibility: "public",
|
|
122
|
+
line_start: lineNum,
|
|
123
|
+
line_end: endLine,
|
|
124
|
+
line_count: Math.max(1, endLine - lineNum + 1),
|
|
125
|
+
});
|
|
126
|
+
} else {
|
|
127
|
+
const typeMatch = /^(?:export\s+)?\btype\s+([A-Za-z_$][A-Za-z0-9_$]*)\b\s*=/.exec(cleanTrimmed);
|
|
128
|
+
if (typeMatch) {
|
|
129
|
+
const endLine = cleanTrimmed.endsWith(";") ? lineNum : findBraceBlockEnd(cleanLines, i);
|
|
130
|
+
symbols.push({
|
|
131
|
+
name: typeMatch[1],
|
|
132
|
+
kind: "type",
|
|
133
|
+
signature: rawTrimmed.replace(/;$/, "").trim(),
|
|
134
|
+
visibility: "public",
|
|
135
|
+
line_start: lineNum,
|
|
136
|
+
line_end: endLine,
|
|
137
|
+
line_count: Math.max(1, endLine - lineNum + 1),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const enumMatch = /^(?:export\s+)?(?:const\s+)?\benum\s+([A-Za-z_$][A-Za-z0-9_$]*)\b/.exec(cleanTrimmed);
|
|
142
|
+
if (enumMatch) {
|
|
143
|
+
const endLine = findBraceBlockEnd(cleanLines, i);
|
|
144
|
+
symbols.push({
|
|
145
|
+
name: enumMatch[1],
|
|
146
|
+
kind: "enum",
|
|
147
|
+
signature: rawTrimmed.replace(/\{$/, "").trim(),
|
|
148
|
+
visibility: "public",
|
|
149
|
+
line_start: lineNum,
|
|
150
|
+
line_end: endLine,
|
|
151
|
+
line_count: Math.max(1, endLine - lineNum + 1),
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const fnMatch =
|
|
156
|
+
/^(?:export\s+)?(?:default\s+)?(?:async\s+)?\bfunction\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
|
|
157
|
+
cleanTrimmed
|
|
158
|
+
);
|
|
159
|
+
if (fnMatch) {
|
|
160
|
+
const name = fnMatch[1];
|
|
161
|
+
const params = fnMatch[2];
|
|
162
|
+
const retType = fnMatch[3] ? `: ${fnMatch[3].trim()}` : "";
|
|
163
|
+
const endLine = findBraceBlockEnd(cleanLines, i);
|
|
164
|
+
const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
|
|
165
|
+
symbols.push({
|
|
166
|
+
name,
|
|
167
|
+
kind: "function",
|
|
168
|
+
signature: `${name}(${params})${retType}`,
|
|
169
|
+
visibility: "public",
|
|
170
|
+
line_start: lineNum,
|
|
171
|
+
line_end: endLine,
|
|
172
|
+
line_count: Math.max(1, endLine - lineNum + 1),
|
|
173
|
+
nesting_depth: nestingDepth,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const varMatch =
|
|
178
|
+
/^(?:export\s+)?\b(const|let|var)\s+([A-Za-z_$][A-Za-z0-9_$]*)\s*(?::\s*([^=;]+))?\s*=\s*(.*)$/.exec(
|
|
179
|
+
cleanTrimmed
|
|
180
|
+
);
|
|
181
|
+
if (varMatch) {
|
|
182
|
+
const declKind = varMatch[1];
|
|
183
|
+
const varName = varMatch[2];
|
|
184
|
+
const typeStr = varMatch[3] ? `: ${varMatch[3].trim()}` : "";
|
|
185
|
+
const rhs = varMatch[4].trim();
|
|
186
|
+
const isArrowOrFn = /^(?:async\s+)?(?:\([^)]*\)|[A-Za-z_$][A-Za-z0-9_$]*)\s*=>|^function\b/.test(rhs);
|
|
187
|
+
symbols.push({
|
|
188
|
+
name: varName,
|
|
189
|
+
kind: isArrowOrFn ? "function" : declKind === "const" ? "constant" : "variable",
|
|
190
|
+
signature: `${declKind} ${varName}${typeStr}`,
|
|
191
|
+
visibility: cleanTrimmed.startsWith("export ") ? "public" : "private",
|
|
192
|
+
line_start: lineNum,
|
|
193
|
+
line_end: lineNum,
|
|
194
|
+
line_count: 1,
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
} else if (cleanTrimmed && currentClass && braceDepth === currentClassDepth) {
|
|
199
|
+
const methodMatch =
|
|
200
|
+
/^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?(?:async\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*\(([^)]*)\)(?:\s*:\s*([^;{]+))?/.exec(
|
|
201
|
+
cleanTrimmed
|
|
202
|
+
);
|
|
203
|
+
if (
|
|
204
|
+
methodMatch &&
|
|
205
|
+
!["if", "for", "while", "switch", "catch", "function", "return"].includes(methodMatch[2])
|
|
206
|
+
) {
|
|
207
|
+
const vis = (methodMatch[1] as Visibility) || "public";
|
|
208
|
+
const name = methodMatch[2];
|
|
209
|
+
const params = methodMatch[3];
|
|
210
|
+
const retType = methodMatch[4] ? `: ${methodMatch[4].trim()}` : "";
|
|
211
|
+
const endLine = findBraceBlockEnd(cleanLines, i);
|
|
212
|
+
const nestingDepth = calculateControlFlowNesting(rawLines, i, endLine - 1);
|
|
213
|
+
symbols.push({
|
|
214
|
+
name: `${currentClass}::${name}`,
|
|
215
|
+
kind: "method",
|
|
216
|
+
signature: `${vis} ${name}(${params})${retType}`,
|
|
217
|
+
visibility: vis,
|
|
218
|
+
line_start: lineNum,
|
|
219
|
+
line_end: endLine,
|
|
220
|
+
line_count: Math.max(1, endLine - lineNum + 1),
|
|
221
|
+
nesting_depth: nestingDepth,
|
|
222
|
+
});
|
|
223
|
+
} else {
|
|
224
|
+
const propMatch =
|
|
225
|
+
/^(?:(public|protected|private)\s+)?(?:static\s+)?(?:readonly\s+)?\b([A-Za-z_$][A-Za-z0-9_$]*)\s*(?:\?|\!)?\s*(?::\s*([^;={]+))?(?:\s*=[^;]+)?;\s*$/.exec(
|
|
226
|
+
cleanTrimmed
|
|
227
|
+
);
|
|
228
|
+
if (
|
|
229
|
+
propMatch &&
|
|
230
|
+
!["return", "const", "let", "var", "throw", "import", "export", "continue", "break"].includes(
|
|
231
|
+
propMatch[2]
|
|
232
|
+
)
|
|
233
|
+
) {
|
|
234
|
+
const vis = (propMatch[1] as Visibility) || "public";
|
|
235
|
+
const propName = propMatch[2];
|
|
236
|
+
const typeStr = propMatch[3] ? `: ${propMatch[3].trim()}` : "";
|
|
237
|
+
symbols.push({
|
|
238
|
+
name: `${currentClass}::${propName}`,
|
|
239
|
+
kind: "property",
|
|
240
|
+
signature: `${vis} ${propName}${typeStr}`,
|
|
241
|
+
visibility: vis,
|
|
242
|
+
line_start: lineNum,
|
|
243
|
+
line_end: lineNum,
|
|
244
|
+
line_count: 1,
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
for (const ch of cleanLines[i]) {
|
|
251
|
+
if (ch === "{") braceDepth++;
|
|
252
|
+
else if (ch === "}") braceDepth = Math.max(0, braceDepth - 1);
|
|
253
|
+
}
|
|
254
|
+
if (currentClass && braceDepth < currentClassDepth) {
|
|
255
|
+
currentClass = null;
|
|
256
|
+
currentClassDepth = 0;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
return { symbols, dependencies };
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
private extractFromAst(rootNode: Parser.SyntaxNode, content: string): ParsedFileAST {
|
|
264
|
+
const symbols: ExtractedSymbol[] = [];
|
|
265
|
+
const dependencies: ExtractedDependency[] = [];
|
|
266
|
+
const lines = content.split("\n");
|
|
267
|
+
|
|
268
|
+
const stripQuotes = (raw: string): string => raw.replace(/^['"`]|['"`]$/g, "");
|
|
269
|
+
|
|
270
|
+
const walkDependencies = (node: Parser.SyntaxNode): void => {
|
|
271
|
+
if (node.type === "import_statement") {
|
|
272
|
+
const sourceNode =
|
|
273
|
+
node.childForFieldName("source") ??
|
|
274
|
+
node.namedChildren.find((c) => c.type === "string");
|
|
275
|
+
if (sourceNode) {
|
|
276
|
+
const target = stripQuotes(sourceNode.text.trim());
|
|
277
|
+
if (target) {
|
|
278
|
+
const importedSymbols = this.extractImportedSymbols(node);
|
|
279
|
+
const isExternal = !target.startsWith(".") && !target.startsWith("/");
|
|
280
|
+
dependencies.push({
|
|
281
|
+
target,
|
|
282
|
+
statement: (lines[node.startPosition.row] ?? node.text).trim(),
|
|
283
|
+
line_number: node.startPosition.row + 1,
|
|
284
|
+
is_external: isExternal,
|
|
285
|
+
...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
if (node.type === "export_statement") {
|
|
293
|
+
const sourceNode =
|
|
294
|
+
node.childForFieldName("source") ??
|
|
295
|
+
node.namedChildren.find((c) => c.type === "string");
|
|
296
|
+
if (sourceNode) {
|
|
297
|
+
const target = stripQuotes(sourceNode.text.trim());
|
|
298
|
+
if (target) {
|
|
299
|
+
const importedSymbols = this.extractExportedSymbols(node);
|
|
300
|
+
const isExternal = !target.startsWith(".") && !target.startsWith("/");
|
|
301
|
+
dependencies.push({
|
|
302
|
+
target,
|
|
303
|
+
statement: (lines[node.startPosition.row] ?? node.text).trim(),
|
|
304
|
+
line_number: node.startPosition.row + 1,
|
|
305
|
+
is_external: isExternal,
|
|
306
|
+
...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
if (node.type === "call_expression") {
|
|
314
|
+
const fnNode = node.childForFieldName("function") ?? node.namedChildren[0];
|
|
315
|
+
const argsNode = node.childForFieldName("arguments") ?? node.namedChildren.find((c) => c.type === "arguments");
|
|
316
|
+
if (fnNode && (fnNode.text === "require" || fnNode.type === "import") && argsNode) {
|
|
317
|
+
const firstArg = argsNode.namedChildren[0];
|
|
318
|
+
if (firstArg && (firstArg.type !== "string" && firstArg.type !== "template_string" || firstArg.text.includes("${"))) {
|
|
319
|
+
dependencies.push({ target: `dynamic:${node.text}`, statement: node.text, line_number: node.startPosition.row + 1, is_external: false });
|
|
320
|
+
}
|
|
321
|
+
if (firstArg && (firstArg.type === "string" || firstArg.type === "template_string")) {
|
|
322
|
+
const target = stripQuotes(firstArg.text.trim());
|
|
323
|
+
if (target && !target.includes("${")) {
|
|
324
|
+
const importedSymbols = this.extractRequireImportedSymbols(node);
|
|
325
|
+
const isExternal = !target.startsWith(".") && !target.startsWith("/");
|
|
326
|
+
dependencies.push({
|
|
327
|
+
target,
|
|
328
|
+
statement: (lines[node.startPosition.row] ?? node.text).trim(),
|
|
329
|
+
line_number: node.startPosition.row + 1,
|
|
330
|
+
is_external: isExternal,
|
|
331
|
+
...(importedSymbols.length > 0 ? { imported_symbols: importedSymbols } : {}),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
for (const child of node.namedChildren) {
|
|
339
|
+
walkDependencies(child);
|
|
340
|
+
}
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
walkDependencies(rootNode);
|
|
344
|
+
|
|
345
|
+
const processTopLevelNode = (stmtNode: Parser.SyntaxNode, isExported: boolean, outerStartRow?: number): void => {
|
|
346
|
+
const startRow = outerStartRow ?? stmtNode.startPosition.row;
|
|
347
|
+
const endRow = stmtNode.endPosition.row;
|
|
348
|
+
const lineStart = startRow + 1;
|
|
349
|
+
const lineEnd = Math.max(lineStart, endRow + 1);
|
|
350
|
+
const lineCount = Math.max(1, lineEnd - lineStart + 1);
|
|
351
|
+
|
|
352
|
+
if (stmtNode.type === "export_statement") {
|
|
353
|
+
const decl =
|
|
354
|
+
stmtNode.childForFieldName("declaration") ??
|
|
355
|
+
stmtNode.namedChildren.find((c) => c.type !== "decorator" && c.type !== "export_clause");
|
|
356
|
+
if (decl) {
|
|
357
|
+
processTopLevelNode(decl, true, stmtNode.startPosition.row);
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const sourceNode =
|
|
362
|
+
stmtNode.childForFieldName("source") ??
|
|
363
|
+
stmtNode.namedChildren.find((c) => c.type === "string");
|
|
364
|
+
if (!sourceNode) {
|
|
365
|
+
const exportClause = stmtNode.namedChildren.find((c) => c.type === "export_clause");
|
|
366
|
+
if (exportClause) {
|
|
367
|
+
for (const spec of exportClause.namedChildren) {
|
|
368
|
+
if (spec.type !== "export_specifier") continue;
|
|
369
|
+
const origName = spec.childForFieldName("name") ?? spec.namedChildren[0];
|
|
370
|
+
const aliasName = spec.childForFieldName("alias");
|
|
371
|
+
const exportedName = aliasName ? aliasName.text.trim() : origName ? origName.text.trim() : "";
|
|
372
|
+
if (!exportedName) continue;
|
|
373
|
+
if (aliasName && origName) {
|
|
374
|
+
symbols.push({
|
|
375
|
+
name: exportedName,
|
|
376
|
+
kind: "constant",
|
|
377
|
+
signature: `export { ${origName.text.trim()} as ${exportedName} }`,
|
|
378
|
+
visibility: "public",
|
|
379
|
+
line_start: lineStart,
|
|
380
|
+
line_end: lineEnd,
|
|
381
|
+
line_count: lineCount,
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
if (stmtNode.type === "internal_module") {
|
|
391
|
+
const name = stmtNode.childForFieldName("name");
|
|
392
|
+
const body = stmtNode.childForFieldName("body");
|
|
393
|
+
if (name && body && name.type !== "string") {
|
|
394
|
+
const firstSymbol = symbols.length;
|
|
395
|
+
for (const child of body.namedChildren) processTopLevelNode(child, false);
|
|
396
|
+
for (let i = firstSymbol; i < symbols.length; i++) {
|
|
397
|
+
symbols[i].name = `${name.text}::${symbols[i].name}`;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
return;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (
|
|
404
|
+
stmtNode.type === "class_declaration" ||
|
|
405
|
+
stmtNode.type === "abstract_class_declaration" ||
|
|
406
|
+
stmtNode.type === "interface_declaration"
|
|
407
|
+
) {
|
|
408
|
+
const nameNode =
|
|
409
|
+
stmtNode.childForFieldName("name") ??
|
|
410
|
+
stmtNode.namedChildren.find((c) => c.type === "type_identifier" || c.type === "identifier");
|
|
411
|
+
if (!nameNode) return;
|
|
412
|
+
|
|
413
|
+
const className = nameNode.text;
|
|
414
|
+
const kind: SymbolKind = stmtNode.type === "interface_declaration" ? "interface" : "class";
|
|
415
|
+
symbols.push({
|
|
416
|
+
name: className,
|
|
417
|
+
kind,
|
|
418
|
+
signature: getNodeHeader(stmtNode),
|
|
419
|
+
visibility: "public",
|
|
420
|
+
line_start: lineStart,
|
|
421
|
+
line_end: lineEnd,
|
|
422
|
+
line_count: lineCount,
|
|
423
|
+
});
|
|
424
|
+
|
|
425
|
+
const bodyNode =
|
|
426
|
+
stmtNode.childForFieldName("body") ??
|
|
427
|
+
stmtNode.namedChildren.find(
|
|
428
|
+
(c) => c.type === "class_body" || c.type === "interface_body" || c.type === "object_type"
|
|
429
|
+
);
|
|
430
|
+
if (bodyNode) {
|
|
431
|
+
this.extractClassOrInterfaceMembers(className, bodyNode, symbols);
|
|
432
|
+
}
|
|
433
|
+
return;
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
if (stmtNode.type === "type_alias_declaration" || stmtNode.type === "enum_declaration") {
|
|
437
|
+
const nameNode =
|
|
438
|
+
stmtNode.childForFieldName("name") ??
|
|
439
|
+
stmtNode.namedChildren.find((c) => c.type === "type_identifier" || c.type === "identifier");
|
|
440
|
+
if (!nameNode) return;
|
|
441
|
+
|
|
442
|
+
symbols.push({
|
|
443
|
+
name: nameNode.text,
|
|
444
|
+
kind: stmtNode.type === "enum_declaration" ? "enum" : "type",
|
|
445
|
+
signature: getNodeHeader(stmtNode),
|
|
446
|
+
visibility: "public",
|
|
447
|
+
line_start: lineStart,
|
|
448
|
+
line_end: lineEnd,
|
|
449
|
+
line_count: lineCount,
|
|
450
|
+
});
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (stmtNode.type === "function_declaration" || stmtNode.type === "generator_function_declaration") {
|
|
455
|
+
const nameNode =
|
|
456
|
+
stmtNode.childForFieldName("name") ??
|
|
457
|
+
stmtNode.namedChildren.find((c) => c.type === "identifier");
|
|
458
|
+
if (!nameNode) return;
|
|
459
|
+
|
|
460
|
+
const fnName = nameNode.text;
|
|
461
|
+
const paramsNode =
|
|
462
|
+
stmtNode.childForFieldName("parameters") ??
|
|
463
|
+
stmtNode.namedChildren.find((c) => c.type === "formal_parameters");
|
|
464
|
+
const retNode = stmtNode.childForFieldName("return_type");
|
|
465
|
+
const paramsText = paramsNode ? paramsNode.text : "()";
|
|
466
|
+
const retText = retNode ? `: ${retNode.text.replace(/^:\s*/, "")}` : "";
|
|
467
|
+
const nestingDepth = calculateAstControlFlowNesting(
|
|
468
|
+
stmtNode,
|
|
469
|
+
TS_CONTROL_FLOW_NODES,
|
|
470
|
+
TS_FUNCTION_BOUNDARY_NODES
|
|
471
|
+
);
|
|
472
|
+
|
|
473
|
+
symbols.push({
|
|
474
|
+
name: fnName,
|
|
475
|
+
kind: "function",
|
|
476
|
+
signature: `${fnName}${paramsText}${retText}`,
|
|
477
|
+
visibility: "public",
|
|
478
|
+
line_start: lineStart,
|
|
479
|
+
line_end: lineEnd,
|
|
480
|
+
line_count: lineCount,
|
|
481
|
+
nesting_depth: nestingDepth,
|
|
482
|
+
});
|
|
483
|
+
return;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (stmtNode.type === "lexical_declaration" || stmtNode.type === "variable_declaration") {
|
|
487
|
+
this.extractVariableDeclarations(stmtNode, isExported, outerStartRow, symbols);
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
|
|
491
|
+
for (const child of rootNode.namedChildren) {
|
|
492
|
+
processTopLevelNode(child, false);
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return { symbols, dependencies };
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private extractVariableDeclarations(
|
|
499
|
+
stmtNode: Parser.SyntaxNode,
|
|
500
|
+
isExported: boolean,
|
|
501
|
+
outerStartRow: number | undefined,
|
|
502
|
+
symbols: ExtractedSymbol[]
|
|
503
|
+
): void {
|
|
504
|
+
const declText = stmtNode.text.trimStart();
|
|
505
|
+
const isConst = declText.startsWith("const ") || declText.startsWith("const\t");
|
|
506
|
+
const declKeyword = isConst ? "const" : declText.startsWith("var ") ? "var" : "let";
|
|
507
|
+
|
|
508
|
+
for (const child of stmtNode.namedChildren) {
|
|
509
|
+
if (child.type !== "variable_declarator") continue;
|
|
510
|
+
const nameNode = child.childForFieldName("name") ?? child.namedChildren[0];
|
|
511
|
+
if (!nameNode) continue;
|
|
512
|
+
|
|
513
|
+
const dStart = (outerStartRow ?? child.startPosition.row) + 1;
|
|
514
|
+
const dEnd = Math.max(dStart, child.endPosition.row + 1);
|
|
515
|
+
const dCount = Math.max(1, dEnd - dStart + 1);
|
|
516
|
+
|
|
517
|
+
if (nameNode.type !== "identifier") {
|
|
518
|
+
const patternVars = this.extractPatternIdentifiers(nameNode);
|
|
519
|
+
for (const varName of patternVars) {
|
|
520
|
+
symbols.push({
|
|
521
|
+
name: varName,
|
|
522
|
+
kind: isConst ? "constant" : "variable",
|
|
523
|
+
signature: `${declKeyword} ${varName}`,
|
|
524
|
+
visibility: isExported ? "public" : "private",
|
|
525
|
+
line_start: dStart,
|
|
526
|
+
line_end: dEnd,
|
|
527
|
+
line_count: dCount,
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
continue;
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
const varName = nameNode.text;
|
|
534
|
+
const typeNode = child.childForFieldName("type");
|
|
535
|
+
const valueNode = child.childForFieldName("value");
|
|
536
|
+
const typeStr = typeNode ? `: ${typeNode.text.replace(/^:\s*/, "")}` : "";
|
|
537
|
+
|
|
538
|
+
if (
|
|
539
|
+
valueNode &&
|
|
540
|
+
(valueNode.type === "arrow_function" ||
|
|
541
|
+
valueNode.type === "function_expression" ||
|
|
542
|
+
valueNode.type === "function")
|
|
543
|
+
) {
|
|
544
|
+
const paramsNode =
|
|
545
|
+
valueNode.childForFieldName("parameters") ??
|
|
546
|
+
valueNode.namedChildren.find((c) => c.type === "formal_parameters");
|
|
547
|
+
const retNode = valueNode.childForFieldName("return_type");
|
|
548
|
+
const paramsText = paramsNode ? paramsNode.text : "()";
|
|
549
|
+
const retText = retNode ? `: ${retNode.text.replace(/^:\s*/, "")}` : typeStr;
|
|
550
|
+
const nestingDepth = calculateAstControlFlowNesting(
|
|
551
|
+
valueNode,
|
|
552
|
+
TS_CONTROL_FLOW_NODES,
|
|
553
|
+
TS_FUNCTION_BOUNDARY_NODES
|
|
554
|
+
);
|
|
555
|
+
|
|
556
|
+
symbols.push({
|
|
557
|
+
name: varName,
|
|
558
|
+
kind: "function",
|
|
559
|
+
signature: `${varName}${paramsText}${retText}`,
|
|
560
|
+
visibility: isExported ? "public" : "private",
|
|
561
|
+
line_start: dStart,
|
|
562
|
+
line_end: dEnd,
|
|
563
|
+
line_count: dCount,
|
|
564
|
+
nesting_depth: nestingDepth,
|
|
565
|
+
});
|
|
566
|
+
} else {
|
|
567
|
+
symbols.push({
|
|
568
|
+
name: varName,
|
|
569
|
+
kind: isConst ? "constant" : "variable",
|
|
570
|
+
signature: `${declKeyword} ${varName}${typeStr}`,
|
|
571
|
+
visibility: isExported ? "public" : "private",
|
|
572
|
+
line_start: dStart,
|
|
573
|
+
line_end: dEnd,
|
|
574
|
+
line_count: dCount,
|
|
575
|
+
});
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
private extractClassOrInterfaceMembers(
|
|
581
|
+
className: string,
|
|
582
|
+
bodyNode: Parser.SyntaxNode,
|
|
583
|
+
symbols: ExtractedSymbol[]
|
|
584
|
+
): void {
|
|
585
|
+
for (const member of bodyNode.namedChildren) {
|
|
586
|
+
const mStart = member.startPosition.row + 1;
|
|
587
|
+
const mEnd = Math.max(mStart, member.endPosition.row + 1);
|
|
588
|
+
const mCount = Math.max(1, mEnd - mStart + 1);
|
|
589
|
+
|
|
590
|
+
if (
|
|
591
|
+
member.type === "method_definition" ||
|
|
592
|
+
member.type === "method_signature" ||
|
|
593
|
+
member.type === "abstract_method_signature"
|
|
594
|
+
) {
|
|
595
|
+
const nameNode =
|
|
596
|
+
member.childForFieldName("name") ??
|
|
597
|
+
member.namedChildren.find(
|
|
598
|
+
(c) =>
|
|
599
|
+
c.type === "property_identifier" ||
|
|
600
|
+
c.type === "private_property_identifier" ||
|
|
601
|
+
c.type === "identifier"
|
|
602
|
+
);
|
|
603
|
+
if (!nameNode) continue;
|
|
604
|
+
|
|
605
|
+
const methodName = nameNode.text;
|
|
606
|
+
const vis = this.extractVisibility(member, methodName);
|
|
607
|
+
const paramsNode =
|
|
608
|
+
member.childForFieldName("parameters") ??
|
|
609
|
+
member.namedChildren.find((c) => c.type === "formal_parameters");
|
|
610
|
+
|
|
611
|
+
if (methodName === "constructor" && paramsNode) {
|
|
612
|
+
this.extractConstructorParameterProperties(className, paramsNode, symbols);
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
const retNode = member.childForFieldName("return_type");
|
|
616
|
+
const paramsText = paramsNode ? paramsNode.text : "()";
|
|
617
|
+
const retText = retNode ? `: ${retNode.text.replace(/^:\s*/, "")}` : "";
|
|
618
|
+
const nestingDepth = calculateAstControlFlowNesting(
|
|
619
|
+
member,
|
|
620
|
+
TS_CONTROL_FLOW_NODES,
|
|
621
|
+
TS_FUNCTION_BOUNDARY_NODES
|
|
622
|
+
);
|
|
623
|
+
|
|
624
|
+
symbols.push({
|
|
625
|
+
name: `${className}::${methodName}`,
|
|
626
|
+
kind: "method",
|
|
627
|
+
signature: `${vis} ${methodName}${paramsText}${retText}`,
|
|
628
|
+
visibility: vis,
|
|
629
|
+
line_start: mStart,
|
|
630
|
+
line_end: mEnd,
|
|
631
|
+
line_count: mCount,
|
|
632
|
+
nesting_depth: nestingDepth,
|
|
633
|
+
});
|
|
634
|
+
continue;
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
if (
|
|
638
|
+
member.type === "public_field_definition" ||
|
|
639
|
+
member.type === "field_definition" ||
|
|
640
|
+
member.type === "property_signature"
|
|
641
|
+
) {
|
|
642
|
+
const nameNode =
|
|
643
|
+
member.childForFieldName("name") ??
|
|
644
|
+
member.namedChildren.find(
|
|
645
|
+
(c) =>
|
|
646
|
+
c.type === "property_identifier" ||
|
|
647
|
+
c.type === "private_property_identifier" ||
|
|
648
|
+
c.type === "identifier"
|
|
649
|
+
);
|
|
650
|
+
if (!nameNode) continue;
|
|
651
|
+
|
|
652
|
+
const propName = nameNode.text;
|
|
653
|
+
const vis = this.extractVisibility(member, propName);
|
|
654
|
+
const typeNode = member.childForFieldName("type");
|
|
655
|
+
const typeStr = typeNode ? `: ${typeNode.text.replace(/^:\s*/, "")}` : "";
|
|
656
|
+
|
|
657
|
+
symbols.push({
|
|
658
|
+
name: `${className}::${propName}`,
|
|
659
|
+
kind: "property",
|
|
660
|
+
signature: `${vis} ${propName}${typeStr}`,
|
|
661
|
+
visibility: vis,
|
|
662
|
+
line_start: mStart,
|
|
663
|
+
line_end: mEnd,
|
|
664
|
+
line_count: mCount,
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
private extractVisibility(memberNode: Parser.SyntaxNode, memberName: string): Visibility {
|
|
671
|
+
if (memberName.startsWith("#")) return "private";
|
|
672
|
+
for (const child of memberNode.children) {
|
|
673
|
+
if (child.type === "accessibility_modifier") {
|
|
674
|
+
const text = child.text.trim();
|
|
675
|
+
if (text === "private" || text === "protected" || text === "public") {
|
|
676
|
+
return text;
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
return "public";
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
private extractImportedSymbols(importNode: Parser.SyntaxNode): string[] {
|
|
684
|
+
const names = new Set<string>();
|
|
685
|
+
const walkClause = (node: Parser.SyntaxNode): void => {
|
|
686
|
+
if (node.type === "import_specifier") {
|
|
687
|
+
const origName = node.childForFieldName("name") ?? node.namedChildren[0];
|
|
688
|
+
const aliasName = node.childForFieldName("alias");
|
|
689
|
+
if (origName && origName.text) names.add(origName.text.trim());
|
|
690
|
+
if (aliasName && aliasName.text) names.add(aliasName.text.trim());
|
|
691
|
+
return;
|
|
692
|
+
}
|
|
693
|
+
if (node.type === "namespace_import") {
|
|
694
|
+
const idNode = node.namedChildren.find((c) => c.type === "identifier");
|
|
695
|
+
if (idNode?.text) names.add(idNode.text.trim());
|
|
696
|
+
return;
|
|
697
|
+
}
|
|
698
|
+
if (node.type === "import_clause") {
|
|
699
|
+
for (const child of node.namedChildren) {
|
|
700
|
+
if (child.type === "identifier") {
|
|
701
|
+
names.add(child.text.trim());
|
|
702
|
+
} else {
|
|
703
|
+
walkClause(child);
|
|
704
|
+
}
|
|
705
|
+
}
|
|
706
|
+
return;
|
|
707
|
+
}
|
|
708
|
+
for (const child of node.namedChildren) {
|
|
709
|
+
if (child.type !== "string") {
|
|
710
|
+
walkClause(child);
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
};
|
|
714
|
+
walkClause(importNode);
|
|
715
|
+
return Array.from(names);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
private extractRequireImportedSymbols(callNode: Parser.SyntaxNode): string[] {
|
|
719
|
+
const names = new Set<string>();
|
|
720
|
+
const parent = callNode.parent;
|
|
721
|
+
if (parent && parent.type === "variable_declarator") {
|
|
722
|
+
const nameNode = parent.childForFieldName("name") ?? parent.namedChildren[0];
|
|
723
|
+
if (nameNode) {
|
|
724
|
+
if (nameNode.type === "identifier") {
|
|
725
|
+
names.add(nameNode.text.trim());
|
|
726
|
+
} else if (nameNode.type === "object_pattern") {
|
|
727
|
+
for (const prop of nameNode.namedChildren) {
|
|
728
|
+
if (prop.type === "shorthand_property_identifier_pattern" || prop.type === "identifier") {
|
|
729
|
+
names.add(prop.text.trim());
|
|
730
|
+
} else if (prop.type === "pair_pattern") {
|
|
731
|
+
const key = prop.childForFieldName("key") ?? prop.namedChildren[0];
|
|
732
|
+
const val = prop.childForFieldName("value") ?? prop.namedChildren[1];
|
|
733
|
+
if (key?.text) names.add(key.text.trim());
|
|
734
|
+
if (val?.text) names.add(val.text.trim());
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
return Array.from(names);
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
private extractExportedSymbols(exportNode: Parser.SyntaxNode): string[] {
|
|
744
|
+
const names = new Set<string>();
|
|
745
|
+
const walk = (node: Parser.SyntaxNode): void => {
|
|
746
|
+
if (node.type === "export_specifier") {
|
|
747
|
+
const origName = node.childForFieldName("name") ?? node.namedChildren[0];
|
|
748
|
+
const aliasName = node.childForFieldName("alias");
|
|
749
|
+
if (origName?.text) names.add(origName.text.trim());
|
|
750
|
+
if (aliasName?.text) names.add(aliasName.text.trim());
|
|
751
|
+
return;
|
|
752
|
+
}
|
|
753
|
+
if (node.type === "namespace_export") {
|
|
754
|
+
const idNode = node.namedChildren.find((c) => c.type === "identifier");
|
|
755
|
+
if (idNode?.text) names.add(idNode.text.trim());
|
|
756
|
+
return;
|
|
757
|
+
}
|
|
758
|
+
for (const child of node.namedChildren) {
|
|
759
|
+
if (child.type !== "string") {
|
|
760
|
+
walk(child);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
walk(exportNode);
|
|
765
|
+
return Array.from(names);
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
private extractConstructorParameterProperties(
|
|
769
|
+
className: string,
|
|
770
|
+
paramsNode: Parser.SyntaxNode,
|
|
771
|
+
symbols: ExtractedSymbol[]
|
|
772
|
+
): void {
|
|
773
|
+
for (const param of paramsNode.namedChildren) {
|
|
774
|
+
if (param.type !== "required_parameter" && param.type !== "optional_parameter") continue;
|
|
775
|
+
|
|
776
|
+
const hasAccessibility = param.namedChildren.some((c) => c.type === "accessibility_modifier");
|
|
777
|
+
const hasReadonly = param.namedChildren.some((c) => c.type === "readonly");
|
|
778
|
+
if (!hasAccessibility && !hasReadonly) continue;
|
|
779
|
+
|
|
780
|
+
const nameNode =
|
|
781
|
+
param.childForFieldName("pattern") ??
|
|
782
|
+
param.childForFieldName("name") ??
|
|
783
|
+
param.namedChildren.find((c) => c.type === "identifier");
|
|
784
|
+
if (!nameNode) continue;
|
|
785
|
+
|
|
786
|
+
const propName = nameNode.text.trim();
|
|
787
|
+
const vis = this.extractVisibility(param, propName);
|
|
788
|
+
const typeNode = param.childForFieldName("type");
|
|
789
|
+
const typeStr = typeNode ? `: ${typeNode.text.replace(/^:\s*/, "")}` : "";
|
|
790
|
+
const pStart = param.startPosition.row + 1;
|
|
791
|
+
const pEnd = Math.max(pStart, param.endPosition.row + 1);
|
|
792
|
+
|
|
793
|
+
symbols.push({
|
|
794
|
+
name: `${className}::${propName}`,
|
|
795
|
+
kind: "property",
|
|
796
|
+
signature: `${vis} ${propName}${typeStr}`,
|
|
797
|
+
visibility: vis,
|
|
798
|
+
line_start: pStart,
|
|
799
|
+
line_end: pEnd,
|
|
800
|
+
line_count: Math.max(1, pEnd - pStart + 1),
|
|
801
|
+
});
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
private extractPatternIdentifiers(node: Parser.SyntaxNode): string[] {
|
|
806
|
+
const results: string[] = [];
|
|
807
|
+
const walk = (n: Parser.SyntaxNode): void => {
|
|
808
|
+
if (n.type === "identifier" || n.type === "shorthand_property_identifier_pattern") {
|
|
809
|
+
results.push(n.text.trim());
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
if (n.type === "pair_pattern") {
|
|
813
|
+
const val = n.childForFieldName("value") ?? n.namedChildren[1];
|
|
814
|
+
if (val) walk(val);
|
|
815
|
+
return;
|
|
816
|
+
}
|
|
817
|
+
if (n.type === "assignment_pattern" || n.type === "object_assignment_pattern") {
|
|
818
|
+
const left = n.childForFieldName("left") ?? n.namedChildren[0];
|
|
819
|
+
if (left) walk(left);
|
|
820
|
+
return;
|
|
821
|
+
}
|
|
822
|
+
if (n.type === "rest_pattern") {
|
|
823
|
+
const arg = n.namedChildren[0];
|
|
824
|
+
if (arg) walk(arg);
|
|
825
|
+
return;
|
|
826
|
+
}
|
|
827
|
+
if (n.type === "object_pattern" || n.type === "array_pattern") {
|
|
828
|
+
for (const child of n.namedChildren) {
|
|
829
|
+
walk(child);
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
walk(node);
|
|
834
|
+
return results;
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
|
|
838
|
+
|
|
839
|
+
|