@nudojs/core 1.2.2 → 1.4.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-0B9Z66n0.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-0B9Z66n0.js';
3
- import { A as Abs, T as Term, c as AstEnv } from './hof-types-DqDpAxfh.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-DqDpAxfh.js';
1
+ import { I as InterfaceSource, a as InterfaceTierOpts, p as parseSource, C as CheckIssue } from './check-report-Ci1dDysO.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, i as stablePathKey, j as stablePathKeyGraph, t as termDepth, k as termNodes } from './check-report-Ci1dDysO.js';
3
+ import { A as Abs, T as Term, c as AstEnv } from './run-WJfj477N.js';
4
+ export { $ as $tryDigestSoft, d as $tryMarkSoft, e as $tryReleaseSoft, E as ERROR_FAMILY, f as EvalFallbackStats, M as MayThrowEffect, g as clearPureCallMemo, h as clearPureMemo, i as enterEvalCallBudgetSession, j as errorTypeAbs, k as exitEvalCallBudgetSession, l as filterDeclaredThrows, m as filterGateThrows, n as filterIgnoredThrows, o as flushMayThrowEffects, p as formatThrowsAbs, q as getEvalCallBudgetState, r as getEvalFallbackStats, s as getMayThrowCollector, t as isThrowsIgnored, u as mayThrowEffectsToAbs, v as orphanMayThrowEffects, w as popMayThrowFrame, x as pushMayThrowFrame, y as recordMayThrow, z as resetEvalFallbackStats, B as runWithMayThrowSession, D as setMayThrowCollector, F as throwAbsToKinds, G as throwsKindCovered, H as withEvalBudgetOverride } from './run-WJfj477N.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
@@ -15,8 +15,10 @@ import {
15
15
  resetHashSourceCache,
16
16
  resolveDepPath,
17
17
  sidecarSpecsOf,
18
- stableAnalyzeKeySource
19
- } from "./chunk-TOURNNEA.js";
18
+ stableAnalyzeKeySource,
19
+ stablePathKey,
20
+ stablePathKeyGraph
21
+ } from "./chunk-7QUVTEYZ.js";
20
22
  import {
21
23
  $tryDigestSoft,
22
24
  $tryMarkSoft,
@@ -26,8 +28,11 @@ import {
26
28
  HOST_EFFECT_LABEL_PREFIX,
27
29
  MAX_CALL_DEPTH,
28
30
  MAX_EVAL_TOTAL_FORKS,
31
+ MAX_PROMISE_MICROS,
29
32
  MAX_TOTAL_CALLS,
30
33
  OBJECT_PROTO_NAMES,
34
+ PROMISE_MICRO_ERROR_LABEL,
35
+ PROMISE_MICRO_OVERFLOW_LABEL,
31
36
  abortDerivationSession,
32
37
  absTemplateViews,
33
38
  allFixedTextOfViews,
@@ -38,6 +43,8 @@ import {
38
43
  callBudgetKey,
39
44
  classChainNames,
40
45
  classFromMethods,
46
+ clearPureCallMemo,
47
+ clearPureMemo,
41
48
  coerceAsyncReturn,
42
49
  concatString,
43
50
  createTemplateAbs,
@@ -50,9 +57,11 @@ import {
50
57
  derivationChain,
51
58
  endDerivationSession,
52
59
  enterCall,
60
+ enterEvalCallBudgetSession,
53
61
  errorTypeAbs,
54
62
  exceedsBudget,
55
63
  exitCall,
64
+ exitEvalCallBudgetSession,
56
65
  filterDeclaredThrows,
57
66
  filterGateThrows,
58
67
  filterIgnoredThrows,
@@ -66,9 +75,12 @@ import {
66
75
  getClass,
67
76
  getClassChain,
68
77
  getDerivation,
78
+ getEvalCallBudgetState,
79
+ getEvalFallbackStats,
69
80
  getEvalForkBudgetLimit,
70
81
  getEvalForkCount,
71
82
  getMayThrowCollector,
83
+ getPromiseMicrosLength,
72
84
  hasDerivationSession,
73
85
  instanceOf,
74
86
  instantiateClass,
@@ -83,6 +95,7 @@ import {
83
95
  lookupMethod,
84
96
  lookupMethodWithOwner,
85
97
  lookupSuperMethod,
98
+ maskCommentsAndStrings,
86
99
  mayThrowEffectsToAbs,
87
100
  maybeLeak,
88
101
  mergeAdjacentFixedViews,
@@ -109,10 +122,12 @@ import {
109
122
  recordMayThrow,
110
123
  recordMemberDiag,
111
124
  resetAbsCallBudget,
125
+ resetEvalFallbackStats,
112
126
  resetEvalForkBudget,
113
127
  resetLeakCounter,
114
128
  runWithEvalMissingSlot,
115
129
  runWithMayThrowSession,
130
+ scanStringLiterals,
116
131
  setAbsTruncationCollector,
117
132
  setDerivation,
118
133
  setDerivationCollector,
@@ -120,7 +135,12 @@ import {
120
135
  setEvalMissingSlotEnabled,
121
136
  setMayThrowCollector,
122
137
  setMemberDiagCollector,
138
+ sourceHasCjsExports,
139
+ sourceHasModuleDependency,
140
+ sourceHasRequireCall,
123
141
  stableCallId,
142
+ stripCommentsAndStrings,
143
+ stripStringsKeepComments,
124
144
  superNameOf,
125
145
  tagAbsOrigin,
126
146
  tagDerivationRoot,
@@ -134,8 +154,10 @@ import {
134
154
  throwsKindCovered,
135
155
  truncatedAbs,
136
156
  viewTemplateParts,
157
+ withEvalBudgetOverride,
158
+ withFnBudgetOverride,
137
159
  wrapPromise
138
- } from "./chunk-4V3CRVSD.js";
160
+ } from "./chunk-LFCF6BLE.js";
139
161
 
140
162
  // src/algebra/inlay.ts
141
163
  function listFunctions(source) {
@@ -193,12 +215,13 @@ function formatReturnDisplay(g) {
193
215
  const t = stripParens(renameTypeVars(termToString(m.term), varMap));
194
216
  return { key: `app:${t}`, text: t };
195
217
  }
196
- const lv = litValue(m);
197
- if (typeof lv === "number" && !Number.isFinite(lv)) {
198
- return { key: `lit:${String(lv)}`, text: String(lv) };
199
- }
200
- if (lv !== void 0) {
201
- return { key: `lit:${String(lv)}`, text: JSON.stringify(lv) };
218
+ const lvR = litValue(m);
219
+ if (lvR.ok) {
220
+ const lv = lvR.value;
221
+ if (typeof lv === "number" && !Number.isFinite(lv)) {
222
+ return { key: `lit:${String(lv)}`, text: String(lv) };
223
+ }
224
+ return { key: `lit:${String(lv)}`, text: JSON.stringify(lv) ?? "undefined" };
202
225
  }
203
226
  return { key: `shape:${formatShape(m)}`, text: formatShape(m) };
204
227
  };
@@ -286,11 +309,31 @@ function collectAbsInlays(source, opts) {
286
309
  return inlays;
287
310
  }
288
311
 
312
+ // src/algebra/codegen-escape.ts
313
+ var JS_IDENT = /^[A-Za-z_$][A-Za-z0-9_$]*$/;
314
+ var JS_CANONICAL_INT = /^(?:0|[1-9]\d*)$/;
315
+ function isJsIdent(name) {
316
+ return JS_IDENT.test(name);
317
+ }
318
+ function formatObjectKey(k) {
319
+ if (JS_IDENT.test(k)) return k;
320
+ if (JS_CANONICAL_INT.test(k)) return k;
321
+ return JSON.stringify(k);
322
+ }
323
+ function safeMemberAccess(recv, key) {
324
+ return JS_IDENT.test(key) ? `${recv}.${key}` : `${recv}[${JSON.stringify(key)}]`;
325
+ }
326
+ function escapeTemplateTypeFixed(text) {
327
+ return text.replace(/[\\`$]/g, "\\$&");
328
+ }
329
+ function sanitizeCommentText(text) {
330
+ return text.replace(/\*\//g, "*\\/").replace(/[\r\n\u2028\u2029\x00-\x08\x0b\x0c\x0e-\x1f\x7f]/g, " ");
331
+ }
332
+
289
333
  // src/algebra/denote.ts
290
334
  function denoteGuard(a, v) {
291
- const lv = litValue(a);
292
- if (lv !== void 0 && (!a.pred || a.pred.op === "true")) {
293
- return eqGuard(v, lv);
335
+ if (a.term?.op === "lit" && (!a.pred || a.pred.op === "true")) {
336
+ return eqGuard(v, a.term.value);
294
337
  }
295
338
  const shape = denoteShape(a.shape, v);
296
339
  const pred = denotePred(a, v);
@@ -323,7 +366,7 @@ function denoteShape(s, v) {
323
366
  case "obj": {
324
367
  const checks = [`typeof ${v} === "object"`, `${v} !== null`];
325
368
  for (const [key, slot] of Object.entries(s.slots)) {
326
- const access = `${v}.${key}`;
369
+ const access = safeMemberAccess(v, key);
327
370
  const inner = denoteGuard(slot.value, access);
328
371
  if (slot.optional) {
329
372
  if (inner !== "true") checks.push(`(${access} === undefined || ${inner})`);
@@ -338,11 +381,19 @@ function denoteShape(s, v) {
338
381
  case "tuple": {
339
382
  const checks = [`Array.isArray(${v})`];
340
383
  const minLen = s.elements.length;
384
+ const holes = new Set(s.holes ?? []);
341
385
  checks.push(s.rest ? `${v}.length >= ${minLen}` : `${v}.length === ${minLen}`);
342
386
  s.elements.forEach((el, i) => {
387
+ if (holes.has(i)) {
388
+ checks.push(`!(${i} in ${v})`);
389
+ return;
390
+ }
343
391
  const inner = denoteGuard(el, `${v}[${i}]`);
344
392
  if (inner !== "true") checks.push(inner);
345
393
  });
394
+ for (const i of holes) {
395
+ if (i >= minLen) checks.push(`!(${i} in ${v})`);
396
+ }
346
397
  if (s.rest) {
347
398
  const rest = denoteGuard(s.rest, "item");
348
399
  if (rest !== "true") {
@@ -368,8 +419,7 @@ function denoteShape(s, v) {
368
419
  function denotePred(a, v) {
369
420
  const p = a.pred;
370
421
  if (!p || p.op === "true") {
371
- const lv = litValue(a);
372
- if (lv !== void 0) return eqGuard(v, lv);
422
+ if (a.term?.op === "lit") return eqGuard(v, a.term.value);
373
423
  return "true";
374
424
  }
375
425
  return predAsJs(p, v, a);
@@ -396,17 +446,17 @@ function predAsJs(p, v, a) {
396
446
  case "ne": {
397
447
  const op = { gt: ">", ge: ">=", lt: "<", le: "<=", eq: "===", ne: "!==" }[p.op];
398
448
  const leftIsValue = termIsValue(p.a, a);
399
- const rightLit = litOfTerm(p.b);
400
- if (leftIsValue && rightLit !== void 0) {
401
- return cmpOp(v, op, rightLit);
449
+ const rightLitTerm = p.b.op === "lit" ? p.b : void 0;
450
+ if (leftIsValue && rightLitTerm) {
451
+ return cmpOp(v, op, rightLitTerm.value);
402
452
  }
403
- const leftLit = litOfTerm(p.a);
453
+ const leftLitTerm = p.a.op === "lit" ? p.a : void 0;
404
454
  const rightIsValue = termIsValue(p.b, a);
405
- if (rightIsValue && leftLit !== void 0) {
406
- return cmpLitValue(leftLit, op, v);
455
+ if (rightIsValue && leftLitTerm) {
456
+ return cmpLitValue(leftLitTerm.value, op, v);
407
457
  }
408
- if (leftLit !== void 0 && rightLit !== void 0) {
409
- return `${jsLit(leftLit)} ${op} ${jsLit(rightLit)}`;
458
+ if (leftLitTerm && rightLitTerm) {
459
+ return `${jsLit(leftLitTerm.value)} ${op} ${jsLit(rightLitTerm.value)}`;
410
460
  }
411
461
  return "true";
412
462
  }
@@ -414,12 +464,10 @@ function predAsJs(p, v, a) {
414
464
  return "true";
415
465
  }
416
466
  }
417
- function litOfTerm(t) {
418
- return t.op === "lit" ? t.value : void 0;
419
- }
420
467
  function jsLit(v) {
421
468
  if (v === void 0) return "undefined";
422
469
  if (v === null) return "null";
470
+ if (typeof v === "bigint") return `${v}n`;
423
471
  if (typeof v === "number") {
424
472
  if (Number.isNaN(v)) return "NaN";
425
473
  if (v === Infinity) return "Infinity";
@@ -449,8 +497,7 @@ function cmpLitValue(lit, op, v) {
449
497
  function termIsValue(t, a) {
450
498
  if (t.op === "var") return true;
451
499
  if (t.op === "lit") {
452
- const lv = litValue(a);
453
- return lv !== void 0 && Object.is(lv, t.value);
500
+ return a.term?.op === "lit" && Object.is(a.term.value, t.value);
454
501
  }
455
502
  return false;
456
503
  }
@@ -463,8 +510,11 @@ export {
463
510
  HOST_EFFECT_LABEL_PREFIX,
464
511
  MAX_CALL_DEPTH,
465
512
  MAX_EVAL_TOTAL_FORKS,
513
+ MAX_PROMISE_MICROS,
466
514
  MAX_TOTAL_CALLS,
467
515
  OBJECT_PROTO_NAMES,
516
+ PROMISE_MICRO_ERROR_LABEL,
517
+ PROMISE_MICRO_OVERFLOW_LABEL,
468
518
  abortDerivationSession,
469
519
  absTemplateViews,
470
520
  allFixedTextOfViews,
@@ -477,6 +527,8 @@ export {
477
527
  checkInjectedDomainEvidence,
478
528
  classChainNames,
479
529
  classFromMethods,
530
+ clearPureCallMemo,
531
+ clearPureMemo,
480
532
  coerceAsyncReturn,
481
533
  collectAbsInlays,
482
534
  concatString,
@@ -491,9 +543,12 @@ export {
491
543
  derivationChain,
492
544
  endDerivationSession,
493
545
  enterCall,
546
+ enterEvalCallBudgetSession,
494
547
  errorTypeAbs,
548
+ escapeTemplateTypeFixed,
495
549
  exceedsBudget,
496
550
  exitCall,
551
+ exitEvalCallBudgetSession,
497
552
  extractAllLoadSpecs,
498
553
  filterDeclaredThrows,
499
554
  filterGateThrows,
@@ -501,6 +556,7 @@ export {
501
556
  fixedLengthOfViews,
502
557
  flushMayThrowEffects,
503
558
  fnFingerprints,
559
+ formatObjectKey,
504
560
  formatTemplateNameViews,
505
561
  formatThrowsAbs,
506
562
  generalizeSourceKeyPart,
@@ -509,15 +565,19 @@ export {
509
565
  getClass,
510
566
  getClassChain,
511
567
  getDerivation,
568
+ getEvalCallBudgetState,
569
+ getEvalFallbackStats,
512
570
  getEvalForkBudgetLimit,
513
571
  getEvalForkCount,
514
572
  getFnNameAndBodies,
515
573
  getMayThrowCollector,
574
+ getPromiseMicrosLength,
516
575
  hasDerivationSession,
517
576
  hashSource,
518
577
  instanceOf,
519
578
  instantiateClass,
520
579
  isEvalMissingSlotEnabled,
580
+ isJsIdent,
521
581
  isNullishAbs,
522
582
  isTemplateLike,
523
583
  isThrowsIgnored,
@@ -529,6 +589,7 @@ export {
529
589
  lookupMethod,
530
590
  lookupMethodWithOwner,
531
591
  lookupSuperMethod,
592
+ maskCommentsAndStrings,
532
593
  mayThrowEffectsToAbs,
533
594
  maybeLeak,
534
595
  mergeAdjacentFixedViews,
@@ -554,6 +615,7 @@ export {
554
615
  recordMayThrow,
555
616
  recordMemberDiag,
556
617
  resetAbsCallBudget,
618
+ resetEvalFallbackStats,
557
619
  resetEvalForkBudget,
558
620
  resetFnFpCache,
559
621
  resetHashSourceCache,
@@ -561,6 +623,9 @@ export {
561
623
  resolveDepPath,
562
624
  runWithEvalMissingSlot,
563
625
  runWithMayThrowSession,
626
+ safeMemberAccess,
627
+ sanitizeCommentText,
628
+ scanStringLiterals,
564
629
  setAbsTruncationCollector,
565
630
  setDerivation,
566
631
  setDerivationCollector,
@@ -569,8 +634,15 @@ export {
569
634
  setMayThrowCollector,
570
635
  setMemberDiagCollector,
571
636
  sidecarSpecsOf,
637
+ sourceHasCjsExports,
638
+ sourceHasModuleDependency,
639
+ sourceHasRequireCall,
572
640
  stableAnalyzeKeySource,
573
641
  stableCallId,
642
+ stablePathKey,
643
+ stablePathKeyGraph,
644
+ stripCommentsAndStrings,
645
+ stripStringsKeepComments,
574
646
  superNameOf,
575
647
  tagAbsOrigin,
576
648
  tagDerivationRoot,
@@ -583,5 +655,7 @@ export {
583
655
  throwsKindCovered,
584
656
  truncatedAbs,
585
657
  viewTemplateParts,
658
+ withEvalBudgetOverride,
659
+ withFnBudgetOverride,
586
660
  wrapPromise
587
661
  };