@nudojs/core 1.2.0 → 1.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.
@@ -1,9 +1,56 @@
1
- import { I as InterfaceSource, a as InterfaceTierOpts, p as parseSource, C as CheckIssue } from './check-report-TEOZ4cPZ.js';
2
- export { L as LeakBudget, b as LoadDepsFingerprint, d as defaultLeakBudget, e as exceedsBudget, c as extractAllLoadSpecs, l as leakIfNeeded, f as loadModuleDepsFingerprint, m as maybeLeak, n as normPath, r as resetLeakCounter, g as resolveDepPath, s as sidecarSpecsOf, t as termDepth, h as termNodes } from './check-report-TEOZ4cPZ.js';
3
- import { A as Abs, T as Term, c as AstEnv } from './hof-types-COqDeD5F.js';
4
- export { $ as $tryDigestSoft, d as $tryMarkSoft, e as $tryReleaseSoft, E as ERROR_FAMILY, M as MayThrowEffect, f as errorTypeAbs, g as filterDeclaredThrows, h as filterGateThrows, i as filterIgnoredThrows, j as flushMayThrowEffects, k as formatThrowsAbs, l as getMayThrowCollector, m as isThrowsIgnored, n as mayThrowEffectsToAbs, o as orphanMayThrowEffects, p as popMayThrowFrame, q as pushMayThrowFrame, r as recordMayThrow, s as runWithMayThrowSession, t as setMayThrowCollector, u as throwAbsToKinds, v as throwsKindCovered } from './hof-types-COqDeD5F.js';
1
+ import { I as InterfaceSource, a as InterfaceTierOpts, p as parseSource, C as CheckIssue } from './check-report-BWmfy810.js';
2
+ export { L as LeakBudget, b as LoadDepsFingerprint, M as MAX_PROMISE_MICROS, d as defaultLeakBudget, e as exceedsBudget, c as extractAllLoadSpecs, g as getPromiseMicrosLength, l as leakIfNeeded, f as loadModuleDepsFingerprint, m as maybeLeak, n as normPath, r as resetLeakCounter, h as resolveDepPath, s as sidecarSpecsOf, t as termDepth, i as termNodes } from './check-report-BWmfy810.js';
3
+ import { A as Abs, T as Term, c as AstEnv } from './run-Dk08Q5zl.js';
4
+ export { $ as $tryDigestSoft, d as $tryMarkSoft, e as $tryReleaseSoft, E as ERROR_FAMILY, f as EvalFallbackStats, M as MayThrowEffect, g as enterEvalCallBudgetSession, h as errorTypeAbs, i as exitEvalCallBudgetSession, j as filterDeclaredThrows, k as filterGateThrows, l as filterIgnoredThrows, m as flushMayThrowEffects, n as formatThrowsAbs, o as getEvalCallBudgetState, p as getEvalFallbackStats, q as getMayThrowCollector, r as isThrowsIgnored, s as mayThrowEffectsToAbs, t as orphanMayThrowEffects, u as popMayThrowFrame, v as pushMayThrowFrame, w as recordMayThrow, x as resetEvalFallbackStats, y as runWithMayThrowSession, z as setMayThrowCollector, B as throwAbsToKinds, D as throwsKindCovered, F as withEvalBudgetOverride } from './run-Dk08Q5zl.js';
5
5
  import { File, Node } from '@babel/types';
6
6
 
7
+ /**
8
+ * 源码文本工具:注释/字符串/正则字面量剥离。
9
+ * 原文正则特性探测(require/import/exports 等)必须先剥再测——
10
+ * 字符串或注释里的同名片段不是代码。
11
+ *
12
+ * 扫描语义(单遍状态机):
13
+ * - 字符串/模板/注释互不串台(字符串里的 `//` 不是注释)。
14
+ * - 模板插值 `${…}` 是**代码岛**:内部按普通代码继续扫(可嵌套模板/字符串/
15
+ * 正则/注释),只把真正的字符串内容当 string——`${require()}` 里的 require
16
+ * 是真代码,必须可见;嵌套模板按深度配对,内外不串台。
17
+ * - 正则字面量按 division-vs-regex 启发式识别(前一有效 token 决定 `/`):
18
+ * `/https?:\/\//` 尾部 `//` 不会误开行注释;regex 体整体当 string 剥掉,
19
+ * 避免 `/import *from/` 误命中 import 探针。
20
+ * - 已知限制:`if (x) /re/` 这类 `)` 后紧跟 regex 的极端写法会当除法;
21
+ * 目标是探测器正确,不做完整 JS 词法。
22
+ */
23
+ type StringLiteralSpan = {
24
+ /** 引号内原文(转义未折叠;模块 specifier 无需折叠) */
25
+ value: string;
26
+ /** 开引号下标 */
27
+ start: number;
28
+ /** 含两侧引号的总长 */
29
+ length: number;
30
+ };
31
+ declare function stripCommentsAndStrings(source: string): string;
32
+ /**
33
+ * 只剥字符串/模板/正则,**保留注释原文**。
34
+ * `@nudo:` 指令合法住在 JSDoc/行注释里——指令存在性探针不能吃掉注释,
35
+ * 否则真指令被漏扫;同时字符串里的假指令文本必须不算命中。
36
+ * 模板插值 `${…}` 是代码,保留。
37
+ */
38
+ declare function stripStringsKeepComments(source: string): string;
39
+ /**
40
+ * 等长掩码:注释与字符串/模板/正则整段替换为空格(保留 `\n` 侧行号对齐)。
41
+ * 插值 `${…}` 的**代码**保留,定界符与 cooked 段变空格——下标与原文一一对应。
42
+ * 供定位/改写在**代码区**进行。
43
+ */
44
+ declare function maskCommentsAndStrings(source: string): string;
45
+ /** 代码区字符串/模板字面量(注释内引号不算;插值模板不报整体,正则不报) */
46
+ declare function scanStringLiterals(source: string): StringLiteralSpan[];
47
+ /** 真实 `require(` 调用(忽略字符串/注释/正则;模板插值内可见) */
48
+ declare function sourceHasRequireCall(source: string): boolean;
49
+ /** 真实 import / require 模块依赖(忽略字符串/注释/正则;模板插值内可见) */
50
+ declare function sourceHasModuleDependency(source: string): boolean;
51
+ /** 真实 CJS exports 赋值面(exports.x / exports[x] / module.x) */
52
+ declare function sourceHasCjsExports(source: string): boolean;
53
+
7
54
  /**
8
55
  * 调用预算 + 截断观测(求值引擎共享面)。
9
56
  * 抽象求值对递归做展开而非不动点:参数类型每层变形(fac(n-1))时
@@ -27,6 +74,15 @@ type AbsBudgetStats = {
27
74
  declare function getAbsCallBudgetStats(): AbsBudgetStats;
28
75
  /** 宿主入口(runTranspiled / callTranspiledExportFull / check)前重置 */
