@dimassetoid/septum-mcp 0.2.1 → 0.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 +46 -45
- package/package.json +8 -6
- package/src/cli/commands/check.ts +41 -26
- package/src/cli/commands/hook.ts +77 -105
- package/src/cli/commands/init.ts +35 -9
- package/src/cli/commands/stats.ts +33 -0
- package/src/cli/commands/sync-progress.ts +71 -0
- package/src/cli/commands/sync.ts +35 -9
- package/src/cli/hook-payload.ts +43 -0
- package/src/cli/index.ts +15 -51
- package/src/cli/scaffold/harness-config.ts +48 -8
- package/src/cli/templates/hooks.ts +51 -27
- package/src/cli/templates/rules.ts +34 -49
- package/src/cli/templates/skill.ts +46 -35
- package/src/core/boundary/audit.ts +383 -0
- package/src/core/boundary/evaluator.ts +299 -178
- package/src/core/boundary/staged-auditor.ts +188 -34
- package/src/core/config/domain-ownership.ts +47 -0
- package/src/core/config/domain-registration.ts +141 -0
- package/src/core/config/loader.ts +82 -54
- package/src/core/config/schema.ts +24 -46
- package/src/core/database/client.ts +2 -0
- package/src/core/database/repositories/dependency.repository.ts +326 -543
- package/src/core/database/repositories/domain.repository.ts +48 -4
- package/src/core/database/repositories/file.repository.ts +10 -0
- package/src/core/database/repositories/symbol.repository.ts +97 -259
- package/src/core/database/repository.ts +138 -24
- package/src/core/database/schema.ts +28 -33
- package/src/core/discovery/declarative-routes.ts +69 -0
- package/src/core/discovery/framework-detector.ts +149 -0
- package/src/core/discovery/navigation.ts +269 -0
- package/src/core/discovery/topology-detector.ts +153 -170
- package/src/core/errors.ts +19 -0
- package/src/core/ingestion/pipeline.ts +378 -212
- package/src/core/parser/behavioral-analyzer.ts +26 -22
- package/src/core/parser/boundary-tracker.ts +15 -0
- package/src/core/parser/extractors/base.ts +16 -4
- package/src/core/parser/extractors/csharp.ts +9 -5
- package/src/core/parser/extractors/django-routing.ts +163 -0
- package/src/core/parser/extractors/django-semantic.ts +400 -516
- package/src/core/parser/extractors/elysia-semantic.ts +172 -496
- package/src/core/parser/extractors/express-semantic.ts +195 -398
- package/src/core/parser/extractors/fastapi-semantic.ts +182 -399
- package/src/core/parser/extractors/fastify-semantic.ts +216 -732
- package/src/core/parser/extractors/flask-semantic.ts +92 -388
- package/src/core/parser/extractors/go-routing.ts +344 -0
- package/src/core/parser/extractors/go-semantic.ts +210 -508
- package/src/core/parser/extractors/go.ts +6 -3
- package/src/core/parser/extractors/graphql-entrypoint.ts +146 -0
- package/src/core/parser/extractors/hono-semantic.ts +132 -530
- package/src/core/parser/extractors/java.ts +7 -5
- package/src/core/parser/extractors/laravel-routing.ts +263 -0
- package/src/core/parser/extractors/laravel-semantic.ts +169 -333
- package/src/core/parser/extractors/manifest-helpers.ts +64 -0
- package/src/core/parser/extractors/mcp-cli-dispatch.ts +268 -0
- package/src/core/parser/extractors/mcp-cli-semantic.ts +84 -336
- package/src/core/parser/extractors/nestjs-semantic.ts +238 -510
- package/src/core/parser/extractors/nextjs-semantic.ts +164 -0
- package/src/core/parser/extractors/php-ast-helpers.ts +51 -0
- package/src/core/parser/extractors/php.ts +17 -1
- package/src/core/parser/extractors/python-route-ast.ts +249 -0
- package/src/core/parser/extractors/python.ts +9 -8
- package/src/core/parser/extractors/registry.ts +28 -5
- package/src/core/parser/extractors/route-prefixes.ts +43 -0
- package/src/core/parser/extractors/ruby.ts +10 -7
- package/src/core/parser/extractors/rust.ts +35 -17
- package/src/core/parser/extractors/semantic-extractor.interface.ts +3 -1
- package/src/core/parser/extractors/symfony-routing.ts +114 -0
- package/src/core/parser/extractors/symfony-semantic.ts +75 -262
- package/src/core/parser/extractors/typescript-bindings.ts +333 -0
- package/src/core/parser/extractors/typescript-compiler-fallback.ts +380 -0
- package/src/core/parser/extractors/typescript-fallback.ts +207 -0
- package/src/core/parser/extractors/typescript-route-context.ts +58 -0
- package/src/core/parser/extractors/typescript.ts +36 -216
- package/src/core/parser/implementation-fingerprint.ts +97 -0
- package/src/core/parser/language-capabilities.ts +23 -7
- package/src/core/parser/schema/providers/laravel-migration-provider.ts +77 -51
- package/src/core/parser/schema/schema-provider-registry.ts +1 -3
- package/src/core/parser/schema/schema-provider.interface.ts +2 -1
- package/src/core/parser/semantic-revision.ts +3 -0
- package/src/core/parser/static-string.ts +51 -0
- package/src/core/parser/wasm-loader.ts +6 -2
- package/src/core/resolver/ast-method-tracer.ts +230 -0
- package/src/core/resolver/call-graph-helpers.ts +72 -0
- package/src/core/resolver/call-graph-tracer.ts +375 -311
- package/src/core/resolver/dependency-analysis.ts +593 -0
- package/src/core/resolver/import-candidates.ts +120 -0
- package/src/core/resolver/import-evidence.ts +88 -0
- package/src/core/resolver/import-resolver.ts +162 -181
- package/src/core/resolver/interpretation-inputs.ts +65 -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 +133 -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 +74 -0
- package/src/core/resolver/module-resolver.ts +18 -7
- package/src/core/resolver/path-resolver.ts +6 -3
- package/src/core/resolver/polyglot-slice-tracer.ts +197 -0
- package/src/core/resolver/slice-catalog.ts +94 -0
- package/src/core/resolver/slice-format.ts +22 -0
- package/src/core/resolver/slice-selection.ts +237 -0
- package/src/core/resolver/symbol-impact.ts +477 -0
- package/src/core/resolver/symbol-locator.ts +82 -15
- package/src/core/resolver/vertical-slice-tracer.ts +57 -278
- package/src/core/resources/ignore.ts +21 -1
- package/src/core/resources/limits.ts +2 -1
- package/src/core/resources/source-files.ts +143 -20
- package/src/core/resources/source-inventory.ts +55 -0
- package/src/core/resources/work-queue.ts +167 -4
- package/src/core/retrieval/context-page.ts +116 -0
- package/src/core/retrieval/context.ts +457 -0
- package/src/core/retrieval/resolution-warnings.ts +21 -0
- package/src/core/retrieval/source-context.ts +448 -0
- package/src/core/retrieval/symbol-details.ts +453 -0
- package/src/core/retrieval/symbol-evidence.ts +97 -0
- package/src/core/retrieval/typescript-references.ts +293 -0
- package/src/core/retrieval/universal-context.ts +182 -0
- package/src/core/telemetry/summary.ts +114 -0
- package/src/core/telemetry/telemetry.ts +225 -37
- package/src/index.ts +0 -3
- package/src/mcp/formatters/compact-text.ts +439 -0
- package/src/mcp/resources-and-prompts.ts +253 -0
- package/src/mcp/schemas/boundary.ts +145 -0
- package/src/mcp/schemas/map.ts +250 -0
- package/src/mcp/schemas/shared.ts +52 -0
- package/src/mcp/schemas/slice.ts +60 -0
- package/src/mcp/schemas/symbol.ts +268 -0
- package/src/mcp/schemas.ts +5 -1105
- package/src/mcp/server.ts +263 -597
- package/src/mcp/tool-catalog.ts +331 -0
- package/src/mcp/tools/boundary.ts +69 -4
- package/src/mcp/tools/map.ts +126 -0
- package/src/mcp/tools/slice.ts +101 -3
- package/src/mcp/tools/symbol.ts +480 -26
- package/src/mcp/ui/app-client.ts +899 -0
- package/src/mcp/ui/app.html +478 -0
- package/src/mcp/workflow-playbooks.ts +181 -0
- package/src/mcp/workspace-boundary.ts +50 -0
- package/src/mcp/workspace-manager.ts +102 -18
- package/src/mcp/workspace-watcher.ts +38 -19
- package/src/types/index.ts +47 -53
- package/src/cli/commands/topology.ts +0 -161
- package/src/core/database/repositories/environment.repository.ts +0 -207
- package/src/core/parser/schema/providers/prisma-schema-provider.ts +0 -90
- package/src/core/session/session-manager.ts +0 -107
- package/src/core/topology/environment-detector.ts +0 -973
- package/src/core/topology/types.ts +0 -83
- package/src/mcp/tools/check-boundary.ts +0 -387
- package/src/mcp/tools/domain.ts +0 -40
- package/src/mcp/tools/feature.ts +0 -67
- package/src/mcp/tools/get-domain-catalog.ts +0 -226
- package/src/mcp/tools/get-environment-topology.ts +0 -138
- package/src/mcp/tools/get-feature-context.ts +0 -224
- package/src/mcp/tools/get-symbol-hotspots.ts +0 -54
- package/src/mcp/tools/get-symbol-impact.ts +0 -64
- package/src/mcp/tools/get-symbol.ts +0 -175
- package/src/mcp/tools/locate-symbol.ts +0 -196
- package/src/mcp/tools/register-domain.ts +0 -75
- package/src/mcp/tools/register-feature.ts +0 -110
- package/src/mcp/tools/trace-vertical-slice.ts +0 -80
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import * as path from "node:path";
|
|
2
|
+
import ts from "typescript";
|
|
3
|
+
import { ImportResolver } from "../../resolver/import-resolver.ts";
|
|
4
|
+
import { bindContextFile } from "../../retrieval/typescript-references.ts";
|
|
5
|
+
import { readOptionalSourceFile } from "../../resources/source-files.ts";
|
|
6
|
+
|
|
7
|
+
export type Handler = { node: ts.FunctionLikeDeclaration; name: string };
|
|
8
|
+
type Unit = ReturnType<typeof bindContextFile>;
|
|
9
|
+
type PackageBinding = { module: string; name: string };
|
|
10
|
+
|
|
11
|
+
export function nodes(node: ts.Node, stopAtFunctions = false): ts.Node[] {
|
|
12
|
+
const found: ts.Node[] = [];
|
|
13
|
+
const visit = (child: ts.Node): void => {
|
|
14
|
+
found.push(child);
|
|
15
|
+
if (!stopAtFunctions || !ts.isFunctionLike(child)) ts.forEachChild(child, visit);
|
|
16
|
+
};
|
|
17
|
+
ts.forEachChild(node, visit);
|
|
18
|
+
return found;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export function unwrap(node: ts.Expression): ts.Expression {
|
|
22
|
+
while (ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isSatisfiesExpression(node) ||
|
|
23
|
+
ts.isNonNullExpression(node) || ts.isAwaitExpression(node)) node = node.expression;
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export function nameText(node: ts.Node | undefined): string | undefined {
|
|
28
|
+
return node && (ts.isIdentifier(node) || ts.isStringLiteral(node) || ts.isNoSubstitutionTemplateLiteral(node)) ? node.text : undefined;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function literal(node: ts.Expression | undefined): string | undefined {
|
|
32
|
+
return node && ts.isStringLiteralLike(node) ? node.text : undefined;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export function lineOf(node: ts.Node): number {
|
|
36
|
+
return node.getSourceFile().getLineAndCharacterOfPosition(node.getStart()).line + 1;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function visitRouteCalls(
|
|
40
|
+
container: ts.SourceFile | ts.Block | ts.Expression,
|
|
41
|
+
visit: (call: ts.CallExpression) => void,
|
|
42
|
+
): void {
|
|
43
|
+
const walk = (node: ts.Node): void => {
|
|
44
|
+
if (ts.isFunctionLike(node) || ts.isClassLike(node) || ts.isConditionalExpression(node)) return;
|
|
45
|
+
ts.forEachChild(node, walk);
|
|
46
|
+
if (ts.isCallExpression(node)) visit(node);
|
|
47
|
+
};
|
|
48
|
+
if (ts.isSourceFile(container) || ts.isBlock(container)) {
|
|
49
|
+
for (const statement of container.statements) {
|
|
50
|
+
if (ts.isVariableStatement(statement) || ts.isExpressionStatement(statement) || ts.isExportAssignment(statement) ||
|
|
51
|
+
ts.isReturnStatement(statement)) {
|
|
52
|
+
walk(statement);
|
|
53
|
+
} else if (ts.isFunctionDeclaration(statement) && statement.body) {
|
|
54
|
+
visitRouteCalls(statement.body, visit);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} else walk(container);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function objectMember(
|
|
61
|
+
node: ts.ObjectLiteralExpression,
|
|
62
|
+
key: string,
|
|
63
|
+
): ts.Expression | ts.MethodDeclaration | undefined {
|
|
64
|
+
for (const property of [...node.properties].reverse()) {
|
|
65
|
+
// An unknown later assignment may override this property.
|
|
66
|
+
if (ts.isSpreadAssignment(property) || (property.name && ts.isComputedPropertyName(property.name))) return undefined;
|
|
67
|
+
if (nameText(property.name) !== key) continue;
|
|
68
|
+
if (ts.isPropertyAssignment(property)) return property.initializer;
|
|
69
|
+
if (ts.isShorthandPropertyAssignment(property)) return property.name;
|
|
70
|
+
if (ts.isMethodDeclaration(property)) return property;
|
|
71
|
+
return undefined;
|
|
72
|
+
}
|
|
73
|
+
return undefined;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function importTarget(node: ts.Node): string | undefined {
|
|
77
|
+
for (let parent: ts.Node | undefined = node; parent; parent = parent.parent) {
|
|
78
|
+
if (ts.isImportDeclaration(parent) || ts.isExportDeclaration(parent)) {
|
|
79
|
+
return parent.moduleSpecifier && nameText(parent.moduleSpecifier);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export class TypeScriptBindings {
|
|
86
|
+
private readonly indexed = new Map<string, Unit | undefined>();
|
|
87
|
+
private readonly textCache = new Map<string, string | undefined>();
|
|
88
|
+
private readonly resolver: ImportResolver;
|
|
89
|
+
|
|
90
|
+
constructor(private readonly root: string, private readonly files: ReadonlySet<string>, private readonly signal?: AbortSignal) {
|
|
91
|
+
this.resolver = new ImportResolver(root);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
private readText(file: string): string | undefined {
|
|
95
|
+
this.signal?.throwIfAborted();
|
|
96
|
+
if (!this.files.has(file)) return undefined;
|
|
97
|
+
if (!this.textCache.has(file)) {
|
|
98
|
+
this.textCache.set(file, readOptionalSourceFile(file, "utf-8"));
|
|
99
|
+
}
|
|
100
|
+
return this.textCache.get(file);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** Fast text pre-filter before constructing a TypeScript Program/TypeChecker for a file. */
|
|
104
|
+
matches(file: string, pattern: RegExp): boolean {
|
|
105
|
+
const text = this.readText(file);
|
|
106
|
+
return text !== undefined && pattern.test(text);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
load(file: string): Unit | undefined {
|
|
110
|
+
this.signal?.throwIfAborted();
|
|
111
|
+
if (!this.files.has(file)) return undefined;
|
|
112
|
+
if (!this.indexed.has(file)) {
|
|
113
|
+
const text = this.readText(file);
|
|
114
|
+
this.textCache.delete(file);
|
|
115
|
+
const unit = text ? bindContextFile(file, text) : undefined;
|
|
116
|
+
this.indexed.set(file, unit?.hasErrors ? undefined : unit);
|
|
117
|
+
}
|
|
118
|
+
return this.indexed.get(file);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
declaration(name: ts.Node): ts.Declaration | undefined {
|
|
122
|
+
const unit = this.load(name.getSourceFile().fileName);
|
|
123
|
+
const symbol = ts.isShorthandPropertyAssignment(name.parent) && name.parent.name === name
|
|
124
|
+
? unit?.checker.getShorthandAssignmentValueSymbol(name.parent) : unit?.checker.getSymbolAtLocation(name);
|
|
125
|
+
return symbol?.declarations?.length === 1 ? symbol.declarations[0] : undefined;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
sdk(name: ts.Node | undefined, expected: string, packageName = "@modelcontextprotocol/sdk"): boolean {
|
|
129
|
+
if (!name) return false;
|
|
130
|
+
const declaration = this.declaration(name);
|
|
131
|
+
const target = declaration && importTarget(declaration);
|
|
132
|
+
return Boolean(declaration && ts.isImportSpecifier(declaration) && !declaration.isTypeOnly &&
|
|
133
|
+
!declaration.parent.parent.isTypeOnly && (declaration.propertyName ?? declaration.name).text === expected &&
|
|
134
|
+
(target === packageName || target?.startsWith(packageName + "/")));
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
initializer(node: ts.Declaration | undefined): ts.Expression | undefined {
|
|
138
|
+
if (!node || !ts.isVariableDeclaration(node) || !ts.isVariableDeclarationList(node.parent) ||
|
|
139
|
+
!(node.parent.flags & ts.NodeFlags.Const)) return undefined;
|
|
140
|
+
return node.initializer;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
private module(spec: string, from: ts.Node): Unit | undefined {
|
|
144
|
+
const result = this.resolver.resolve(spec, from.getSourceFile().fileName);
|
|
145
|
+
if (result.status !== "resolved") return undefined;
|
|
146
|
+
const matches = result.targets.flatMap(target => target.files);
|
|
147
|
+
return matches.length === 1 ? this.load(path.resolve(this.root, matches[0]!)) : undefined;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
visitModules(files: readonly string[], visit: (unit: Unit) => void, pattern?: RegExp): void {
|
|
151
|
+
const visited = new Set<string>();
|
|
152
|
+
const evaluate = (unit: Unit) => {
|
|
153
|
+
this.signal?.throwIfAborted();
|
|
154
|
+
if (visited.has(unit.source.fileName)) return;
|
|
155
|
+
visited.add(unit.source.fileName);
|
|
156
|
+
for (const stmt of unit.source.statements) {
|
|
157
|
+
if (!(ts.isImportDeclaration(stmt) || ts.isExportDeclaration(stmt))) continue;
|
|
158
|
+
if (ts.isImportDeclaration(stmt) ? stmt.importClause?.isTypeOnly : stmt.isTypeOnly) continue;
|
|
159
|
+
const spec = nameText(stmt.moduleSpecifier);
|
|
160
|
+
const dependency = spec && this.module(spec, stmt);
|
|
161
|
+
if (dependency) evaluate(dependency);
|
|
162
|
+
}
|
|
163
|
+
visit(unit);
|
|
164
|
+
};
|
|
165
|
+
for (const file of files) {
|
|
166
|
+
if (pattern && !this.matches(file, pattern)) continue;
|
|
167
|
+
const unit = this.load(file);
|
|
168
|
+
if (unit) evaluate(unit);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
definition(expression: ts.Expression, seen = new Set<ts.Node>()): ts.Declaration | undefined {
|
|
173
|
+
const node = this.value(expression);
|
|
174
|
+
if (!node || seen.has(node) || seen.size >= 24) return undefined;
|
|
175
|
+
seen.add(node);
|
|
176
|
+
if (ts.isNewExpression(node)) return this.definition(node.expression, seen);
|
|
177
|
+
if (ts.isIdentifier(node)) {
|
|
178
|
+
const declaration = this.declaration(node);
|
|
179
|
+
if (!declaration) return undefined;
|
|
180
|
+
if ((ts.isImportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) ||
|
|
181
|
+
(ts.isImportClause(declaration) && !declaration.isTypeOnly)) {
|
|
182
|
+
const spec = importTarget(declaration);
|
|
183
|
+
const target = spec && this.module(spec, declaration);
|
|
184
|
+
const name = ts.isImportSpecifier(declaration) ? (declaration.propertyName ?? declaration.name).text : "default";
|
|
185
|
+
return target ? this.exportDeclaration(target, name) : undefined;
|
|
186
|
+
}
|
|
187
|
+
return declaration;
|
|
188
|
+
}
|
|
189
|
+
return undefined;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
private exported(unit: Unit, name: string, seen: Set<ts.Node>): Handler | undefined {
|
|
193
|
+
return this.target(this.exportDeclaration(unit, name), seen);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private exportDeclaration(unit: Unit, name: string): ts.Declaration | undefined {
|
|
197
|
+
const symbol = unit.checker.getSymbolAtLocation(unit.source);
|
|
198
|
+
const exported = symbol && unit.checker.getExportsOfModule(symbol).find(item => item.name === name);
|
|
199
|
+
return exported?.declarations?.length === 1 ? exported.declarations[0] : undefined;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
value(expression: ts.Expression | undefined, seen = new Set<ts.Node>()): ts.Expression | undefined {
|
|
203
|
+
if (!expression) return undefined;
|
|
204
|
+
const node = unwrap(expression);
|
|
205
|
+
if (ts.isIdentifier(node)) return this.declarationValue(this.declaration(node), seen) ?? node;
|
|
206
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
|
|
207
|
+
const declaration = this.declaration(node.expression);
|
|
208
|
+
if (declaration && ts.isNamespaceImport(declaration) && !declaration.parent.isTypeOnly) {
|
|
209
|
+
const spec = importTarget(declaration);
|
|
210
|
+
const unit = spec && this.module(spec, node);
|
|
211
|
+
return (unit && this.declarationValue(this.exportDeclaration(unit, node.name.text), seen)) || node;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return node;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
private declarationValue(declaration: ts.Declaration | undefined, seen: Set<ts.Node>): ts.Expression | undefined {
|
|
218
|
+
if (!declaration || seen.has(declaration) || seen.size >= 24) return undefined;
|
|
219
|
+
seen.add(declaration);
|
|
220
|
+
if (ts.isExportAssignment(declaration) && !declaration.isExportEquals) return this.value(declaration.expression, seen);
|
|
221
|
+
if (ts.isExportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) {
|
|
222
|
+
const spec = importTarget(declaration);
|
|
223
|
+
if (spec) {
|
|
224
|
+
const target = this.module(spec, declaration);
|
|
225
|
+
const imported = (declaration.propertyName ?? declaration.name).text;
|
|
226
|
+
return target && this.declarationValue(this.exportDeclaration(target, imported), seen);
|
|
227
|
+
}
|
|
228
|
+
const unit = this.load(declaration.getSourceFile().fileName);
|
|
229
|
+
const local = unit?.checker.getExportSpecifierLocalTargetSymbol(declaration)?.declarations;
|
|
230
|
+
return local?.length === 1 ? this.declarationValue(local[0], seen) : undefined;
|
|
231
|
+
}
|
|
232
|
+
if ((ts.isImportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) ||
|
|
233
|
+
(ts.isImportClause(declaration) && !declaration.isTypeOnly)) {
|
|
234
|
+
const spec = importTarget(declaration);
|
|
235
|
+
const target = spec && this.module(spec, declaration);
|
|
236
|
+
const name = ts.isImportSpecifier(declaration) ? (declaration.propertyName ?? declaration.name).text : "default";
|
|
237
|
+
return target ? this.declarationValue(this.exportDeclaration(target, name), seen) : undefined;
|
|
238
|
+
}
|
|
239
|
+
return this.value(this.initializer(declaration), seen);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
packageBinding(expression: ts.Expression | undefined, seen = new Set<ts.Node>()): PackageBinding | undefined {
|
|
243
|
+
const node = this.value(expression);
|
|
244
|
+
if (!node || seen.has(node) || seen.size >= 24) return undefined;
|
|
245
|
+
seen.add(node);
|
|
246
|
+
if (ts.isPropertyAccessExpression(node)) {
|
|
247
|
+
const owner = this.packageBinding(node.expression, seen);
|
|
248
|
+
if (owner?.name === "*" || owner?.name === "default") return { module: owner.module, name: node.name.text };
|
|
249
|
+
}
|
|
250
|
+
if (ts.isCallExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === "require" &&
|
|
251
|
+
!this.declaration(node.expression)) {
|
|
252
|
+
const module = literal(node.arguments[0]);
|
|
253
|
+
if (module) return { module, name: "default" };
|
|
254
|
+
}
|
|
255
|
+
if (!ts.isIdentifier(node)) return undefined;
|
|
256
|
+
const declaration = this.declaration(node);
|
|
257
|
+
if (!declaration) return undefined;
|
|
258
|
+
const module = importTarget(declaration);
|
|
259
|
+
if (!module) return undefined;
|
|
260
|
+
if (ts.isImportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) {
|
|
261
|
+
return { module, name: (declaration.propertyName ?? declaration.name).text };
|
|
262
|
+
}
|
|
263
|
+
if (ts.isImportClause(declaration) && !declaration.isTypeOnly) return { module, name: "default" };
|
|
264
|
+
if (ts.isNamespaceImport(declaration) && !declaration.parent.isTypeOnly) return { module, name: "*" };
|
|
265
|
+
return undefined;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
handler(expression: ts.Expression | undefined, seen = new Set<ts.Node>()): Handler | undefined {
|
|
269
|
+
if (!expression) return undefined;
|
|
270
|
+
const node = unwrap(expression);
|
|
271
|
+
if (ts.isIdentifier(node)) return this.target(this.declaration(node), seen);
|
|
272
|
+
if (ts.isFunctionExpression(node) || ts.isArrowFunction(node)) return this.target(node, seen);
|
|
273
|
+
if (ts.isCallExpression(node) && node.arguments.length >= 1) {
|
|
274
|
+
for (const arg of node.arguments) {
|
|
275
|
+
if (ts.isFunctionExpression(arg) || ts.isArrowFunction(arg)) {
|
|
276
|
+
const inner = this.handler(arg, seen);
|
|
277
|
+
if (inner) return inner;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.expression)) {
|
|
282
|
+
const declaration = this.declaration(node.expression);
|
|
283
|
+
const moduleName = declaration && importTarget(declaration);
|
|
284
|
+
if (declaration && ts.isNamespaceImport(declaration) && !declaration.parent.isTypeOnly && moduleName) {
|
|
285
|
+
const unit = this.module(moduleName, node);
|
|
286
|
+
if (unit) return this.exported(unit, node.name.text, seen);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private target(declaration: ts.Declaration | undefined, seen: Set<ts.Node>): Handler | undefined {
|
|
293
|
+
if (!declaration || seen.has(declaration) || seen.size >= 24) return undefined;
|
|
294
|
+
seen.add(declaration);
|
|
295
|
+
if ((ts.isFunctionDeclaration(declaration) || ts.isArrowFunction(declaration) || ts.isFunctionExpression(declaration)) && declaration.body) {
|
|
296
|
+
const parentName = ts.isVariableDeclaration(declaration.parent) ? nameText(declaration.parent.name) : undefined;
|
|
297
|
+
return { node: declaration, name: nameText(declaration.name) ?? parentName ?? "callback" };
|
|
298
|
+
}
|
|
299
|
+
if (ts.isExportAssignment(declaration) && !declaration.isExportEquals) {
|
|
300
|
+
return this.handler(declaration.expression, seen);
|
|
301
|
+
}
|
|
302
|
+
if (ts.isExportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) {
|
|
303
|
+
const spec = importTarget(declaration);
|
|
304
|
+
if (spec) {
|
|
305
|
+
const unit = this.module(spec, declaration);
|
|
306
|
+
return unit && this.exported(unit, (declaration.propertyName ?? declaration.name).text, seen);
|
|
307
|
+
}
|
|
308
|
+
const unit = this.load(declaration.getSourceFile().fileName);
|
|
309
|
+
const local = unit?.checker.getExportSpecifierLocalTargetSymbol(declaration);
|
|
310
|
+
return this.target(local?.declarations?.length === 1 ? local.declarations[0] : undefined, seen);
|
|
311
|
+
}
|
|
312
|
+
if ((ts.isImportSpecifier(declaration) && !declaration.isTypeOnly && !declaration.parent.parent.isTypeOnly) ||
|
|
313
|
+
(ts.isImportClause(declaration) && !declaration.isTypeOnly)) {
|
|
314
|
+
const spec = importTarget(declaration);
|
|
315
|
+
const unit = spec && this.module(spec, declaration);
|
|
316
|
+
const name = ts.isImportSpecifier(declaration) ? (declaration.propertyName ?? declaration.name).text : "default";
|
|
317
|
+
return unit ? this.exported(unit, name, seen) : undefined;
|
|
318
|
+
}
|
|
319
|
+
if (ts.isBindingElement(declaration) && ts.isObjectBindingPattern(declaration.parent) && !declaration.dotDotDotToken &&
|
|
320
|
+
!declaration.initializer && ts.isIdentifier(declaration.name)) {
|
|
321
|
+
const owner = declaration.parent.parent;
|
|
322
|
+
const init = ts.isVariableDeclaration(owner) && this.initializer(owner);
|
|
323
|
+
const call = init && unwrap(init);
|
|
324
|
+
if (call && ts.isCallExpression(call) && call.expression.kind === ts.SyntaxKind.ImportKeyword) {
|
|
325
|
+
const spec = literal(call.arguments[0]);
|
|
326
|
+
const unit = spec && this.module(spec, declaration);
|
|
327
|
+
const name = nameText(declaration.propertyName ?? declaration.name);
|
|
328
|
+
return unit && name ? this.exported(unit, name, seen) : undefined;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return this.handler(this.initializer(declaration), seen);
|
|
332
|
+
}
|
|
333
|
+
}
|