@nudojs/service 3.0.0 → 5.0.0-beta.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 +19 -4
- package/dist/analysis-CSXrOVlg.d.ts +267 -0
- package/dist/analysis.d.ts +7 -0
- package/dist/analysis.js +57 -0
- package/dist/analyzer-types-JyJiCt8w.d.ts +158 -0
- package/dist/call-record-CkyCFkT9.d.ts +33 -0
- package/dist/case.d.ts +124 -0
- package/dist/case.js +18 -0
- package/dist/chunk-6IZR4ZYJ.js +1107 -0
- package/dist/chunk-E4N4A4JV.js +651 -0
- package/dist/chunk-HEU4WON5.js +2419 -0
- package/dist/chunk-K3ZPOTP2.js +199 -0
- package/dist/chunk-LFZRUXGK.js +89 -0
- package/dist/chunk-PVJIMQRI.js +246 -0
- package/dist/chunk-QAFMPM2E.js +3687 -0
- package/dist/chunk-QYRH7Z2Q.js +89 -0
- package/dist/chunk-U7JYTRIB.js +888 -0
- package/dist/{chunk-ADFCZP72.js → chunk-YLALZXTZ.js} +180 -165
- package/dist/chunk-YLVZMHWC.js +364 -0
- package/dist/{config-Cqj8zeZH.d.ts → config-DDB588oA.d.ts} +45 -48
- package/dist/dts.d.ts +142 -0
- package/dist/dts.js +30 -0
- package/dist/env-loader-fj0TSCcA.d.ts +20 -0
- package/dist/evaluator/evaluator-api.d.ts +3 -1
- package/dist/evaluator/evaluator-api.js +9 -3
- package/dist/harvest.d.ts +254 -0
- package/dist/harvest.js +75 -0
- package/dist/index.d.ts +293 -1197
- package/dist/index.js +328 -7639
- package/dist/interface-BGlP7aIk.d.ts +367 -0
- package/dist/interface.d.ts +3 -0
- package/dist/interface.js +43 -0
- package/dist/lsp.d.ts +103 -0
- package/dist/lsp.js +36 -0
- package/package.json +32 -8
package/README.md
CHANGED
|
@@ -4,16 +4,31 @@ Shared inference service for [Nudo](https://github.com/nudojs/nudo) IDE integrat
|
|
|
4
4
|
|
|
5
5
|
## What is Nudo?
|
|
6
6
|
|
|
7
|
-
Nudo is a type inference engine for JavaScript.
|
|
7
|
+
Nudo is a type inference engine for JavaScript. The type system is Abs (`shape × term × pred × conf`); production analysis is Abs-native via abstract interpretation — no TypeScript, no build step.
|
|
8
8
|
|
|
9
9
|
## This package
|
|
10
10
|
|
|
11
|
-
`@nudojs/service` provides the high-level analysis API used by editor extensions and build tools
|
|
11
|
+
`@nudojs/service` provides the high-level analysis API used by editor extensions and build tools.
|
|
12
|
+
|
|
13
|
+
Production evaluation is **Abs-native B-path** (`evalAbsModuleGraph` + `runTranspiled`); the TypeValue AST interpreter is gone. Prefer a focused subpath over the full barrel:
|
|
14
|
+
|
|
15
|
+
| Subpath | Face |
|
|
16
|
+
|---|---|
|
|
17
|
+
| `@nudojs/service/analysis` | File analysis, diagnostics, call records, Abs module-graph eval |
|
|
18
|
+
| `@nudojs/service/interface` | Interface / contract product (surface, emit, draft, derive) |
|
|
19
|
+
| `@nudojs/service/dts` | Extensional projections: dts / schema / standard / guard |
|
|
20
|
+
| `@nudojs/service/case` | Debug case reports + case directive emit (`nudo test`) |
|
|
21
|
+
| `@nudojs/service/lsp` | IDE surface (hover, completions, semantic tokens, inlays) |
|
|
22
|
+
| `@nudojs/service/harvest` | `@types` → Abs env harvesting |
|
|
23
|
+
| `@nudojs/service/evaluator` | Host API surface (env/config/CallRecord) — not the eval engine |
|
|
24
|
+
| `@nudojs/service` | Full barrel (stable; all of the above) |
|
|
25
|
+
|
|
26
|
+
Highlights:
|
|
12
27
|
|
|
13
28
|
- **File analysis** — `analyzeFile` returns diagnostics, function analyses, and case results
|
|
14
29
|
- **IDE features** — `getTypeAtPosition`, `getCompletionsAtPosition`, `getCasesForFile`
|
|
15
|
-
- **DTS generation** — `generateDts`
|
|
16
|
-
- **
|
|
30
|
+
- **DTS generation** — `generateDts` / `absToTSType` for producing `.d.ts` output from Abs
|
|
31
|
+
- **Schema projection** — `absToSchemaSource` / `projectAbsToSchema` produce dialect schema source
|
|
17
32
|
- **Guard generation** — `generateGuardFunction` produces zero-dependency runtime type guards
|
|
18
33
|
|
|
19
34
|
## Install
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
import { A as AnalyzeLoadModule, D as DirectiveCaseMode, a as AnalysisResult } from './analyzer-types-JyJiCt8w.js';
|
|
2
|
+
import { C as CallRecord } from './call-record-CkyCFkT9.js';
|
|
3
|
+
import { Abs, AbsModuleExports, BCallRecord, Phi, TranspiledCallResult } from '@nudojs/core';
|
|
4
|
+
import { Node } from '@babel/types';
|
|
5
|
+
import { BMemberDiag } from '@nudojs/core/internal';
|
|
6
|
+
import { D as DiagnosticsLevel, A as AnalysisConfig } from './config-DDB588oA.js';
|
|
7
|
+
|
|
8
|
+
/** mtime 边缓存:key 为文件路径,edges 为已抽取的相对 import 边(与 buildModuleGraph 返回语义一致)。 */
|
|
9
|
+
type ModuleGraphCache = Map<string, {
|
|
10
|
+
mtimeMs: number;
|
|
11
|
+
size: number;
|
|
12
|
+
edges: string[];
|
|
13
|
+
}>;
|
|
14
|
+
/** Statically extract each file's relative import edges (extension resolution identical to CLI resolveModule: ''/'.js'/'.ts'/'.mjs'; bare npm specifiers skipped). */
|
|
15
|
+
declare function buildModuleGraph(files: string[], cache?: ModuleGraphCache): {
|
|
16
|
+
imports: Map<string, Set<string>>;
|
|
17
|
+
dependents: Map<string, Set<string>>;
|
|
18
|
+
};
|
|
19
|
+
/** changed plus its transitive dependents (reverse-edge BFS); cycle-safe via visited. */
|
|
20
|
+
declare function computeDirtySet(dependents: Map<string, Set<string>>, changedFile: string): string[];
|
|
21
|
+
/** Topological order with dependencies before dependents (only imports edges internal to dirty; cycles tolerated — remaining files appended in arbitrary order). */
|
|
22
|
+
declare function topoSortDirty(imports: Map<string, Set<string>>, dirty: string[]): string[];
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 调用点发现(阶段一):在"使用现场"文件(测试 / 上层应用)中求值
|
|
26
|
+
* 顶层代码,收集它对(外部模块导出的)函数的调用记录。每条记录带
|
|
27
|
+
* 真实的实参类型与结果类型——后续 analyzeFile 将其注入合成 case,
|
|
28
|
+
* 使被使用方从 entry-only(参数全 unknown)升级为真实调用形态。
|
|
29
|
+
*
|
|
30
|
+
* Abs 路径(TypeValue evaluateProgram 已删):evalAbsModuleGraph + AbsCallRecord。
|
|
31
|
+
* 只做求值与记录,不产出诊断;求值异常不抛出(使用现场文件可能
|
|
32
|
+
* 依赖未 mock 的全局,收集不到就收集不到,不能拖垮主分析)。
|
|
33
|
+
*/
|
|
34
|
+
declare function collectCallRecords(filePath: string, source: string): CallRecord[];
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Async entry to analyzeFile: preloads path-based env files
|
|
38
|
+
* (`/// @nudo:env ./nudo-harvest-node.ts`) via dynamic import — impossible
|
|
39
|
+
* synchronously in ESM — then runs the sync analysis, which picks the
|
|
40
|
+
* preloaded factories up from the env-loader cache.
|
|
41
|
+
* `loadModule` is optional; when provided it is used for relative imports /
|
|
42
|
+
* sidecar ambient bindings (LSP buffer-aware path). Default remains
|
|
43
|
+
* `defaultLoadModule` (disk).
|
|
44
|
+
*/
|
|
45
|
+
declare function analyzeFileAsync(filePath: string, source: string, activeCases?: Map<string, number>, externalCallRecords?: CallRecord[], loadModule?: AnalyzeLoadModule,
|
|
46
|
+
/** 默认 all(库/测试兼容);check/IDE 宿主应传 none(惰性 case) */
|
|
47
|
+
caseMode?: DirectiveCaseMode): Promise<AnalysisResult>;
|
|
48
|
+
/**
|
|
49
|
+
* 整文件分析。同 (path, source, cases, external) 命中 memo → O(1)。
|
|
50
|
+
* 不再每次 clearBPathCache:B 路径按本文件 source 键控。
|
|
51
|
+
*
|
|
52
|
+
* `loadModule`:可选;提供时用于相对 import / 侧车 ambient(LSP
|
|
53
|
+
* buffer-aware)。未提供时走 defaultLoadModule(磁盘)。
|
|
54
|
+
*
|
|
55
|
+
* 宿主契约:入口 source 未变但依赖模块内容变了时,必须调用
|
|
56
|
+
* `evictBPathCacheForFiles` / `evictAnalysisFileCacheForFiles` /
|
|
57
|
+
* `evictFnAnalysisCacheForFiles`(LSP 已接好)。非 LSP 宿主
|
|
58
|
+
* (CLI watch / vite-plugin)在 dep 变更时应 `clearBPathCache()` 或上述逐出。
|
|
59
|
+
*/
|
|
60
|
+
declare function analyzeFile(filePath: string, source: string, activeCases?: Map<string, number>, externalCallRecords?: CallRecord[], loadModule?: AnalyzeLoadModule, caseMode?: DirectiveCaseMode): AnalysisResult;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Host:import 图(相对 + 裸包 harvest)→ Abs 导出表 → 注入入口。
|
|
64
|
+
* 读 fs / 解析路径 / harvest 在这里;core 只收 modules 表。
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
type AbsLoadModule = (spec: string, fromFile: string) => string | undefined;
|
|
68
|
+
/** 相对说明符 → 源码 */
|
|
69
|
+
declare function defaultAbsLoadModule(spec: string, fromFile: string): string | undefined;
|
|
70
|
+
/** 模块加载守卫:与 TypeValue loadModuleEnv 口径对齐,供 analyzer 映射诊断 */
|
|
71
|
+
type AbsModuleLoadIssue = {
|
|
72
|
+
kind: "cycle" | "depth" | "missing";
|
|
73
|
+
/** 诊断定位用标签(文件 basename 或 require/import 说明符) */
|
|
74
|
+
label: string;
|
|
75
|
+
reason: string;
|
|
76
|
+
};
|
|
77
|
+
type AbsModuleGraphResult = {
|
|
78
|
+
/** 入口 import 说明符 → 依赖导出表 */
|
|
79
|
+
modules: Record<string, AbsModuleExports>;
|
|
80
|
+
/** 绝对路径 → 导出表(含依赖;循环时占位为空) */
|
|
81
|
+
byPath: Map<string, AbsModuleExports>;
|
|
82
|
+
/** cycle / depth / missing(B 路径权威,避免 TypeValue 叠报) */
|
|
83
|
+
issues: AbsModuleLoadIssue[];
|
|
84
|
+
};
|
|
85
|
+
type AbsGraphOptions = {
|
|
86
|
+
loadModule?: AbsLoadModule;
|
|
87
|
+
seedVars?: Record<string, Abs>;
|
|
88
|
+
seedFns?: Record<string, {
|
|
89
|
+
params: string[];
|
|
90
|
+
body: Node;
|
|
91
|
+
async?: boolean;
|
|
92
|
+
}>;
|
|
93
|
+
maxDepth?: number;
|
|
94
|
+
};
|
|
95
|
+
/** 会话级依赖模块缓存条目:stat 指纹 + 导出 + 子树装载 issue。 */
|
|
96
|
+
type AbsModuleCacheEntry = {
|
|
97
|
+
mtimeMs: number;
|
|
98
|
+
size: number;
|
|
99
|
+
exports: AbsModuleExports;
|
|
100
|
+
/** 该模块子树首次求值时记录的 cycle/depth/missing;命中时重放。 */
|
|
101
|
+
issues: AbsModuleLoadIssue[];
|
|
102
|
+
};
|
|
103
|
+
/** 测试/诊断:当前条目数(≤ ABS_MODULE_CACHE_MAX) */
|
|
104
|
+
declare function getAbsModuleCacheSize(): number;
|
|
105
|
+
declare function clearAbsModuleCache(): void;
|
|
106
|
+
declare function evictAbsModuleCacheFiles(paths: string[]): void;
|
|
107
|
+
/**
|
|
108
|
+
* 递归求值相对依赖 + 裸包 harvest,产出入口可用的 modules 表。
|
|
109
|
+
* 循环依赖:先放空表再回填(与 TypeValue 路径 partial 口径一致),
|
|
110
|
+
* 并记录 cycle/depth/missing 供诊断。
|
|
111
|
+
*/
|
|
112
|
+
declare function evalAbsModuleGraph(entrySource: string, entryFile: string, opts?: AbsGraphOptions): AbsModuleGraphResult;
|
|
113
|
+
/**
|
|
114
|
+
* 收集顶层绑定名 → Abs(含相对 import / 裸包 harvest 注入)。
|
|
115
|
+
* 供 bindings / hover 从 Abs 投影,不必走 TypeValue evaluator。
|
|
116
|
+
*
|
|
117
|
+
* B-path fail-closed:绑定 = B run 绑定表($recordBinding:顶层 const/let,
|
|
118
|
+
* arrow/function 表达式经 $fnVal 已是 Abs fn)+ 导出表桥接(export
|
|
119
|
+
* function/const)+ import 本地名(模块图解析);B 失败 → 空 Map
|
|
120
|
+
* (显式无信息,不回落解释求值)。
|
|
121
|
+
*/
|
|
122
|
+
declare function collectAbsBindingsFromGraph(source: string, filePath: string, opts?: AbsGraphOptions): Map<string, Abs>;
|
|
123
|
+
|
|
124
|
+
/** @nudo:env → Abs 全局表(env 模块 Abs 原生) */
|
|
125
|
+
declare function collectEnvGlobals(envNames: string[]): Record<string, Abs>;
|
|
126
|
+
/** @nudo:env modules(path / node:path / fs…)→ AbsModuleExports */
|
|
127
|
+
declare function collectEnvModules(envNames: string[]): Record<string, AbsModuleExports>;
|
|
128
|
+
/** Conflict when handwritten env overwrote a harvest module/export (B8). */
|
|
129
|
+
type EnvHarvestConflict = {
|
|
130
|
+
module: string;
|
|
131
|
+
/** export names where env replaced a harvest binding (empty + defaulted = default only) */
|
|
132
|
+
exports: string[];
|
|
133
|
+
defaultOverwritten: boolean;
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* Install conflict collector; returns the previous one so nested/concurrent
|
|
137
|
+
* analyzeFile callers can save/restore (module-global is not re-entrant).
|
|
138
|
+
*/
|
|
139
|
+
declare function setEnvHarvestConflictCollector(collector: ((c: EnvHarvestConflict) => void) | null): ((c: EnvHarvestConflict) => void) | null;
|
|
140
|
+
/** Read-only peek for tests / nested restore. */
|
|
141
|
+
declare function getEnvHarvestConflictCollector(): ((c: EnvHarvestConflict) => void) | null;
|
|
142
|
+
type MergeHarvestOptions = {
|
|
143
|
+
/**
|
|
144
|
+
* Per-call conflict sink. Takes precedence over the module-global collector
|
|
145
|
+
* installed via `setEnvHarvestConflictCollector`.
|
|
146
|
+
*/
|
|
147
|
+
onConflict?: (c: EnvHarvestConflict) => void;
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* Handwritten `@nudojs/env` wins over harvest / graph modules on overlapping
|
|
151
|
+
* module keys and overlapping export names (docs/versioning.md B8 + website
|
|
152
|
+
* harvester API). Harvest-only modules/exports are kept as fill-in.
|
|
153
|
+
* Overwrites notify `opts.onConflict` or the global collector.
|
|
154
|
+
*/
|
|
155
|
+
declare function mergeHarvestUnderEnv(harvestModules: Record<string, AbsModuleExports>, envModules: Record<string, AbsModuleExports>, opts?: MergeHarvestOptions): Record<string, AbsModuleExports>;
|
|
156
|
+
/** 收集 @nudo:replace + @nudo:as → transpile 注入表 */
|
|
157
|
+
declare function collectBPathReplacements(source: string): {
|
|
158
|
+
targets: Array<{
|
|
159
|
+
target: string;
|
|
160
|
+
varName: string;
|
|
161
|
+
stmtStart?: number;
|
|
162
|
+
stmtEnd?: number;
|
|
163
|
+
}>;
|
|
164
|
+
values: Record<string, Abs>;
|
|
165
|
+
asTargets: Array<{
|
|
166
|
+
varName: string;
|
|
167
|
+
stmtStart: number;
|
|
168
|
+
stmtEnd: number;
|
|
169
|
+
}>;
|
|
170
|
+
asValues: Record<string, Abs>;
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 可走 transpile+exec 的快速预判(env 经 loadEnvs 内置 + 已 preload 的路径型)。
|
|
174
|
+
* 注意:正确性不依赖本函数——未 lowering 的构造在转译点 fail-closed
|
|
175
|
+
* (unknown / 空导出),tryRunTranspiled 捕获后记录;本函数仅是廉价前置闸。
|
|
176
|
+
* 顶层 this 已按 ESM 托管,不再关 B 路径。
|
|
177
|
+
*/
|
|
178
|
+
declare function isBPathCapable(source: string, envNames?: string[]): boolean;
|
|
179
|
+
type BPathRunResult = {
|
|
180
|
+
exports: Record<string, unknown>;
|
|
181
|
+
modules: Record<string, AbsModuleExports>;
|
|
182
|
+
/** 顶层执行期 method-missing */
|
|
183
|
+
memberDiags?: BMemberDiag[];
|
|
184
|
+
/** 模块图 cycle/depth/missing(B 权威) */
|
|
185
|
+
moduleIssues?: AbsModuleLoadIssue[];
|
|
186
|
+
/** Abs 求值递归截断的函数标签 */
|
|
187
|
+
truncatedFns?: string[];
|
|
188
|
+
/** 顶层 $callNamed 调用点(call@ 合成;不经 TypeValue collector) */
|
|
189
|
+
calls?: BCallRecord[];
|
|
190
|
+
};
|
|
191
|
+
declare function clearBPathCache(): void;
|
|
192
|
+
/** 测试/诊断:当前 B-path run 缓存条目数(≤ getSessionCacheLimits().maxBRuns) */
|
|
193
|
+
declare function getBPathCacheSize(): number;
|
|
194
|
+
/** 依赖文件变更后:逐出以这些文件为入口的 B-path 缓存 */
|
|
195
|
+
declare function evictBPathCacheForFiles(files: string[]): number;
|
|
196
|
+
/** 立刻压到当前 maxBRuns(调低上限时收内存) */
|
|
197
|
+
declare function trimBPathCache(): void;
|
|
198
|
+
/** 模块图 + runTranspiled(默认 analyze 模式) */
|
|
199
|
+
declare function tryRunBPath(source: string, filePath: string, opts?: {
|
|
200
|
+
maxLoopIters?: number;
|
|
201
|
+
mode?: "exec" | "analyze";
|
|
202
|
+
envNames?: string[];
|
|
203
|
+
/** @nudo:mock → Abs,注入为全局绑定(防止顶层调用真 fetch 等) */
|
|
204
|
+
mocks?: Record<string, Abs>;
|
|
205
|
+
/** 宽松全局(调用点发现 exec 采集) */
|
|
206
|
+
lenientGlobals?: boolean;
|
|
207
|
+
}): BPathRunResult | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* B 路径求值具名导出(结果 + throws);opts.collectCalls 时附带调用点记录。
|
|
210
|
+
*
|
|
211
|
+
* `calls` 只含**本次具名调用期间**(callTranspiledExportFull 内)发生的
|
|
212
|
+
* 调用点——不含模块级顶层调用(run.calls)。模块级记录由主分析流程
|
|
213
|
+
* 另行收集(analyzer 的 bTopCallRecords / absCallRecords);在此重复返回
|
|
214
|
+
* 会把 B 路径结果(常为 unknown)当第二组记录推给 analyzer,dedupe 因
|
|
215
|
+
* 结果形态不同而保留,污染被调函数的 case 列表(多余 call@L 重复 +
|
|
216
|
+
* call@symbolic 聚合 case,见 analyzer directive-case 分支)。
|
|
217
|
+
*/
|
|
218
|
+
declare function tryBPathCallFull(source: string, filePath: string, fnName: string, args: Abs[], opts?: {
|
|
219
|
+
collectCalls?: boolean;
|
|
220
|
+
collectMemberDiags?: boolean;
|
|
221
|
+
envNames?: string[];
|
|
222
|
+
mocks?: Record<string, Abs>;
|
|
223
|
+
/** 入口 Φ 种子(assume 约束——B 侧路径条件收窄) */
|
|
224
|
+
phi?: Phi;
|
|
225
|
+
}): (TranspiledCallResult & {
|
|
226
|
+
calls?: BCallRecord[];
|
|
227
|
+
memberDiags?: BMemberDiag[];
|
|
228
|
+
moduleIssues?: AbsModuleLoadIssue[];
|
|
229
|
+
truncatedFns?: string[];
|
|
230
|
+
}) | undefined;
|
|
231
|
+
/** B 路径求值具名导出(仅成功结果) */
|
|
232
|
+
declare function tryBPathCall(source: string, filePath: string, fnName: string, args: Abs[], opts?: {
|
|
233
|
+
envNames?: string[];
|
|
234
|
+
mocks?: Record<string, Abs>;
|
|
235
|
+
phi?: Phi;
|
|
236
|
+
}): Abs | undefined;
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* 分析范围判定(design-cli-semantics.md §7)。
|
|
240
|
+
* CLI 显式路径不受 mode 限制;本模块供 LSP/watch 自动验证使用。
|
|
241
|
+
*/
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* 按 analysis.diagnostics 档过滤 evaluator/check **显示路径**诊断。
|
|
245
|
+
* - off:显示层全静音(与 errors 档区分)。check 门禁(CLI `nudo check` /
|
|
246
|
+
* checkSource)独立于本过滤,不受 off 影响。
|
|
247
|
+
* - errors:只发 severity=error
|
|
248
|
+
* - default:error + warning(静音 NOISY_WARNING_CODES)
|
|
249
|
+
* - verbose:全量
|
|
250
|
+
*/
|
|
251
|
+
declare function filterDiagnosticsByLevel<T extends {
|
|
252
|
+
severity: string;
|
|
253
|
+
code?: string;
|
|
254
|
+
}>(diags: T[], level: DiagnosticsLevel): T[];
|
|
255
|
+
declare function diagnosticsLevelForFile(filePath: string): DiagnosticsLevel;
|
|
256
|
+
declare function hasNudoDirectives(source: string): boolean;
|
|
257
|
+
/**
|
|
258
|
+
* 是否应对该文件跑分析(自动路径,如 LSP validate)。
|
|
259
|
+
* - 非 target 路径 → false
|
|
260
|
+
* - exclude 命中 / include 未命中 → false
|
|
261
|
+
* - mode=directives → 仅有指令
|
|
262
|
+
* - mode=exports → 指令 | export | 同名侧车
|
|
263
|
+
* - mode=all → true
|
|
264
|
+
*/
|
|
265
|
+
declare function shouldAnalyzeFile(filePath: string, source: string | undefined, config?: AnalysisConfig): boolean;
|
|
266
|
+
|
|
267
|
+
export { type AbsGraphOptions as A, type BPathRunResult as B, setEnvHarvestConflictCollector as C, shouldAnalyzeFile as D, type EnvHarvestConflict as E, hasNudoDirectives as F, topoSortDirty as G, trimBPathCache as H, tryBPathCall as I, tryBPathCallFull as J, tryRunBPath as K, type MergeHarvestOptions as M, type AbsModuleCacheEntry as a, type AbsModuleGraphResult as b, type AbsModuleLoadIssue as c, type ModuleGraphCache as d, analyzeFile as e, analyzeFileAsync as f, buildModuleGraph as g, clearAbsModuleCache as h, clearBPathCache as i, collectAbsBindingsFromGraph as j, collectBPathReplacements as k, collectCallRecords as l, collectEnvGlobals as m, collectEnvModules as n, computeDirtySet as o, defaultAbsLoadModule as p, diagnosticsLevelForFile as q, evalAbsModuleGraph as r, evictAbsModuleCacheFiles as s, evictBPathCacheForFiles as t, filterDiagnosticsByLevel as u, getAbsModuleCacheSize as v, getBPathCacheSize as w, getEnvHarvestConflictCollector as x, isBPathCapable as y, mergeHarvestUnderEnv as z };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { a as AnalysisResult, B as BindingInfo, C as CaseHint, b as CaseResult, c as CompletionItem, d as Diagnostic, e as DiagnosticSeverity, f as DiagnosticTag, D as DirectiveCaseMode, F as FunctionAnalysis, R as ReferenceInfo, S as SourceLocation, g as SymbolInfo, h as SymbolTable } from './analyzer-types-JyJiCt8w.js';
|
|
2
|
+
export { A as AbsGraphOptions, a as AbsModuleCacheEntry, b as AbsModuleGraphResult, c as AbsModuleLoadIssue, B as BPathRunResult, d as ModuleGraphCache, e as analyzeFile, f as analyzeFileAsync, g as buildModuleGraph, h as clearAbsModuleCache, i as clearBPathCache, j as collectAbsBindingsFromGraph, l as collectCallRecords, o as computeDirtySet, p as defaultAbsLoadModule, q as diagnosticsLevelForFile, r as evalAbsModuleGraph, s as evictAbsModuleCacheFiles, t as evictBPathCacheForFiles, u as filterDiagnosticsByLevel, v as getAbsModuleCacheSize, w as getBPathCacheSize, y as isBPathCapable, D as shouldAnalyzeFile, F as sourceHasNudoDirectives, G as topoSortDirty, H as trimBPathCache, I as tryBPathCall, J as tryBPathCallFull, K as tryRunBPath } from './analysis-CSXrOVlg.js';
|
|
3
|
+
export { C as CallRecord } from './call-record-CkyCFkT9.js';
|
|
4
|
+
import '@babel/types';
|
|
5
|
+
import '@nudojs/core';
|
|
6
|
+
import '@nudojs/core/internal';
|
|
7
|
+
import './config-DDB588oA.js';
|
package/dist/analysis.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import {
|
|
2
|
+
diagnosticsLevelForFile,
|
|
3
|
+
filterDiagnosticsByLevel,
|
|
4
|
+
hasNudoDirectives,
|
|
5
|
+
shouldAnalyzeFile
|
|
6
|
+
} from "./chunk-LFZRUXGK.js";
|
|
7
|
+
import {
|
|
8
|
+
analyzeFile,
|
|
9
|
+
analyzeFileAsync,
|
|
10
|
+
buildModuleGraph,
|
|
11
|
+
clearAbsModuleCache,
|
|
12
|
+
clearBPathCache,
|
|
13
|
+
collectAbsBindingsFromGraph,
|
|
14
|
+
collectCallRecords,
|
|
15
|
+
computeDirtySet,
|
|
16
|
+
defaultAbsLoadModule,
|
|
17
|
+
evalAbsModuleGraph,
|
|
18
|
+
evictAbsModuleCacheFiles,
|
|
19
|
+
evictBPathCacheForFiles,
|
|
20
|
+
getAbsModuleCacheSize,
|
|
21
|
+
getBPathCacheSize,
|
|
22
|
+
isBPathCapable,
|
|
23
|
+
topoSortDirty,
|
|
24
|
+
trimBPathCache,
|
|
25
|
+
tryBPathCall,
|
|
26
|
+
tryBPathCallFull,
|
|
27
|
+
tryRunBPath
|
|
28
|
+
} from "./chunk-QAFMPM2E.js";
|
|
29
|
+
import "./chunk-U7JYTRIB.js";
|
|
30
|
+
import "./chunk-YLALZXTZ.js";
|
|
31
|
+
import "./chunk-PVJIMQRI.js";
|
|
32
|
+
export {
|
|
33
|
+
analyzeFile,
|
|
34
|
+
analyzeFileAsync,
|
|
35
|
+
buildModuleGraph,
|
|
36
|
+
clearAbsModuleCache,
|
|
37
|
+
clearBPathCache,
|
|
38
|
+
collectAbsBindingsFromGraph,
|
|
39
|
+
collectCallRecords,
|
|
40
|
+
computeDirtySet,
|
|
41
|
+
defaultAbsLoadModule,
|
|
42
|
+
diagnosticsLevelForFile,
|
|
43
|
+
evalAbsModuleGraph,
|
|
44
|
+
evictAbsModuleCacheFiles,
|
|
45
|
+
evictBPathCacheForFiles,
|
|
46
|
+
filterDiagnosticsByLevel,
|
|
47
|
+
getAbsModuleCacheSize,
|
|
48
|
+
getBPathCacheSize,
|
|
49
|
+
isBPathCapable,
|
|
50
|
+
shouldAnalyzeFile,
|
|
51
|
+
hasNudoDirectives as sourceHasNudoDirectives,
|
|
52
|
+
topoSortDirty,
|
|
53
|
+
trimBPathCache,
|
|
54
|
+
tryBPathCall,
|
|
55
|
+
tryBPathCallFull,
|
|
56
|
+
tryRunBPath
|
|
57
|
+
};
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { Node } from '@babel/types';
|
|
2
|
+
import { FormalParam, Abs } from '@nudojs/core';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* analyzer 共享类型(自 analyzer.ts god-file 机械拆出)。
|
|
6
|
+
* 只含类型,无运行时逻辑——供 module-load / diagnose / cache / orchestrate 共用。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type SourceLocation = {
|
|
10
|
+
start: {
|
|
11
|
+
line: number;
|
|
12
|
+
column: number;
|
|
13
|
+
};
|
|
14
|
+
end: {
|
|
15
|
+
line: number;
|
|
16
|
+
column: number;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
type DiagnosticSeverity = "error" | "warning" | "info";
|
|
20
|
+
type DiagnosticTag = "unnecessary";
|
|
21
|
+
type Diagnostic = {
|
|
22
|
+
range: SourceLocation;
|
|
23
|
+
severity: DiagnosticSeverity;
|
|
24
|
+
message: string;
|
|
25
|
+
tags?: DiagnosticTag[];
|
|
26
|
+
code?: string;
|
|
27
|
+
suggestions?: string[];
|
|
28
|
+
data?: unknown;
|
|
29
|
+
/** provenance of the receiver value (callsite argument that flowed into the error) */
|
|
30
|
+
origin?: {
|
|
31
|
+
line: number;
|
|
32
|
+
column: number;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
type CaseResult = {
|
|
36
|
+
name: string;
|
|
37
|
+
/** 无损参数 Abs */
|
|
38
|
+
argAbs: Abs[];
|
|
39
|
+
/** 无损结果 Abs */
|
|
40
|
+
abs: Abs;
|
|
41
|
+
/** 无损抛出 Abs(未抛为 never) */
|
|
42
|
+
throwsAbs: Abs;
|
|
43
|
+
throwLoc?: SourceLocation;
|
|
44
|
+
source?: "directive" | "callsite";
|
|
45
|
+
/** `@nudo:case "name" (…) => expected` — presence means the case is a test assertion */
|
|
46
|
+
expected?: Abs;
|
|
47
|
+
/** number of additional call sites folded into a symbolic case */
|
|
48
|
+
aggregatedFrom?: number;
|
|
49
|
+
/**
|
|
50
|
+
* 内涵摘要(代数 generalize):无损 Abs + term/pred/conf。
|
|
51
|
+
*/
|
|
52
|
+
intension?: {
|
|
53
|
+
display?: string;
|
|
54
|
+
term?: string;
|
|
55
|
+
pred?: string;
|
|
56
|
+
conf?: string;
|
|
57
|
+
/** 无损 Abs 单行(formatAbs) */
|
|
58
|
+
abs?: string;
|
|
59
|
+
/** 无损 Abs 多行(formatAbsMultiline) */
|
|
60
|
+
absMultiline?: string;
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
type FunctionAnalysis = {
|
|
64
|
+
name: string;
|
|
65
|
+
loc: SourceLocation;
|
|
66
|
+
paramNames: string[];
|
|
67
|
+
/** C4.1 形参表面:draft/契约对齐(解构 placeholder + bound 名) */
|
|
68
|
+
formals?: FormalParam[];
|
|
69
|
+
cases: CaseResult[];
|
|
70
|
+
/** cases 结果 Abs 的 join;dts 返回位源 */
|
|
71
|
+
combinedAbs?: Abs;
|
|
72
|
+
entryOnly?: boolean;
|
|
73
|
+
skipped?: boolean;
|
|
74
|
+
/**
|
|
75
|
+
* True for functions collected from CJS-style bindings/assignments
|
|
76
|
+
* (`exports.X = fn`, `module.exports = fn`, `const f = fn`): their name has
|
|
77
|
+
* no declaration-level stability, so .d.ts generation skips them while
|
|
78
|
+
* infer/JSON output still reports them.
|
|
79
|
+
*/
|
|
80
|
+
noDeclaration?: boolean;
|
|
81
|
+
/** absolute path of the module this function is imported from (externalFunctions only) */
|
|
82
|
+
fromModule?: string;
|
|
83
|
+
/**
|
|
84
|
+
* HOF / entry shape 关系快照(generalizeFromAst),供 dts 泛型投影(C3.3)。
|
|
85
|
+
* 只存投影所需的 Abs,不挂 PolyFn 本体(缓存可克隆)。
|
|
86
|
+
*/
|
|
87
|
+
hof?: {
|
|
88
|
+
/** 函数形参:外延关系 Abs(fn 形状,paramTypes/returnType) */
|
|
89
|
+
fnRels?: Array<{
|
|
90
|
+
param: string;
|
|
91
|
+
abs: Abs;
|
|
92
|
+
}>;
|
|
93
|
+
/** 值形参提升快照(如 items → arr(A1)) */
|
|
94
|
+
entryShapes?: Array<{
|
|
95
|
+
param: string;
|
|
96
|
+
abs: Abs;
|
|
97
|
+
}>;
|
|
98
|
+
/** 符号返回 Abs(含自由 α / B:param) */
|
|
99
|
+
symbolic?: Abs;
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
type BindingInfo = {
|
|
103
|
+
/** 无损 Abs */
|
|
104
|
+
abs: Abs;
|
|
105
|
+
loc?: SourceLocation;
|
|
106
|
+
};
|
|
107
|
+
type CaseHint = {
|
|
108
|
+
line: number;
|
|
109
|
+
label: string;
|
|
110
|
+
ok: boolean;
|
|
111
|
+
};
|
|
112
|
+
type AnalysisResult = {
|
|
113
|
+
functions: FunctionAnalysis[];
|
|
114
|
+
diagnostics: Diagnostic[];
|
|
115
|
+
bindings: Map<string, BindingInfo>;
|
|
116
|
+
/**
|
|
117
|
+
* Node identity is from the analysis-time parse. A later re-parse of the
|
|
118
|
+
* same source returns a *different* File (new Nodes) if the AST LRU evicted
|
|
119
|
+
* the original — lookups must use the File that produced this result, not a
|
|
120
|
+
* freshly parsed one. getTypeAtPosition rebuilds its own map and is unaffected.
|
|
121
|
+
*/
|
|
122
|
+
/** 无损节点 Abs */
|
|
123
|
+
nodeAbsMap: Map<Node, Abs>;
|
|
124
|
+
caseHints: CaseHint[];
|
|
125
|
+
/** functions imported from other modules, synthesized from cross-file call sites observed while analyzing this file */
|
|
126
|
+
externalFunctions?: FunctionAnalysis[];
|
|
127
|
+
};
|
|
128
|
+
type CompletionItem = {
|
|
129
|
+
label: string;
|
|
130
|
+
kind: "property" | "method" | "variable";
|
|
131
|
+
detail?: string;
|
|
132
|
+
};
|
|
133
|
+
type SymbolInfo = {
|
|
134
|
+
name: string;
|
|
135
|
+
kind: "function" | "variable" | "class" | "parameter";
|
|
136
|
+
loc: SourceLocation;
|
|
137
|
+
uri?: string;
|
|
138
|
+
};
|
|
139
|
+
type ReferenceInfo = {
|
|
140
|
+
name: string;
|
|
141
|
+
loc: SourceLocation;
|
|
142
|
+
uri?: string;
|
|
143
|
+
};
|
|
144
|
+
type SymbolTable = {
|
|
145
|
+
definitions: Map<string, SymbolInfo>;
|
|
146
|
+
references: ReferenceInfo[];
|
|
147
|
+
};
|
|
148
|
+
/** Optional module loader for analysis (sidecar / relative imports). */
|
|
149
|
+
type AnalyzeLoadModule = (spec: string, fromFile: string) => string | undefined;
|
|
150
|
+
/**
|
|
151
|
+
* `@nudo:case` 求值档:
|
|
152
|
+
* - `none`(默认):不跑 case;有 case 的函数也走 entry@ 出签名(check / IDE)
|
|
153
|
+
* - `all`:逐 case 真跑(`nudo test` / CaseJson / freeze)
|
|
154
|
+
* - `selected`:只跑 `activeCases` 选中的那条(LSP selectCase)
|
|
155
|
+
*/
|
|
156
|
+
type DirectiveCaseMode = "none" | "all" | "selected";
|
|
157
|
+
|
|
158
|
+
export type { AnalyzeLoadModule as A, BindingInfo as B, CaseHint as C, DirectiveCaseMode as D, FunctionAnalysis as F, ReferenceInfo as R, SourceLocation as S, AnalysisResult as a, CaseResult as b, CompletionItem as c, Diagnostic as d, DiagnosticSeverity as e, DiagnosticTag as f, SymbolInfo as g, SymbolTable as h };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Abs } from '@nudojs/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 调用点记录(CallRecord)。Abs 唯一真理源。
|
|
5
|
+
* argAbs/resultAbs/throwsAbs 必填;展示/外延在 CaseResult 边界再桥。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
type CallRecord = {
|
|
9
|
+
fnName: string;
|
|
10
|
+
/** 无损参数 Abs */
|
|
11
|
+
argAbs: Abs[];
|
|
12
|
+
/** 无损结果 Abs(threw 时为 never) */
|
|
13
|
+
resultAbs: Abs;
|
|
14
|
+
/** 无损抛出值 Abs(未抛为 never) */
|
|
15
|
+
throwsAbs: Abs;
|
|
16
|
+
/** Line-relative. Per-fn cache replay shifts this by lineDelta — if you
|
|
17
|
+
* add another position field (callee loc, arg loc), extend
|
|
18
|
+
* shiftCallRecordLines in analyzer.ts in the same change. */
|
|
19
|
+
callLoc?: {
|
|
20
|
+
line: number;
|
|
21
|
+
column: number;
|
|
22
|
+
};
|
|
23
|
+
targetModule?: string;
|
|
24
|
+
targetExport?: string;
|
|
25
|
+
/** export names the same function value was re-exported under after its
|
|
26
|
+
* defining module (barrel `index.js`, CJS forwarding shims); usage-site
|
|
27
|
+
* records stay name-matchable against them */
|
|
28
|
+
targetAliases?: string[];
|
|
29
|
+
/** module whose evaluation created the function value (definition site). */
|
|
30
|
+
fnModule?: string;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type { CallRecord as C };
|