29
76
  declare function resetAbsCallBudget(): void;
77
+ /**
78
+ * 函数级预算覆盖(`@nudo:budget`):在 fn 期间抬高 depth/calls/forks 上限。
79
+ * 返回 restore 回调(恢复先前值)。非法值忽略对应维。
80
+ */
81
+ declare function withFnBudgetOverride(budget: {
82
+ depth?: number;
83
+ calls?: number;
84
+ forks?: number;
85
+ }, run: () => void): void;
30
86
  declare function stableCallId(obj: object): string;
31
87
  /**
32
88
  * 截断结果:分析无信息,conf=opaque。
@@ -72,6 +128,10 @@ declare const FORK_TRUNCATION_LABEL = "#fork-budget";
72
128
  * `nudo:host-effect-blocked`,不复用「某函数被截断」文案。
73
129
  */
74
130
  declare const HOST_EFFECT_LABEL_PREFIX = "#host-effect:";
131
+ /** promise 微队列溢出标签(队列硬上限丢弃;check 映射,避免误报 recursion-truncated) */
132
+ declare const PROMISE_MICRO_OVERFLOW_LABEL = "#promise-micro-overflow";
133
+ /** promise 微任务 drain 抛错标签(不得静默吞掉) */
134
+ declare const PROMISE_MICRO_ERROR_LABEL = "#promise-micro-error";
75
135
  /** 宿主副作用未执行观测(service/LSP 映射 nudo:host-effect-blocked;与调用截断同 collector 管道) */
76
136
  declare function noteHostEffectBlocked(name: string): void;
77
137
  /** fork 超限观测(service/LSP 映射 nudo:fork-truncated;与调用截断同 collector 管道) */
@@ -304,13 +364,24 @@ declare function fixedLengthOfViews(views: TemplatePartView[]): number | undefin
304
364
  declare function formatTemplateNameViews(views: TemplatePartView[]): string;
305
365
  /** 相邻固定文本合并;rebuildFixed 以合并文本重建视图(含原始 part) */
306
366
  declare function mergeAdjacentFixedViews<P>(views: TemplatePartView<P>[], rebuildFixed: (text: string) => TemplatePartView<P>): TemplatePartView<P>[];
307
- /** 具体字符串是否匹配模板(Refinement.check 的判定语义) */
367
+ /**
368
+ * 具体字符串是否匹配模板(Refinement.check 的判定语义)。
369
+ * 抽象 part 吃掉任意(含空)子串;相邻抽象合并成一段可变间隙。
370
+ * 非末尾固定段从当前位置向后找;末尾固定段须落在字符串末尾
371
+ * (`${x}abc` 匹配 "abcabc",x="abc")。
372
+ * (pos, si) 记忆化:多间隙长串下否则为 O(n^k) 指数回溯。
373
+ */
308
374
  declare function templateMatchesValue(value: string, views: TemplatePartView[]): boolean;
309
375
  /** 三值判定;Abs 方法表把 "unknown" 适配为 boolPrim */
310
376
  type TemplatePredicateDecision = boolean | "unknown";
311
377
  declare function decideStartsWith(prefix: string, search: string): TemplatePredicateDecision;
312
378
  declare function decideEndsWith(suffix: string, search: string): TemplatePredicateDecision;
313
- declare function decideIncludes(fixedText: string, search: string): TemplatePredicateDecision;
379
+ /**
380
+ * includes 判定:search 必须落在**单个**固定段内才是 true。
381
+ * 跨抽象间隙拼接固定段会假精确(`a${x}b` 的固定文本 "ab" 并不蕴含
382
+ * includes("ab")——x="zz" 时 "azzb" 不含 "ab")。无固定段命中 → unknown。
383
+ */
384
+ declare function decideIncludes(fixedRuns: readonly string[], search: string): TemplatePredicateDecision;
314
385
  declare function absTemplateViews(parts: Abs[]): TemplatePartView<Abs>[];
315
386
  /** 从 Abs 提取 template parts(已是 template 则展开,否则 [self]) */
316
387
  declare function templatePartsOf(a: Abs): Abs[];
@@ -335,6 +406,39 @@ declare function concatString(a: Abs, b: Abs): Abs;
335
406
  /** Abs 上的运行时守卫表达式(JS boolean 布尔串) */
336
407
  declare function denoteGuard(a: Abs, v: string): string;
337
408
 
409
+ /**
410
+ * Codegen escaping: one policy for embedding user-controlled strings into
411
+ * generated JS/TS/comments (guard bodies, .d.ts types, schema modules, JSDoc).
412
+ *
413
+ * - object keys: bare JS ident or canonical integer, else JSON-quoted
414
+ * - member access: `recv.key` for idents, `recv["key"]` otherwise
415
+ * - template literal type fixed segments: escape `\` `` ` `` `$`
416
+ * - comment bodies: neutralize block-comment close, line breaks, control chars
417
+ */
418
+ declare function isJsIdent(name: string): boolean;
419
+ /**
420
+ * Object-literal / type-member key: bare ident or canonical integer,
421
+ * otherwise JSON-quoted. Leading-zero digit keys (`01`) stay quoted — bare
422
+ * `01` is a SyntaxError in modules/TS.
423
+ */
424
+ declare function formatObjectKey(k: string): string;
425
+ /**
426
+ * Member-access expression: `recv.key` for idents, `recv["key"]` otherwise.
427
+ * Bare non-ident keys inject operators (`foo||true||bar`) or SyntaxError.
428
+ */
429
+ declare function safeMemberAccess(recv: string, key: string): string;
430
+ /**
431
+ * Escape a fixed text segment for a TypeScript template literal type.
432
+ * Escapes `\`, `` ` ``, and `$` so `${` cannot open a type interpolation.
433
+ */
434
+ declare function escapeTemplateTypeFixed(text: string): string;
435
+ /**
436
+ * Sanitize text destined for a generated comment body (JSDoc `* ` or `//`).
437
+ * Neutralizes the block-comment close sequence, line breaks (U+2028/2029
438
+ * included), and control characters so the comment cannot be broken out of.
439
+ */
440
+ declare function sanitizeCommentText(text: string): string;
441
+
338
442
  /**
339
443
  * 语言覆盖:class / new / instanceof / this / async await。
340
444
  * brand 表示名义类;eff("promise") 表示异步效应。
@@ -547,4 +651,4 @@ declare function runWithEvalMissingSlot<T>(enabled: boolean, body: () => T): T;
547
651
  */
548
652
  declare function noteObjSlotMissing(recv: Abs | undefined, name: string, loc?: [number, number]): boolean;
549
653
 
550
- export { type AbsBudgetStats, type AbsInlay, type ArgDerivation, type ClassDef, type CollectAbsInlaysOpts, type DerivationNode, type EvalMemberDiag, FORK_TRUNCATION_LABEL, type FnFp, HOST_EFFECT_LABEL_PREFIX, type InjectedDomainEvidenceOpts, type InjectedDomainRecord, MAX_CALL_DEPTH, MAX_EVAL_TOTAL_FORKS, MAX_TOTAL_CALLS, type MethodDef, OBJECT_PROTO_NAMES, type TemplateMeta, type TemplatePartDesc, type TemplatePartView, type TemplatePredicateDecision, abortDerivationSession, absTemplateViews, allFixedTextOfViews, anyMemberResult, awaitAbs, beginDerivationSession, bumpEvalForkBudget, callBudgetKey, canSkipLiteralCallScan, checkInjectedDomainEvidence, classChainNames, classFromMethods, coerceAsyncReturn, collectAbsInlays, concatString, createTemplateAbs, decideEndsWith, decideIncludes, decideStartsWith, defineClass, definitelyUncallableMember, denoteGuard, derivationChain, endDerivationSession, enterCall, exitCall, fixedLengthOfViews, fnFingerprints, formatTemplateNameViews, generalizeSourceKeyPart, getAbsCallBudgetStats, getAbsOrigin, getClass, getClassChain, getDerivation, getEvalForkBudgetLimit, getEvalForkCount, getFnNameAndBodies, hasDerivationSession, hashSource, instanceOf, instantiateClass, isEvalMissingSlotEnabled, isNullishAbs, isTemplateLike, knownPrefixOfViews, knownSuffixOfViews, listTopFunctions, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, mergeAdjacentFixedViews, noteAbsTruncation, noteAnyMemberMayThrow, noteDerivationAdd, noteDerivationJoin, noteEvalForkTruncation, noteHostEffectBlocked, noteMemberDispatchMiss, noteNullishMemberThrows, noteObjSlotMissing, notePrimMemberMissing, noteUnknownMemberMissing, popCallLoc, projectBrand, projectDerivationDsl, pushCallLoc, recordMemberDiag, resetAbsCallBudget, resetEvalForkBudget, resetFnFpCache, resetHashSourceCache, runWithEvalMissingSlot, setAbsTruncationCollector, setDerivation, setDerivationCollector, setEvalForkBudgetLimit, setEvalMissingSlotEnabled, setMemberDiagCollector, stableAnalyzeKeySource, stableCallId, superNameOf, tagAbsOrigin, tagDerivationRoot, templateMatchesValue, templatePartsOf, termKey, truncatedAbs, viewTemplateParts, wrapPromise };
654
+ export { type AbsBudgetStats, type AbsInlay, type ArgDerivation, type ClassDef, type CollectAbsInlaysOpts, type DerivationNode, type EvalMemberDiag, FORK_TRUNCATION_LABEL, type FnFp, HOST_EFFECT_LABEL_PREFIX, type InjectedDomainEvidenceOpts, type InjectedDomainRecord, MAX_CALL_DEPTH, MAX_EVAL_TOTAL_FORKS, MAX_TOTAL_CALLS, type MethodDef, OBJECT_PROTO_NAMES, PROMISE_MICRO_ERROR_LABEL, PROMISE_MICRO_OVERFLOW_LABEL, type StringLiteralSpan, type TemplateMeta, type TemplatePartDesc, type TemplatePartView, type TemplatePredicateDecision, abortDerivationSession, absTemplateViews, allFixedTextOfViews, anyMemberResult, awaitAbs, beginDerivationSession, bumpEvalForkBudget, callBudgetKey, canSkipLiteralCallScan, checkInjectedDomainEvidence, classChainNames, classFromMethods, coerceAsyncReturn, collectAbsInlays, concatString, createTemplateAbs, decideEndsWith, decideIncludes, decideStartsWith, defineClass, definitelyUncallableMember, denoteGuard, derivationChain, endDerivationSession, enterCall, escapeTemplateTypeFixed, exitCall, fixedLengthOfViews, fnFingerprints, formatObjectKey, formatTemplateNameViews, generalizeSourceKeyPart, getAbsCallBudgetStats, getAbsOrigin, getClass, getClassChain, getDerivation, getEvalForkBudgetLimit, getEvalForkCount, getFnNameAndBodies, hasDerivationSession, hashSource, instanceOf, instantiateClass, isEvalMissingSlotEnabled, isJsIdent, isNullishAbs, isTemplateLike, knownPrefixOfViews, knownSuffixOfViews, listTopFunctions, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, maskCommentsAndStrings, mergeAdjacentFixedViews, noteAbsTruncation, noteAnyMemberMayThrow, noteDerivationAdd, noteDerivationJoin, noteEvalForkTruncation, noteHostEffectBlocked, noteMemberDispatchMiss, noteNullishMemberThrows, noteObjSlotMissing, notePrimMemberMissing, noteUnknownMemberMissing, popCallLoc, projectBrand, projectDerivationDsl, pushCallLoc, recordMemberDiag, resetAbsCallBudget, resetEvalForkBudget, resetFnFpCache, resetHashSourceCache, runWithEvalMissingSlot, safeMemberAccess, sanitizeCommentText, scanStringLiterals, setAbsTruncationCollector, setDerivation, setDerivationCollector, setEvalForkBudgetLimit, setEvalMissingSlotEnabled, setMemberDiagCollector, sourceHasCjsExports, sourceHasModuleDependency, sourceHasRequireCall, stableAnalyzeKeySource, stableCallId, stripCommentsAndStrings, stripStringsKeepComments, superNameOf, tagAbsOrigin, tagDerivationRoot, templateMatchesValue, templatePartsOf, termKey, truncatedAbs, viewTemplateParts, withFnBudgetOverride, wrapPromise };
package/dist/internal.js CHANGED
@@ -16,7 +16,7 @@ import {
16
16
  resolveDepPath,
17
17
  sidecarSpecsOf,
18
18
  stableAnalyzeKeySource
19
- } from "./chunk-GD5XIQQK.js";
19
+ } from "./chunk-5YNR4Q7E.js";
20
20
  import {
21
21
  $tryDigestSoft,
22
22
  $tryMarkSoft,
@@ -26,8 +26,11 @@ import {
26
26
  HOST_EFFECT_LABEL_PREFIX,
27
27
  MAX_CALL_DEPTH,
28
28
  MAX_EVAL_TOTAL_FORKS,
29
+ MAX_PROMISE_MICROS,
29
30
  MAX_TOTAL_CALLS,
30
31
  OBJECT_PROTO_NAMES,
32
+ PROMISE_MICRO_ERROR_LABEL,
33
+ PROMISE_MICRO_OVERFLOW_LABEL,
31
34
  abortDerivationSession,
32
35
  absTemplateViews,
33
36
  allFixedTextOfViews,
@@ -50,9 +53,11 @@ import {
50
53
  derivationChain,
51
54
  endDerivationSession,
52
55
  enterCall,
56
+ enterEvalCallBudgetSession,
53
57
  errorTypeAbs,
54
58
  exceedsBudget,
55
59
  exitCall,
60
+ exitEvalCallBudgetSession,
56
61
  filterDeclaredThrows,
57
62
  filterGateThrows,
58
63
  filterIgnoredThrows,
@@ -66,9 +71,12 @@ import {
66
71
  getClass,
67
72
  getClassChain,
68
73
  getDerivation,
74
+ getEvalCallBudgetState,
75
+ getEvalFallbackStats,
69
76
  getEvalForkBudgetLimit,
70
77
  getEvalForkCount,
71
78
  getMayThrowCollector,
79
+ getPromiseMicrosLength,
72
80
  hasDerivationSession,
73
81
  instanceOf,
74
82
  instantiateClass,
@@ -83,6 +91,7 @@ import {
83
91
  lookupMethod,
84
92
  lookupMethodWithOwner,
85
93
  lookupSuperMethod,
94
+ maskCommentsAndStrings,
86
95
  mayThrowEffectsToAbs,
87
96
  maybeLeak,
88
97
  mergeAdjacentFixedViews,
@@ -109,10 +118,12 @@ import {
109
118
  recordMayThrow,
110
119
  recordMemberDiag,
111
120
  resetAbsCallBudget,
121
+ resetEvalFallbackStats,
112
122
  resetEvalForkBudget,
113
123
  resetLeakCounter,
114
124
  runWithEvalMissingSlot,
115
125
  runWithMayThrowSession,
126
+ scanStringLiterals,
116
127
  setAbsTruncationCollector,
117
128
  setDerivation,
118
129
  setDerivationCollector,
@@ -120,7 +131,12 @@ import {
120
131
  setEvalMissingSlotEnabled,
121
132
  setMayThrowCollector,
122
133
  setMemberDiagCollector,
134
+ sourceHasCjsExports,
135
+ sourceHasModuleDependency,
136
+ sourceHasRequireCall,
123
137
  stableCallId,
138
+ stripCommentsAndStrings,
139
+ stripStringsKeepComments,
124
140
  superNameOf,
125
141
  tagAbsOrigin,
126
142
  tagDerivationRoot,
@@ -134,8 +150,10 @@ import {
134
150
  throwsKindCovered,
135
151
  truncatedAbs,
136
152
  viewTemplateParts,
153
+ withEvalBudgetOverride,
154
+ withFnBudgetOverride,
137
155
  wrapPromise
138
- } from "./chunk-WB565PQK.js";
156
+ } from "./chunk-CKH6GQAI.js";
139
157
 
140
158
  // src/algebra/inlay.ts
141
159
  function listFunctions(source) {
@@ -286,6 +304,27 @@ function collectAbsInlays(source, opts) {
286
304
  return inlays;
287
305
  }
288
306
 
307
+ // src/algebra/codegen-escape.ts
308
+ var JS_IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
309
+ var JS_CANONICAL_INT = /^(?:0|[1-9]\d*)$/;
310
+ function isJsIdent(name) {
311
+ return JS_IDENT.test(name);
312
+ }
313
+ function formatObjectKey(k) {
314
+ if (JS_IDENT.test(k)) return k;
315
+ if (JS_CANONICAL_INT.test(k)) return k;
316
+ return JSON.stringify(k);
317
+ }
318
+ function safeMemberAccess(recv, key) {
319
+ return JS_IDENT.test(key) ? `${recv}.${key}` : `${recv}[${JSON.stringify(key)}]`;
320
+ }
321
+ function escapeTemplateTypeFixed(text) {
322
+ return text.replace(/[\\`$]/g, "\\$&");
323
+ }
324
+ function sanitizeCommentText(text) {
325
+ return text.replace(/\*\//g, "*\\/").replace(/[\r\n\u2028\u2029\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, " ");
326
+ }
327
+
289
328
  // src/algebra/denote.ts
290
329
  function denoteGuard(a, v) {
291
330
  const lv = litValue(a);
@@ -323,7 +362,7 @@ function denoteShape(s, v) {
323
362
  case "obj": {
324
363
  const checks = [`typeof ${v} === "object"`, `${v} !== null`];
325
364
  for (const [key, slot] of Object.entries(s.slots)) {
326
- const access = `${v}.${key}`;
365
+ const access = safeMemberAccess(v, key);
327
366
  const inner = denoteGuard(slot.value, access);
328
367
  if (slot.optional) {
329
368
  if (inner !== "true") checks.push(`(${access} === undefined || ${inner})`);
@@ -463,8 +502,11 @@ export {
463
502
  HOST_EFFECT_LABEL_PREFIX,
464
503
  MAX_CALL_DEPTH,
465
504
  MAX_EVAL_TOTAL_FORKS,
505
+ MAX_PROMISE_MICROS,
466
506
  MAX_TOTAL_CALLS,
467
507
  OBJECT_PROTO_NAMES,
508
+ PROMISE_MICRO_ERROR_LABEL,
509
+ PROMISE_MICRO_OVERFLOW_LABEL,
468
510
  abortDerivationSession,
469
511
  absTemplateViews,
470
512
  allFixedTextOfViews,
@@ -491,9 +533,12 @@ export {
491
533
  derivationChain,
492
534
  endDerivationSession,
493
535
  enterCall,
536
+ enterEvalCallBudgetSession,
494
537
  errorTypeAbs,
538
+ escapeTemplateTypeFixed,
495
539
  exceedsBudget,
496
540
  exitCall,
541
+ exitEvalCallBudgetSession,
497
542
  extractAllLoadSpecs,
498
543
  filterDeclaredThrows,
499
544
  filterGateThrows,
@@ -501,6 +546,7 @@ export {
501
546
  fixedLengthOfViews,
502
547
  flushMayThrowEffects,
503
548
  fnFingerprints,
549
+ formatObjectKey,
504
550
  formatTemplateNameViews,
505
551
  formatThrowsAbs,
506
552
  generalizeSourceKeyPart,
@@ -509,15 +555,19 @@ export {
509
555
  getClass,
510
556
  getClassChain,
511
557
  getDerivation,
558
+ getEvalCallBudgetState,
559
+ getEvalFallbackStats,
512
560
  getEvalForkBudgetLimit,
513
561
  getEvalForkCount,
514
562
  getFnNameAndBodies,
515
563
  getMayThrowCollector,
564
+ getPromiseMicrosLength,
516
565
  hasDerivationSession,
517
566
  hashSource,
518
567
  instanceOf,
519
568
  instantiateClass,
520
569
  isEvalMissingSlotEnabled,
570
+ isJsIdent,
521
571
  isNullishAbs,
522
572
  isTemplateLike,
523
573
  isThrowsIgnored,
@@ -529,6 +579,7 @@ export {
529
579
  lookupMethod,
530
580
  lookupMethodWithOwner,
531
581
  lookupSuperMethod,
582
+ maskCommentsAndStrings,
532
583
  mayThrowEffectsToAbs,
533
584
  maybeLeak,
534
585
  mergeAdjacentFixedViews,
@@ -554,6 +605,7 @@ export {
554
605
  recordMayThrow,
555
606
  recordMemberDiag,
556
607
  resetAbsCallBudget,
608
+ resetEvalFallbackStats,
557
609
  resetEvalForkBudget,
558
610
  resetFnFpCache,
559
611
  resetHashSourceCache,
@@ -561,6 +613,9 @@ export {
561
613
  resolveDepPath,
562
614
  runWithEvalMissingSlot,
563
615
  runWithMayThrowSession,
616
+ safeMemberAccess,
617
+ sanitizeCommentText,
618
+ scanStringLiterals,
564
619
  setAbsTruncationCollector,
565
620
  setDerivation,
566
621
  setDerivationCollector,
@@ -569,8 +624,13 @@ export {
569
624
  setMayThrowCollector,
570
625
  setMemberDiagCollector,
571
626
  sidecarSpecsOf,
627
+ sourceHasCjsExports,
628
+ sourceHasModuleDependency,
629
+ sourceHasRequireCall,
572
630
  stableAnalyzeKeySource,
573
631
  stableCallId,
632
+ stripCommentsAndStrings,
633
+ stripStringsKeepComments,
574
634
  superNameOf,
575
635
  tagAbsOrigin,
576
636
  tagDerivationRoot,
@@ -583,5 +643,7 @@ export {
583
643
  throwsKindCovered,
584
644
  truncatedAbs,
585
645
  viewTemplateParts,
646
+ withEvalBudgetOverride,
647
+ withFnBudgetOverride,
586
648
  wrapPromise
587
649
  };
@@ -1,4 +1,5 @@
1
- import { Node } from '@babel/types';
1
+ import * as _babel_types from '@babel/types';
2
+ import { Node, ImportDeclaration, File } from '@babel/types';
2
3
 
3
4
  /** 项(Term):抽象值的身份。字面量是项的特例。 */
4
5
  type LiteralValue = string | number | boolean | null | undefined;
@@ -71,6 +72,16 @@ type Pred = {
71
72
  op: "typeof";
72
73
  t: Term;
73
74
  type: TypeofName;
75
+ }
76
+ /**
77
+ * 显式有限证据:t 是有限数(非 NaN/±Inf)。
78
+ * 在场时允许线性环化简(x-x=0、k*(x+y) 分配等);
79
+ * 默认关闭——无此谓词(或由 typeof=number + 双侧有限界自动导出)时
80
+ * 仍 fail-closed,与 BUG-001 / DEC-007A 口径一致。
81
+ */
82
+ | {
83
+ op: "assumeFinite";
84
+ t: Term;
74
85
  };
75
86
  declare const pTrue: Pred;
76
87
  declare const pFalse: Pred;
@@ -81,6 +92,8 @@ declare const le: (a: Term, b: Term) => Pred;
81
92
  declare const gt: (a: Term, b: Term) => Pred;
82
93
  declare const ge: (a: Term, b: Term) => Pred;
83
94
  declare const ptypeof: (t: Term, type: TypeofName) => Pred;
95
+ /** 显式有限证据:t 为有限数(非 NaN/±Inf),开启线性环化简 */
96
+ declare const assumeFinite: (t: Term) => Pred;
84
97
  declare function and(...preds: Pred[]): Pred;
85
98
  declare function or(...preds: Pred[]): Pred;
86
99
  declare function not(p: Pred): Pred;
@@ -88,6 +101,11 @@ declare function not(p: Pred): Pred;
88
101
  * 逻辑否定(De Morgan):¬(A∧B)=¬A∨¬B;¬(A∨B)=¬A∧¬B;双重否定消去。
89
102
  * typeof 否定展开为其余 TypeofName 标签的析取——8 标签域是 JS typeof 的
90
103
  * 完整结果域,展开健全且相对完备。
104
+ *
105
+ * 关系比较(lt/le/gt/ge)的否定 **不是** 全序对偶:JS 里 NaN 参与时
106
+ * 全部关系为 false,故 ¬(x<5) 真而 x≥5 假。精确否定是 not(lt);
107
+ * 正向全序事实(Φ ⊢ x≥5 ⇒ x<5 为假)仍由 totalOrderDual 处理。
108
+ * eq↔ne 是精确否定,不受 NaN 影响。
91
109
  */
92
110
  declare function negatePred(p: Pred): Pred;
93
111
  declare function predEquals(a: Pred, b: Pred): boolean;
@@ -162,6 +180,15 @@ type Shape = {
162
180
  name?: string;
163
181
  paramTypes?: Abs[];
164
182
  returnType?: Abs;
183
+ /**
184
+ * Dual-facet globals (Number/Array/…): callable AND carries static members.
185
+ * `$get` reads these before falling back to Function.prototype names.
186
+ */
187
+ slots?: Record<string, {
188
+ value: Abs;
189
+ optional?: boolean;
190
+ readonly?: boolean;
191
+ }>;
165
192
  } | {
166
193
  k: "brand";
167
194
  name: string;
@@ -294,6 +321,77 @@ declare function filterIgnoredThrows(effects: MayThrowEffect[], ignore: readonly
294
321
  */
295
322
  declare function filterDeclaredThrows(effects: MayThrowEffect[], declared: readonly string[] | "*" | undefined): MayThrowEffect[];
296
323
 
324
+ /**
325
+ * 求值引擎调用点记录:transpile 把 `f(args)` 改成 $callNamed,
326
+ * 分析时可收集 call@ 所需的 AbsCallRecord。
327
+ * 成员缺失诊断见 member-diag.ts(共用,避免循环依赖)。
328
+ */
329
+
330
+ type EvalCallRecord = {
331
+ fnName: string;
332
+ args: Abs[];
333
+ result: Abs;
334
+ callLoc?: {
335
+ line: number;
336
+ column: number;
337
+ };
338
+ threw?: boolean;
339
+ };
340
+ /** B 赋值记录(与 ast-records.ts AbsAssignRecord 同形;structuralAssignIssues 消费) */
341
+ type EvalAbsAssignRecord = {
342
+ name: string;
343
+ prev: Abs | undefined;
344
+ next: Abs;
345
+ line?: number;
346
+ column?: number;
347
+ conditional?: boolean;
348
+ };
349
+ /** 返回先前 collector,便于嵌套调用 save/restore(禁止 finally 置 null 砸外层) */
350
+ declare function setEvalAssignCollector(collector: ((r: EvalAbsAssignRecord) => void) | null): ((r: EvalAbsAssignRecord) => void) | null;
351
+ /** 结构赋值记录(transpile 插桩调用;无收集器时 no-op) */
352
+ declare function $assignRecord(name: string, prev: Abs | undefined, next: Abs, line: number, column: number, conditional: boolean): void;
353
+ declare function setEvalBindingSink(sink: Map<string, unknown> | null): void;
354
+ /** 顶层绑定记录(transpile 插桩调用) */
355
+ declare function $recordBinding(name: string, value: unknown): void;
356
+ /** 返回先前 collector,便于嵌套调用 save/restore(禁止 finally 置 null 砸外层) */
357
+ /** 成员/方法调用点打点($invoke 等;无收集器时 no-op)。不进 $callNamed 预算。 */
358
+ declare function noteEvalCallRecord(r: EvalCallRecord): void;
359
+ declare function setEvalCallCollector(collector: ((r: EvalCallRecord) => void) | null): ((r: EvalCallRecord) => void) | null;
360
+ declare function getEvalCallCollector(): ((r: EvalCallRecord) => void) | null;
361
+ /**
362
+ * 按名调用并记录。
363
+ * loc: [line, column](1-based line,0-based column,与 Babel 一致)
364
+ * argLocs: 与 args 对齐的实参字面量源位置(provenance;无 loc 用 null)
365
+ */
366
+ declare const MAX_EVAL_CALL_DEPTH = 64;
367
+ /** 总调用上限:与 call-budget.MAX_TOTAL_CALLS 同阀(递归×循环×分支展开的
368
+ * 规模阀)。200k 在病态展开(lodash _baseFlatten)下 ~30s,20k 收口到
369
+ * ~3s——截断 → opaque(更保守,zero-FP 安全)。 */
370
+ declare const MAX_EVAL_TOTAL_CALLS = 20000;
371
+ /** 宿主入口前强制清零(测试 / 显式 API)。执行入口请用 enterEvalCallBudgetSession。 */
372
+ declare function resetEvalCallBudget(): void;
373
+ /** @nudo:budget:在 run 期间抬高 B 路径 depth/calls 上限;finally 恢复 */
374
+ declare function withEvalBudgetOverride(budget: {
375
+ depth?: number;
376
+ calls?: number;
377
+ }, run: () => void): void;
378
+ /**
379
+ * 进入执行会话。最外层才重置预算;嵌套(导出桥 $call → apply →
380
+ * callTranspiledExportFull)必须继承外层深度/cycle 键/totalCalls,否则
381
+ * 外层帧被抹掉,$callNamed 的 evalExitCall 再把 depth 打成负数。
382
+ */
383
+ declare function enterEvalCallBudgetSession(): void;
384
+ /** 退出执行会话。禁止把 sessionDepth 留在负数。 */
385
+ declare function exitEvalCallBudgetSession(): void;
386
+ /** 预算快照(测试/诊断:断言嵌套期间 depth/keys 不被清空、depth 不为负) */
387
+ declare function getEvalCallBudgetState(): {
388
+ depth: number;
389
+ totalCalls: number;
390
+ activeKeys: number;
391
+ sessionDepth: number;
392
+ };
393
+ declare function $callNamed(name: string, fn: unknown, args: Abs[], loc?: [number, number], argLocs?: Array<[number, number] | null | undefined>): Abs;
394
+
297
395
  /**
298
396
  * 共享纯类型结点(AstEnv / HofCollectCtx / HofSite / RelSource)。
299
397
  *
@@ -365,4 +463,124 @@ type AstEnv = {
365
463
  hofCollect?: HofCollectCtx;
366
464
  };
367
465
 
368
- export { $tryDigestSoft as $, type Abs as A, absToString as B, type Confidence as C, and as D, ERROR_FAMILY as E, anyAbs as F, anyVar as G, type HofCollectCtx as H, type ImplicationOracle as I, app as J, bigintLit as K, type LiteralValue as L, type MayThrowEffect as M, bool as N, boolLit as O, type PrimName as P, confJoin as Q, type RelSource as R, type Shape as S, type Term as T, emptyPhi as U, eq as V, ge as W, geNum as X, getImplicationOracle as Y, gt as Z, gtNum as _, type Pred as a, implies as a0, isBigPrim as a1, isExactLit as a2, isNumPrim as a3, isStrPrim as a4, le as a5, leNum as a6, lit as a7, litValue as a8, lt as a9, termToString as aA, unknown as aB, v as aC, ltNum as aa, ne as ab, negatePred as ac, never as ad, not as ae, num as af, numLit as ag, numVar as ah, obj as ai, or as aj, pFalse as ak, pTrue as al, phiAnd as am, predEquals as an, predToString as ao, predVars as ap, primToTypeof as aq, ptypeof as ar, setImplicationOracle as as, shapeOfTerm as at, shapeToString as au, simplifyTerm as av, str as aw, strLit as ax, substPred as ay, termEquals as az, type Phi as b, type AstEnv as c, $tryMarkSoft as d, $tryReleaseSoft as e, errorTypeAbs as f, filterDeclaredThrows as g, filterGateThrows as h, filterIgnoredThrows as i, flushMayThrowEffects as j, formatThrowsAbs as k, getMayThrowCollector as l, isThrowsIgnored as m, mayThrowEffectsToAbs as n, orphanMayThrowEffects as o, popMayThrowFrame as p, pushMayThrowFrame as q, recordMayThrow as r, runWithMayThrowSession as s, setMayThrowCollector as t, throwAbsToKinds as u, throwsKindCovered as v, type HofSite as w, TYPEOF_NAMES as x, type TypeofName as y, abs as z };
466
+ /**
467
+ * Abs 模块面(无 fs):import 绑定 + export 收集。
468
+ * 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
469
+ */
470
+
471
+ type AbsModuleExports = {
472
+ named: Record<string, Abs>;
473
+ default?: Abs;
474
+ /**
475
+ * 导出表来自成功求值(evalExportsToModuleExports)。
476
+ * fail-closed 空表 / harvest stub / env 手写表不设——missing-export 只对
477
+ * 成功求值的表报(zero-FP,避免与 module-missing 叠报)。
478
+ */
479
+ evaluated?: boolean;
480
+ };
481
+ /**
482
+ * 命名空间 Abs(`import * as ns` / `export * as ns` / CJS require 绑定):
483
+ * open + path——导出收集可能不全(CJS 收集失败等),缺失成员是分析
484
+ * 视图不完整,不得按「运行时缺失」判定(不可调用判定会假抛 TypeError)。
485
+ * 单一构造点:bindImports / run.ts namespaceAbsOf / abs-modules-graph 同口径。
486
+ */
487
+ declare function namespaceAbsOf(mod: AbsModuleExports): Abs;
488
+ /** 把 import 说明符绑定进 env(宿主已求值依赖) */
489
+ declare function bindImports(node: ImportDeclaration, env: AstEnv, modules: Record<string, AbsModuleExports>): void;
490
+ /**
491
+ * 从已求值 env + AST 收集 ESM 导出。
492
+ * 支持:export function/const、export { a, b as c }、export default(具名)、
493
+ * 以及带 source 的 re-export(`export { a } from "mod"` / `export * from "mod"` /
494
+ * `export * as ns from "mod"`——需 host 传入已求值 modules)。
495
+ */
496
+ declare function collectAbsExports(file: File, env: AstEnv, modules?: Record<string, AbsModuleExports>): AbsModuleExports;
497
+
498
+ type RunTranspiledOptions = {
499
+ /** 说明符 → 依赖导出(host 模块图或 runTranspiled 产物) */
500
+ modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
501
+ maxLoopIters?: number;
502
+ /** analyze = 跳过效应性顶层语句 */
503
+ mode?: "exec" | "analyze";
504
+ /** @nudo:replace 注入值:varName → Abs */
505
+ replacements?: Record<string, Abs>;
506
+ /** @nudo:replace 匹配表:传给 transpile */
507
+ replacementTargets?: Array<{
508
+ target: string;
509
+ varName: string;
510
+ stmtStart?: number;
511
+ stmtEnd?: number;
512
+ }>;
513
+ /** @nudo:as 注入值:varName → Abs */
514
+ asOverrides?: Record<string, Abs>;
515
+ /** @nudo:as 语句范围表 */
516
+ asOverrideTargets?: Array<{
517
+ varName: string;
518
+ stmtStart: number;
519
+ stmtEnd: number;
520
+ }>;
521
+ /** @nudo:env 全局 Abs(JSON/Math/console…)→ 作用域绑定 */
522
+ envGlobals?: Record<string, Abs>;
523
+ /** @nudo:mock 注入值:name → Abs(mockDirectivesToAbsSeeds 产物) */
524
+ mocks?: Record<string, Abs>;
525
+ /** 宽松全局(调用点发现 exec 采集:未声明全局调用保守 unknown 不中断) */
526
+ lenientGlobals?: boolean;
527
+ };
528
+ /**
529
+ * inject/modules **内容**指纹(memo 键)。对象身份对「每次新建同内容」
530
+ * 的 CLI 注入不稳——同一语义的 inject 跨 checkSource 调用会 miss 缓存。
531
+ */
532
+ declare function runTranspiledOptionsMemoKey(opts: RunTranspiledOptions | undefined): string;
533
+ declare const RUNTIME_IMPORT_RE: RegExp;
534
+ declare function bindingsOf(run: Record<string, unknown>): Map<string, unknown> | undefined;
535
+ /**
536
+ * 执行一段 求值引擎程序,返回顶层 `export function` / `export const`。
537
+ */
538
+ declare function runTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown>;
539
+ /** evaluator 回落事件(观测单一埋点;reason: unsupported:* = 能力边界,internal = 引擎自身缺陷) */
540
+ type EvalFallback = {
541
+ reason: string;
542
+ message: string;
543
+ loc?: {
544
+ line: number;
545
+ column: number;
546
+ };
547
+ };
548
+ declare function setEvalFallbackCollector(collector: ((f: EvalFallback) => void) | null): void;
549
+ /** 表达式级求值(scan 的 case 字面量实参等静态求值面):编译单表达式经
550
+ * eval 运行时执行。bindings:表达式自由标识符 → Abs(调用方按绑定表注入)。
551
+ * 编译失败抛错(调用方按需 catch)。 */
552
+ declare function evalExprAbs(expr: _babel_types.Expression, bindings?: Record<string, Abs>): Abs;
553
+ /** 回落计数(D6-A:internal 可暴露为 health 指标,不静默吞) */
554
+ type EvalFallbackStats = {
555
+ internal: number;
556
+ unsupported: number;
557
+ moduleThrow: number;
558
+ total: number;
559
+ };
560
+ /** 始终累计(与 collector 无关)——health / 测试读同一口径 */
561
+ declare function getEvalFallbackStats(): EvalFallbackStats;
562
+ /** 宿主入口 / health 按文件分析前重置 */
563
+ declare function resetEvalFallbackStats(): void;
564
+ /** 记录一次 B 回落(body-fn / tryRunTranspiled / call 边界兜底共用) */
565
+ declare function noteEvalFallback(e: unknown): void;
566
+ /**
567
+ * B 单一入口:runTranspiled + 类型化回落观测。
568
+ * unsupported:*(能力边界)/ internal(B 缺陷)都记录到收集器;
569
+ * 返回 undefined 表示调用方应走解释路径。
570
+ */
571
+ declare function tryRunTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown> | undefined;
572
+ type TranspiledCallResult = {
573
+ result: Abs;
574
+ /** 非 never 表示函数可能 throw 该类型 */
575
+ throws: Abs;
576
+ };
577
+ /** 调用 runTranspiled 导出(捕获 $throw)。opts.phi:入口 Φ 种子
578
+ * (instantiate/symbolic 的约束入口——eval 侧路径条件收窄)。
579
+ * 嵌套进入(导出桥 apply)继承外层预算;仅最外层宿主入口重置。 */
580
+ declare function callTranspiledExportFull(exports: Record<string, unknown>, name: string, args: Abs[], opts?: {
581
+ phi?: Phi;
582
+ }): TranspiledCallResult;
583
+ /** 调用 runTranspiled 导出(仅结果) */
584
+ declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
585
+
586
+ export { $tryDigestSoft as $, type Abs as A, throwAbsToKinds as B, type Confidence as C, throwsKindCovered as D, ERROR_FAMILY as E, withEvalBudgetOverride as F, type HofSite as G, type HofCollectCtx as H, type AbsModuleExports as I, type RunTranspiledOptions as J, $assignRecord as K, $callNamed as L, type MayThrowEffect as M, $recordBinding as N, type EvalAbsAssignRecord as O, type PrimName as P, type EvalCallRecord as Q, type RelSource as R, type Shape as S, type Term as T, type EvalFallback as U, type ImplicationOracle as V, type LiteralValue as W, MAX_EVAL_CALL_DEPTH as X, MAX_EVAL_TOTAL_CALLS as Y, RUNTIME_IMPORT_RE as Z, TYPEOF_NAMES as _, type Pred as a, setEvalCallCollector as a$, type TranspiledCallResult as a0, type TypeofName as a1, abs as a2, absToString as a3, and as a4, anyAbs as a5, anyVar as a6, app as a7, assumeFinite as a8, bigintLit as a9, lt as aA, ltNum as aB, namespaceAbsOf as aC, ne as aD, negatePred as aE, never as aF, not as aG, noteEvalCallRecord as aH, noteEvalFallback as aI, num as aJ, numLit as aK, numVar as aL, obj as aM, or as aN, pFalse as aO, pTrue as aP, phiAnd as aQ, predEquals as aR, predToString as aS, predVars as aT, primToTypeof as aU, ptypeof as aV, resetEvalCallBudget as aW, runTranspiled as aX, runTranspiledOptionsMemoKey as aY, setEvalAssignCollector as aZ, setEvalBindingSink as a_, bindImports as aa, bindingsOf as ab, bool as ac, boolLit as ad, callTranspiledExport as ae, callTranspiledExportFull as af, collectAbsExports as ag, confJoin as ah, emptyPhi as ai, eq as aj, evalExprAbs as ak, ge as al, geNum as am, getEvalCallCollector as an, getImplicationOracle as ao, gt as ap, gtNum as aq, implies as ar, isBigPrim as as, isExactLit as at, isNumPrim as au, isStrPrim as av, le as aw, leNum as ax, lit as ay, litValue as az, type Phi as b, setEvalFallbackCollector as b0, setImplicationOracle as b1, shapeOfTerm as b2, shapeToString as b3, simplifyTerm as b4, str as b5, strLit as b6, substPred as b7, termEquals as b8, termToString as b9, tryRunTranspiled as ba, unknown as bb, v as bc, type AstEnv as c, $tryMarkSoft as d, $tryReleaseSoft as e, type EvalFallbackStats as f, enterEvalCallBudgetSession as g, errorTypeAbs as h, exitEvalCallBudgetSession as i, filterDeclaredThrows as j, filterGateThrows as k, filterIgnoredThrows as l, flushMayThrowEffects as m, formatThrowsAbs as n, getEvalCallBudgetState as o, getEvalFallbackStats as p, getMayThrowCollector as q, isThrowsIgnored as r, mayThrowEffectsToAbs as s, orphanMayThrowEffects as t, popMayThrowFrame as u, pushMayThrowFrame as v, recordMayThrow as w, resetEvalFallbackStats as x, runWithMayThrowSession as y, setMayThrowCollector as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/core",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },