@nudojs/core 1.0.0 → 1.0.1

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/dist/index.js CHANGED
@@ -59,14 +59,17 @@ import {
59
59
  MAX_CALL_DEPTH,
60
60
  MAX_TOTAL_CALLS,
61
61
  NudoThrow,
62
+ abortDerivationSession,
62
63
  abs,
63
64
  absFunction,
65
+ absShapeKey,
64
66
  absTemplateViews,
65
67
  absToString,
66
68
  add,
67
69
  allFixedTextOfViews,
68
70
  alphaOf,
69
71
  analyzeFn,
72
+ analyzeFnFull,
70
73
  and,
71
74
  anyVar,
72
75
  app,
@@ -76,12 +79,14 @@ import {
76
79
  asAbsVal,
77
80
  attachFnImpl,
78
81
  awaitAbs,
82
+ beginDerivationSession,
79
83
  betaOf,
80
84
  bindImports,
81
85
  bool,
82
86
  boolLit,
83
87
  callAbsMethod,
84
88
  callFunction,
89
+ callFunctionFull,
85
90
  callTranspiledExport,
86
91
  callTranspiledExportFull,
87
92
  classFromMethods,
@@ -101,9 +106,11 @@ import {
101
106
  defaultLeakBudget,
102
107
  defineClass,
103
108
  definitelyNotNullishShape,
109
+ derivationChain,
104
110
  div,
105
111
  emptyEnv,
106
112
  emptyPhi,
113
+ endDerivationSession,
107
114
  eq,
108
115
  evalArrayStatic,
109
116
  evalBuiltinInstanceMethod,
@@ -139,11 +146,13 @@ import {
139
146
  getBClass,
140
147
  getClass,
141
148
  getClassChain,
149
+ getDerivation,
142
150
  getFnImpl,
143
151
  getParseSourceCacheSize,
144
152
  getSlot,
145
153
  gt,
146
154
  gtNum,
155
+ hasDerivationSession,
147
156
  implies,
148
157
  instanceOf,
149
158
  instantiateClass,
@@ -189,6 +198,8 @@ import {
189
198
  never,
190
199
  not,
191
200
  notAbs,
201
+ noteDerivationAdd,
202
+ noteDerivationJoin,
192
203
  noteMemberDispatchMiss,
193
204
  notePrimMemberMissing,
194
205
  noteUnknownMemberMissing,
@@ -206,6 +217,7 @@ import {
206
217
  predToString,
207
218
  predVars,
208
219
  projectBrand,
220
+ projectDerivationDsl,
209
221
  projectFlatMapResult,
210
222
  promoteParamShape,
211
223
  ptypeof,
@@ -224,6 +236,8 @@ import {
224
236
  setAbsTruncationCollector,
225
237
  setApplyCallbackHost,
226
238
  setBCallCollector,
239
+ setDerivation,
240
+ setDerivationCollector,
227
241
  setMemberDiagCollector,
228
242
  shapeOfTerm,
229
243
  shapeOnlyFn,
@@ -241,10 +255,12 @@ import {
241
255
  substPredAbs,
242
256
  superNameOf,
243
257
  tagAbsOrigin,
258
+ tagDerivationRoot,
244
259
  templateMatchesValue,
245
260
  templatePartsOf,
246
261
  termDepth,
247
262
  termEquals,
263
+ termKey,
248
264
  termNodes,
249
265
  termToString,
250
266
  transpile,
@@ -264,711 +280,7 @@ import {
264
280
  withExecPhi,
265
281
  withVar,
266
282
  wrapPromise
267
- } from "./chunk-RZOQL6PT.js";
268
-
269
- // src/refinements/template-predicates.ts
270
- function isTemplate(tv) {
271
- return tv.kind === "refined" && Array.isArray(tv.refinement.meta.parts);
272
- }
273
-
274
- // src/type-value.ts
275
- function createUnion(...members) {
276
- return simplifyUnion(members);
277
- }
278
- var T = {
279
- literal: (value) => ({ kind: "literal", value }),
280
- number: { kind: "primitive", type: "number" },
281
- string: { kind: "primitive", type: "string" },
282
- boolean: { kind: "primitive", type: "boolean" },
283
- bigint: { kind: "primitive", type: "bigint" },
284
- symbol: { kind: "primitive", type: "symbol" },
285
- null: { kind: "literal", value: null },
286
- undefined: { kind: "literal", value: void 0 },
287
- unknown: { kind: "unknown" },
288
- never: { kind: "never" },
289
- object: (properties) => ({
290
- kind: "object",
291
- properties,
292
- id: Symbol("object")
293
- }),
294
- array: (element) => ({ kind: "array", element }),
295
- tuple: (elements) => ({ kind: "tuple", elements }),
296
- promise: (value) => ({ kind: "promise", value }),
297
- instanceOf: (className, properties = {}) => ({
298
- kind: "instance",
299
- className,
300
- properties
301
- }),
302
- union: createUnion,
303
- fn: (params, body, closure) => ({
304
- kind: "function",
305
- params,
306
- body,
307
- closure
308
- }),
309
- refine: (base, refinement) => ({
310
- kind: "refined",
311
- base,
312
- refinement
313
- }),
314
- fnSig: (paramTypes, returnType, throwsType = { kind: "never" }, impl) => {
315
- const dummy = {
316
- kind: "function",
317
- params: paramTypes.map((_p, i) => `_arg${i}`),
318
- body: { type: "BlockStatement", body: [], directives: [] },
319
- closure: null
320
- };
321
- dummy._signature = { paramTypes, returnType, throwsType, impl };
322
- return dummy;
323
- }
324
- };
325
- function typeValueEquals(a, b) {
326
- if (a.kind !== b.kind) return false;
327
- if (a.kind === "literal" && b.kind === "literal") return a.value === b.value;
328
- if (a.kind === "primitive" && b.kind === "primitive") return a.type === b.type;
329
- if (a.kind === "never" && b.kind === "never") return true;
330
- if (a.kind === "unknown" && b.kind === "unknown") return true;
331
- if (a.kind === "refined" && b.kind === "refined") {
332
- return a.refinement.name === b.refinement.name && typeValueEquals(a.base, b.base);
333
- }
334
- if (a.kind === "promise" && b.kind === "promise") {
335
- return typeValueEquals(a.value, b.value);
336
- }
337
- if (a.kind === "instance" && b.kind === "instance") {
338
- return a.className === b.className;
339
- }
340
- if (a.kind === "union" && b.kind === "union") {
341
- return a.members.length === b.members.length && a.members.every((m, i) => typeValueEquals(m, b.members[i]));
342
- }
343
- return a === b;
344
- }
345
- function simplifyUnion(members) {
346
- if (members.length === 0) return T.never;
347
- if (members.length === 1) return members[0].kind === "never" ? T.never : members[0];
348
- if (members.length === 2) {
349
- const a = members[0];
350
- const b = members[1];
351
- if (a.kind !== "union" && b.kind !== "union") {
352
- if (a.kind === "never") return b.kind === "never" ? T.never : b;
353
- if (b.kind === "never") return a;
354
- if (typeValueEquals(a, b)) return a;
355
- if (a.kind === "unknown" || b.kind === "unknown") return T.unknown;
356
- const aBase = absorbablePrimitiveBase(a);
357
- if (aBase !== void 0 && typeValueEquals(aBase, b)) return b;
358
- const bBase = absorbablePrimitiveBase(b);
359
- if (bBase !== void 0 && typeValueEquals(bBase, a)) return a;
360
- return { kind: "union", members: [a, b] };
361
- }
362
- }
363
- const flat = [];
364
- for (const m of members) {
365
- if (m.kind === "never") continue;
366
- if (m.kind === "union") {
367
- flat.push(...m.members);
368
- } else {
369
- flat.push(m);
370
- }
371
- }
372
- const deduped = [];
373
- for (const m of flat) {
374
- if (!deduped.some((d) => typeValueEquals(d, m))) {
375
- deduped.push(m);
376
- }
377
- }
378
- const primitives = deduped.filter((m) => m.kind === "primitive");
379
- const absorbed = primitives.length > 0 ? deduped.filter((m) => {
380
- const base = absorbablePrimitiveBase(m);
381
- return base === void 0 || !primitives.some((p) => typeValueEquals(p, base));
382
- }) : deduped;
383
- if (absorbed.length === 0) return T.never;
384
- if (absorbed.length === 1) return absorbed[0];
385
- if (absorbed.some((m) => m.kind === "unknown")) return T.unknown;
386
- return { kind: "union", members: absorbed };
387
- }
388
- function absorbablePrimitiveBase(tv) {
389
- if (tv.kind === "literal") {
390
- const widened = widenLiteral(tv);
391
- return widened.kind === "primitive" ? widened : void 0;
392
- }
393
- if (isTemplate(tv)) return T.string;
394
- return void 0;
395
- }
396
- function widenLiteral(tv) {
397
- if (tv.kind !== "literal") return tv;
398
- const v2 = tv.value;
399
- if (typeof v2 === "number") return T.number;
400
- if (typeof v2 === "string") return T.string;
401
- if (typeof v2 === "boolean") return T.boolean;
402
- if (typeof v2 === "bigint") return T.bigint;
403
- if (v2 === null) return T.null;
404
- if (v2 === void 0) return T.undefined;
405
- return T.unknown;
406
- }
407
- function collapseLiteralUnion(tv, maxLiterals) {
408
- if (tv.kind !== "union") return tv;
409
- if (tv.members.length <= maxLiterals) return tv;
410
- const simplified = simplifyUnion(tv.members);
411
- if (simplified.kind !== "union") return simplified;
412
- if (!simplified.members.every((m) => m.kind === "literal")) return simplified;
413
- const first = widenLiteral(simplified.members[0]);
414
- if (!simplified.members.every((m) => typeValueEquals(widenLiteral(m), first))) return simplified;
415
- return first;
416
- }
417
- function isSubtypeOf(a, b) {
418
- if (b.kind === "unknown") return true;
419
- if (a.kind === "never") return true;
420
- if (typeValueEquals(a, b)) return true;
421
- if (a.kind === "literal" && b.kind === "primitive") {
422
- const v2 = a.value;
423
- if (b.type === "number" && typeof v2 === "number") return true;
424
- if (b.type === "string" && typeof v2 === "string") return true;
425
- if (b.type === "boolean" && typeof v2 === "boolean") return true;
426
- return false;
427
- }
428
- if (a.kind === "literal" && b.kind === "refined") {
429
- if (!isSubtypeOf(a, b.base)) return false;
430
- return b.refinement.check ? b.refinement.check(a.value) : false;
431
- }
432
- if (a.kind === "refined") {
433
- if (b.kind === "refined" && a.refinement.name === b.refinement.name) {
434
- return isSubtypeOf(a.base, b.base);
435
- }
436
- return isSubtypeOf(a.base, b);
437
- }
438
- if (a.kind === "object" && b.kind === "object") {
439
- return Object.entries(b.properties).every(
440
- ([k, bv]) => k in a.properties && isSubtypeOf(a.properties[k], bv)
441
- );
442
- }
443
- if (a.kind === "array" && b.kind === "array") {
444
- return isSubtypeOf(a.element, b.element);
445
- }
446
- if (a.kind === "tuple" && b.kind === "tuple") {
447
- return a.elements.length === b.elements.length && a.elements.every((el, i) => isSubtypeOf(el, b.elements[i]));
448
- }
449
- if (a.kind === "tuple" && b.kind === "array") {
450
- return a.elements.every((el) => isSubtypeOf(el, b.element));
451
- }
452
- if (a.kind === "promise" && b.kind === "promise") {
453
- return isSubtypeOf(a.value, b.value);
454
- }
455
- if (a.kind === "instance" && b.kind === "instance") {
456
- return a.className === b.className || isErrorSubclass(a.className, b.className);
457
- }
458
- if (a.kind === "union") {
459
- return a.members.every((m) => isSubtypeOf(m, b));
460
- }
461
- if (b.kind === "union") {
462
- return b.members.some((m) => isSubtypeOf(a, m));
463
- }
464
- return false;
465
- }
466
- var errorHierarchy = {
467
- TypeError: "Error",
468
- SyntaxError: "Error",
469
- RangeError: "Error",
470
- ReferenceError: "Error",
471
- URIError: "Error",
472
- EvalError: "Error"
473
- };
474
- function isErrorSubclass(child, parent) {
475
- if (child === parent) return true;
476
- const sup = errorHierarchy[child];
477
- return sup ? isErrorSubclass(sup, parent) : false;
478
- }
479
- function deepCloneTypeValue(tv, idMap) {
480
- const map = idMap ?? /* @__PURE__ */ new Map();
481
- if (tv.kind === "object") {
482
- let newId = map.get(tv.id);
483
- if (!newId) {
484
- newId = Symbol("object");
485
- map.set(tv.id, newId);
486
- }
487
- const newProps = {};
488
- for (const [k, v2] of Object.entries(tv.properties)) {
489
- newProps[k] = deepCloneTypeValue(v2, map);
490
- }
491
- return { kind: "object", properties: newProps, id: newId };
492
- }
493
- if (tv.kind === "array") {
494
- return { kind: "array", element: deepCloneTypeValue(tv.element, map) };
495
- }
496
- if (tv.kind === "tuple") {
497
- return { kind: "tuple", elements: tv.elements.map((e) => deepCloneTypeValue(e, map)) };
498
- }
499
- if (tv.kind === "promise") {
500
- return { kind: "promise", value: deepCloneTypeValue(tv.value, map) };
501
- }
502
- if (tv.kind === "instance") {
503
- const newProps = {};
504
- for (const [k, v2] of Object.entries(tv.properties)) {
505
- newProps[k] = deepCloneTypeValue(v2, map);
506
- }
507
- return { kind: "instance", className: tv.className, properties: newProps };
508
- }
509
- if (tv.kind === "refined") {
510
- return { kind: "refined", base: deepCloneTypeValue(tv.base, map), refinement: tv.refinement };
511
- }
512
- if (tv.kind === "union") {
513
- return simplifyUnion(tv.members.map((m) => deepCloneTypeValue(m, map)));
514
- }
515
- return tv;
516
- }
517
- function mergeObjectProperties(a, b) {
518
- const allKeys = /* @__PURE__ */ new Set([...Object.keys(a.properties), ...Object.keys(b.properties)]);
519
- const merged = {};
520
- for (const k of allKeys) {
521
- const av = a.properties[k];
522
- const bv = b.properties[k];
523
- if (av && bv) {
524
- merged[k] = simplifyUnion([av, bv]);
525
- } else {
526
- merged[k] = av ?? bv;
527
- }
528
- }
529
- return { kind: "object", properties: merged, id: a.id };
530
- }
531
- function typeValueToString(tv) {
532
- return typeValueToStringInner(tv, /* @__PURE__ */ new Set());
533
- }
534
- function typeValueToStringInner(tv, seen, depth = 0) {
535
- if (depth > 48) return "\u2026";
536
- const recur = (inner) => {
537
- if (inner && typeof inner === "object") {
538
- if (seen.has(inner)) return "\u2026";
539
- seen.add(inner);
540
- const out = typeValueToStringInner(inner, seen, depth + 1);
541
- seen.delete(inner);
542
- return out;
543
- }
544
- return typeValueToStringInner(inner, seen, depth + 1);
545
- };
546
- switch (tv.kind) {
547
- case "literal": {
548
- const v2 = tv.value;
549
- if (v2 === null) return "null";
550
- if (v2 === void 0) return "undefined";
551
- if (typeof v2 === "string") return JSON.stringify(v2);
552
- return String(v2);
553
- }
554
- case "primitive":
555
- return tv.type;
556
- case "refined":
557
- return tv.refinement.name;
558
- case "object": {
559
- const entries = Object.entries(tv.properties);
560
- if (entries.length === 0) return "{}";
561
- const inner = entries.map(([k, v2]) => `${k}: ${recur(v2)}`).join(", ");
562
- return `{ ${inner} }`;
563
- }
564
- case "array":
565
- return `${recur(tv.element)}[]`;
566
- case "tuple": {
567
- const inner = tv.elements.map(recur).join(", ");
568
- return `[${inner}]`;
569
- }
570
- case "function": {
571
- const sig = getFnSig(tv);
572
- if (sig) {
573
- const params2 = sig.paramTypes.map((p, i) => `${tv.params[i]}: ${recur(p)}`).join(", ");
574
- return `(${params2}) => ${recur(sig.returnType)}`;
575
- }
576
- const params = tv.params.join(", ");
577
- return `(${params}) => ...`;
578
- }
579
- case "promise":
580
- return `Promise<${recur(tv.value)}>`;
581
- case "instance": {
582
- const entries = Object.entries(tv.properties);
583
- if (entries.length === 0) return tv.className;
584
- const inner = entries.map(([k, v2]) => `${k}: ${recur(v2)}`).join(", ");
585
- return `${tv.className} { ${inner} }`;
586
- }
587
- case "union": {
588
- return tv.members.map(recur).join(" | ");
589
- }
590
- case "never":
591
- return "never";
592
- case "unknown":
593
- return "unknown";
594
- }
595
- }
596
- function narrowType(tv, predicate) {
597
- if (tv.kind === "union") {
598
- return simplifyUnion(tv.members.filter(predicate));
599
- }
600
- return predicate(tv) ? tv : T.never;
601
- }
602
- function subtractType(tv, predicate) {
603
- return narrowType(tv, (m) => !predicate(m));
604
- }
605
- function getPrimitiveTypeOf(tv) {
606
- if (tv.kind === "literal") {
607
- const v2 = tv.value;
608
- if (v2 === null) return "object";
609
- return typeof v2;
610
- }
611
- if (tv.kind === "primitive") return tv.type;
612
- if (tv.kind === "refined") return getPrimitiveTypeOf(tv.base);
613
- if (tv.kind === "object") return "object";
614
- if (tv.kind === "array" || tv.kind === "tuple") return "object";
615
- if (tv.kind === "function") return "function";
616
- if (tv.kind === "promise") return "object";
617
- if (tv.kind === "instance") return "object";
618
- return void 0;
619
- }
620
- function getRefinedBase(tv) {
621
- return tv.kind === "refined" ? getRefinedBase(tv.base) : tv;
622
- }
623
- function isFnSig(tv) {
624
- return tv.kind === "function" && "_signature" in tv;
625
- }
626
- function getFnSig(tv) {
627
- if (tv.kind === "function" && "_signature" in tv) {
628
- return tv._signature;
629
- }
630
- return void 0;
631
- }
632
-
633
- // src/refinements/range.ts
634
- function formatRangeName(meta) {
635
- const parts = [];
636
- if (meta.integer) parts.push("integer");
637
- else parts.push("number");
638
- const constraints = [];
639
- if (meta.min != null) {
640
- constraints.push(meta.minExclusive ? `> ${meta.min}` : `>= ${meta.min}`);
641
- }
642
- if (meta.max != null) {
643
- constraints.push(meta.maxExclusive ? `< ${meta.max}` : `<= ${meta.max}`);
644
- }
645
- if (constraints.length > 0) parts.push(`(${constraints.join(", ")})`);
646
- return parts.join(" ");
647
- }
648
- function createRangeRefinement(meta) {
649
- return {
650
- name: formatRangeName(meta),
651
- meta: { ...meta },
652
- check(value) {
653
- if (typeof value !== "number") return false;
654
- if (meta.integer && !Number.isInteger(value)) return false;
655
- if (meta.min != null) {
656
- if (meta.minExclusive ? value <= meta.min : value < meta.min) return false;
657
- }
658
- if (meta.max != null) {
659
- if (meta.maxExclusive ? value >= meta.max : value > meta.max) return false;
660
- }
661
- return true;
662
- },
663
- ops: {
664
- ">="(self, other) {
665
- const m = getRangeMeta(self);
666
- if (!m || other.kind !== "literal" || typeof other.value !== "number") return void 0;
667
- if (m.min != null) {
668
- if (m.minExclusive && m.min >= other.value) return T.literal(true);
669
- if (!m.minExclusive && m.min >= other.value) return T.literal(true);
670
- }
671
- if (m.max != null) {
672
- if (m.maxExclusive && m.max <= other.value) return T.literal(false);
673
- if (!m.maxExclusive && m.max < other.value) return T.literal(false);
674
- }
675
- return void 0;
676
- },
677
- ">"(self, other) {
678
- const m = getRangeMeta(self);
679
- if (!m || other.kind !== "literal" || typeof other.value !== "number") return void 0;
680
- if (m.min != null) {
681
- if (m.minExclusive && m.min >= other.value) return T.literal(true);
682
- if (!m.minExclusive && m.min > other.value) return T.literal(true);
683
- }
684
- if (m.max != null) {
685
- if (m.max <= other.value) return T.literal(false);
686
- }
687
- return void 0;
688
- },
689
- "<="(self, other) {
690
- const m = getRangeMeta(self);
691
- if (!m || other.kind !== "literal" || typeof other.value !== "number") return void 0;
692
- if (m.max != null) {
693
- if (m.maxExclusive && m.max <= other.value) return T.literal(true);
694
- if (!m.maxExclusive && m.max <= other.value) return T.literal(true);
695
- }
696
- if (m.min != null) {
697
- if (m.minExclusive && m.min >= other.value) return T.literal(false);
698
- if (!m.minExclusive && m.min > other.value) return T.literal(false);
699
- }
700
- return void 0;
701
- },
702
- "<"(self, other) {
703
- const m = getRangeMeta(self);
704
- if (!m || other.kind !== "literal" || typeof other.value !== "number") return void 0;
705
- if (m.max != null) {
706
- if (m.maxExclusive && m.max <= other.value) return T.literal(true);
707
- if (!m.maxExclusive && m.max < other.value) return T.literal(true);
708
- }
709
- if (m.min != null) {
710
- if (m.min >= other.value) return T.literal(false);
711
- }
712
- return void 0;
713
- }
714
- }
715
- };
716
- }
717
- function createRange(meta) {
718
- if (meta.min != null && meta.max != null && meta.min === meta.max && !meta.minExclusive && !meta.maxExclusive) {
719
- return T.literal(meta.min);
720
- }
721
- return T.refine(T.number, createRangeRefinement(meta));
722
- }
723
- function isRange(tv) {
724
- if (tv.kind !== "refined") return false;
725
- const m = tv.refinement.meta;
726
- return m.min !== void 0 || m.max !== void 0 || m.minExclusive !== void 0 || m.maxExclusive !== void 0 || m.integer !== void 0;
727
- }
728
- function getRangeMeta(tv) {
729
- if (tv.kind !== "refined") return void 0;
730
- const m = tv.refinement.meta;
731
- if (m.min !== void 0 || m.max !== void 0 || m.minExclusive !== void 0 || m.maxExclusive !== void 0 || m.integer !== void 0) {
732
- return m;
733
- }
734
- return void 0;
735
- }
736
-
737
- // src/refinements/template.ts
738
- function tvTemplateViews(parts) {
739
- return viewTemplateParts(
740
- parts,
741
- (p) => p.kind === "literal" && typeof p.value === "string" ? { fixed: p.value } : { render: typeValueToString(p) }
742
- );
743
- }
744
- function formatTemplateName(parts) {
745
- return formatTemplateNameViews(tvTemplateViews(parts));
746
- }
747
- function normalizeParts(parts) {
748
- const merged = mergeAdjacentFixedViews(tvTemplateViews(parts), (text) => ({
749
- fixed: text,
750
- render: text,
751
- part: T.literal(text)
752
- }));
753
- const out = [];
754
- for (const { part: p } of merged) {
755
- const last = out[out.length - 1];
756
- if (last?.kind === "primitive" && last.type === "string" && p.kind === "primitive" && p.type === "string") {
757
- } else {
758
- out.push(p);
759
- }
760
- }
761
- return out;
762
- }
763
- function createTemplateRefinement(parts) {
764
- return {
765
- name: formatTemplateName(parts),
766
- meta: { parts },
767
- check(value) {
768
- if (typeof value !== "string") return false;
769
- return templateMatchesValue(value, tvTemplateViews(parts));
770
- },
771
- ops: {
772
- "+"(self, other) {
773
- return concatTemplates(self, other);
774
- }
775
- },
776
- methods: {
777
- startsWith(_self, args) {
778
- const arg = args[0];
779
- if (arg?.kind !== "literal" || typeof arg.value !== "string") return void 0;
780
- const parts2 = _self.refinement.meta.parts;
781
- const d = decideStartsWith(knownPrefixOfViews(tvTemplateViews(parts2)), arg.value);
782
- return d === "unknown" ? void 0 : T.literal(d);
783
- },
784
- endsWith(_self, args) {
785
- const arg = args[0];
786
- if (arg?.kind !== "literal" || typeof arg.value !== "string") return void 0;
787
- const parts2 = _self.refinement.meta.parts;
788
- const d = decideEndsWith(knownSuffixOfViews(tvTemplateViews(parts2)), arg.value);
789
- return d === "unknown" ? void 0 : T.literal(d);
790
- },
791
- includes(_self, args) {
792
- const arg = args[0];
793
- if (arg?.kind !== "literal" || typeof arg.value !== "string") return void 0;
794
- const parts2 = _self.refinement.meta.parts;
795
- const d = decideIncludes(allFixedTextOfViews(tvTemplateViews(parts2)), arg.value);
796
- return d === "unknown" ? void 0 : T.literal(d);
797
- }
798
- },
799
- properties: {
800
- length(_self) {
801
- const parts2 = _self.refinement.meta.parts;
802
- const hasAbstract = parts2.some((p) => p.kind !== "literal");
803
- if (!hasAbstract) return void 0;
804
- return createRange({ min: allFixedTextOfViews(tvTemplateViews(parts2)).length });
805
- }
806
- }
807
- };
808
- }
809
- function createTemplate(parts) {
810
- const normalized = normalizeParts(parts);
811
- if (normalized.length === 1 && normalized[0].kind === "literal") {
812
- return normalized[0];
813
- }
814
- if (normalized.length === 1 && normalized[0].kind === "primitive" && normalized[0].type === "string") {
815
- return T.string;
816
- }
817
- return T.refine(T.string, createTemplateRefinement(normalized));
818
- }
819
- function getTemplateParts(tv) {
820
- if (tv.kind === "refined" && Array.isArray(tv.refinement.meta.parts)) {
821
- return tv.refinement.meta.parts;
822
- }
823
- return void 0;
824
- }
825
- function concatTemplates(left, right) {
826
- const leftParts = getTemplateParts(left) ?? [left];
827
- const rightParts = getTemplateParts(right) ?? [right];
828
- return createTemplate([...leftParts, ...rightParts]);
829
- }
830
-
831
- // src/ops.ts
832
- function bothLiteral(l, r) {
833
- if (l.kind === "literal" && r.kind === "literal") {
834
- return { lv: l.value, rv: r.value };
835
- }
836
- return null;
837
- }
838
- function isNullishLiteral(tv) {
839
- return tv.kind === "literal" && (tv.value === null || tv.value === void 0);
840
- }
841
- function definitelyNotNullish(tv) {
842
- switch (tv.kind) {
843
- case "literal":
844
- return tv.value !== null && tv.value !== void 0;
845
- case "primitive":
846
- case "object":
847
- case "array":
848
- case "tuple":
849
- case "function":
850
- case "instance":
851
- case "promise":
852
- return true;
853
- case "refined":
854
- return definitelyNotNullish(tv.base);
855
- case "union":
856
- return tv.members.every(definitelyNotNullish);
857
- default:
858
- return false;
859
- }
860
- }
861
- var Ops = {
862
- add(left, right) {
863
- const lit3 = bothLiteral(left, right);
864
- if (lit3) {
865
- return T.literal(lit3.lv + lit3.rv);
866
- }
867
- const leftIsString = isSubtypeOf(left, T.string) || isTemplate(left);
868
- const rightIsString = isSubtypeOf(right, T.string) || isTemplate(right);
869
- if (leftIsString || rightIsString) {
870
- const hasStructure = left.kind === "literal" && typeof left.value === "string" || right.kind === "literal" && typeof right.value === "string" || isTemplate(left) || isTemplate(right);
871
- if (hasStructure) {
872
- return concatTemplates(left, right);
873
- }
874
- return T.string;
875
- }
876
- if (isSubtypeOf(left, T.number) && isSubtypeOf(right, T.number)) {
877
- return T.number;
878
- }
879
- return T.union(T.number, T.string);
880
- },
881
- strictEq(left, right) {
882
- const lit3 = bothLiteral(left, right);
883
- if (lit3) return T.literal(lit3.lv === lit3.rv);
884
- if (isNullishLiteral(right) && definitelyNotNullish(left) || isNullishLiteral(left) && definitelyNotNullish(right)) {
885
- return T.literal(false);
886
- }
887
- return T.boolean;
888
- },
889
- strictNeq(left, right) {
890
- const lit3 = bothLiteral(left, right);
891
- if (lit3) return T.literal(lit3.lv !== lit3.rv);
892
- if (isNullishLiteral(right) && definitelyNotNullish(left) || isNullishLiteral(left) && definitelyNotNullish(right)) {
893
- return T.literal(true);
894
- }
895
- return T.boolean;
896
- },
897
- gt(left, right) {
898
- const lit3 = bothLiteral(left, right);
899
- if (lit3) return T.literal(lit3.lv > lit3.rv);
900
- return T.boolean;
901
- },
902
- lt(left, right) {
903
- const lit3 = bothLiteral(left, right);
904
- if (lit3) return T.literal(lit3.lv < lit3.rv);
905
- return T.boolean;
906
- },
907
- gte(left, right) {
908
- const lit3 = bothLiteral(left, right);
909
- if (lit3) return T.literal(lit3.lv >= lit3.rv);
910
- return T.boolean;
911
- },
912
- lte(left, right) {
913
- const lit3 = bothLiteral(left, right);
914
- if (lit3) return T.literal(lit3.lv <= lit3.rv);
915
- return T.boolean;
916
- },
917
- not(operand) {
918
- if (operand.kind === "literal") return T.literal(!operand.value);
919
- return T.boolean;
920
- }
921
- };
922
- var binaryOpMap = {
923
- "+": Ops.add,
924
- "===": Ops.strictEq,
925
- "!==": Ops.strictNeq,
926
- ">": Ops.gt,
927
- "<": Ops.lt,
928
- ">=": Ops.gte,
929
- "<=": Ops.lte
930
- };
931
- function applyBinaryOp(op, left, right) {
932
- const fn2 = binaryOpMap[op];
933
- if (!fn2) return T.unknown;
934
- return fn2(left, right);
935
- }
936
- function dispatchBinaryOp(op, left, right) {
937
- if (left.kind === "refined" && left.refinement.ops?.[op]) {
938
- const result = left.refinement.ops[op](left, right);
939
- if (result !== void 0) return result;
940
- }
941
- if (right.kind === "refined" && right.refinement.ops?.[op]) {
942
- const result = right.refinement.ops[op](right, left);
943
- if (result !== void 0) return result;
944
- }
945
- const baseLeft = left.kind === "refined" ? left.base : left;
946
- const baseRight = right.kind === "refined" ? right.base : right;
947
- if (baseLeft !== left || baseRight !== right) {
948
- return dispatchBinaryOp(op, baseLeft, baseRight);
949
- }
950
- return applyBinaryOp(op, left, right);
951
- }
952
- function dispatchMethod(receiver, name, args) {
953
- if (receiver.kind === "refined" && receiver.refinement.methods?.[name]) {
954
- const result = receiver.refinement.methods[name](receiver, args);
955
- if (result !== void 0) return result;
956
- }
957
- if (receiver.kind === "refined") {
958
- return dispatchMethod(receiver.base, name, args);
959
- }
960
- return void 0;
961
- }
962
- function dispatchProperty(receiver, name) {
963
- if (receiver.kind === "refined" && receiver.refinement.properties?.[name]) {
964
- const result = receiver.refinement.properties[name](receiver);
965
- if (result !== void 0) return result;
966
- }
967
- if (receiver.kind === "refined") {
968
- return dispatchProperty(receiver.base, name);
969
- }
970
- return void 0;
971
- }
283
+ } from "./chunk-P3G2TODS.js";
972
284
 
973
285
  // src/environment.ts
974
286
  function createEnvironment(parent, bindings = /* @__PURE__ */ new Map()) {
@@ -978,7 +290,7 @@ function createEnvironment(parent, bindings = /* @__PURE__ */ new Map()) {
978
290
  const val = store.get(name);
979
291
  if (val !== void 0) return val;
980
292
  if (parent) return parent.lookup(name);
981
- return T.undefined;
293
+ return unknown;
982
294
  },
983
295
  bind(name, value) {
984
296
  store.set(name, value);
@@ -1041,7 +353,8 @@ stub.onSecondCall = function(value) {
1041
353
  return { kind: "mock-helper", onSecondCallValue: value };
1042
354
  };
1043
355
  stub.withArgs = function(...args) {
1044
- return { kind: "mock-helper", withArgsCases: [{ args, returnValue: T.unknown }] };
356
+ const unknownAbs = { shape: { k: "unknown" }, conf: "partial" };
357
+ return { kind: "mock-helper", withArgsCases: [{ args, returnValue: unknownAbs }] };
1045
358
  };
1046
359
  stub.callsFake = function(fn2) {
1047
360
  return { kind: "mock-helper", callsFakeImpl: fn2 };
@@ -1055,57 +368,6 @@ spy.returns = function(value) {
1055
368
  function mock() {
1056
369
  return { kind: "mock-helper" };
1057
370
  }
1058
- function mockArgMatches(declared, actual) {
1059
- if (actual === void 0) return false;
1060
- if (typeValueEquals(declared, actual)) return true;
1061
- if (declared.kind === "primitive" && actual.kind === "literal") {
1062
- const t = typeof actual.value;
1063
- return declared.type === "number" && t === "number" || declared.type === "string" && t === "string" || declared.type === "boolean" && t === "boolean" || declared.type === "bigint" && t === "bigint" || declared.type === "symbol" && t === "symbol";
1064
- }
1065
- return false;
1066
- }
1067
- function mockHelperToTypeValue(helper, env) {
1068
- if (helper.callsFakeImpl) {
1069
- if (helper.callsFakeImpl.kind === "function") {
1070
- return helper.callsFakeImpl;
1071
- }
1072
- const plain = T.fn(["...args"], { type: "BlockStatement", body: [] }, env);
1073
- plain._directReturn = helper.callsFakeImpl;
1074
- return plain;
1075
- }
1076
- let defaultReturn;
1077
- if (helper.resolvedValue) {
1078
- defaultReturn = T.promise(helper.resolvedValue);
1079
- } else if (helper.rejectedValue) {
1080
- defaultReturn = T.never;
1081
- } else if (helper.returnValue) {
1082
- defaultReturn = helper.returnValue;
1083
- } else if (helper.onFirstCallValue) {
1084
- defaultReturn = helper.onFirstCallValue;
1085
- } else {
1086
- defaultReturn = T.unknown;
1087
- }
1088
- if (helper.withArgsCases?.length) {
1089
- const cases = helper.withArgsCases;
1090
- return T.fnSig(
1091
- cases[0].args.map(() => T.unknown),
1092
- T.union(...cases.map((c) => c.returnValue), defaultReturn),
1093
- T.never,
1094
- (args) => {
1095
- for (const c of cases) {
1096
- if (c.args.every((a, i) => mockArgMatches(a, args[i]))) {
1097
- return c.returnValue;
1098
- }
1099
- }
1100
- return defaultReturn;
1101
- }
1102
- );
1103
- }
1104
- const body = { type: "BlockStatement", body: [] };
1105
- const fn2 = T.fn(["...args"], body, env);
1106
- fn2._directReturn = defaultReturn;
1107
- return fn2;
1108
- }
1109
371
 
1110
372
  // src/algebra/phi.ts
1111
373
  var phiStack = [pTrue];
@@ -1541,6 +803,46 @@ function constraintToEntryAbs(c, paramName) {
1541
803
  }
1542
804
  return constraintOnTermAbs(c, t);
1543
805
  }
806
+ function memberLitValue(m) {
807
+ const leaves = [];
808
+ const visit = (p2) => {
809
+ if (p2.op === "and") {
810
+ p2.args.forEach(visit);
811
+ return;
812
+ }
813
+ leaves.push(p2);
814
+ };
815
+ m.preds.forEach(visit);
816
+ if (leaves.length !== 1) return void 0;
817
+ const p = leaves[0];
818
+ if (p.op !== "eq") return void 0;
819
+ if (p.a.op === "var" && p.b.op === "lit") return p.b.value;
820
+ if (p.b.op === "var" && p.a.op === "lit") return p.a.value;
821
+ return void 0;
822
+ }
823
+ function samePrimLiteralUnionAbs(members, t) {
824
+ if (members.length === 0) return void 0;
825
+ const values = [];
826
+ let prim;
827
+ for (const m of members) {
828
+ const v2 = memberLitValue(m);
829
+ if (v2 === void 0) return void 0;
830
+ if (v2 === null) return void 0;
831
+ const mp = m.prim ?? (typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : "boolean");
832
+ if (prim === void 0) prim = mp;
833
+ else if (prim !== mp) return void 0;
834
+ values.push(v2);
835
+ }
836
+ if (prim === void 0) return void 0;
837
+ const uniq = [];
838
+ for (const v2 of values) {
839
+ if (!uniq.some((u) => Object.is(u, v2))) uniq.push(v2);
840
+ }
841
+ const disj = or(
842
+ ...uniq.map((v2) => eq(t, lit(v2)))
843
+ );
844
+ return abs({ k: "prim", type: prim }, t, disj, "path");
845
+ }
1544
846
  function constraintOnTermAbs(c, t) {
1545
847
  if (c.fields) {
1546
848
  const slots = {};
@@ -1553,6 +855,8 @@ function constraintOnTermAbs(c, t) {
1553
855
  return abs({ k: "obj", slots }, t, void 0, "path");
1554
856
  }
1555
857
  if (c.members) {
858
+ const litUnion = samePrimLiteralUnionAbs(c.members, t);
859
+ if (litUnion) return litUnion;
1556
860
  const joined = c.members.map((m) => constraintOnTermAbs(m, t)).reduce((a, b) => joinAbs(a, b));
1557
861
  if (joined.shape.k === "prim" && joined.pred === void 0 && c.members.every((m) => m.prim === joined.shape.type)) {
1558
862
  const type = joined.shape.type;
@@ -2304,7 +1608,9 @@ function generatedExportNames(sidecarSrc) {
2304
1608
  } catch {
2305
1609
  return out;
2306
1610
  }
2307
- for (const stmt of ast.program.body) {
1611
+ const stmts = ast.program.body;
1612
+ for (let i = 0; i < stmts.length; i++) {
1613
+ const stmt = stmts[i];
2308
1614
  if (stmt.type !== "ExportNamedDeclaration") continue;
2309
1615
  if (stmt.source) continue;
2310
1616
  const d = stmt.declaration;
@@ -2318,25 +1624,26 @@ function generatedExportNames(sidecarSrc) {
2318
1624
  if (d.id) names.push(d.id.name);
2319
1625
  }
2320
1626
  if (names.length === 0) continue;
2321
- if (leadingCommentHas(stmt.start, sidecarSrc)) {
1627
+ if (regionHasGeneratedMarker(stmts, i, sidecarSrc)) {
2322
1628
  for (const n of names) out.add(n);
2323
1629
  }
2324
1630
  }
2325
1631
  return out;
2326
1632
  }
2327
- function leadingCommentHas(pos, src) {
2328
- const lines = src.slice(0, pos).replace(/\n$/, "").split("\n");
2329
- for (let i = lines.length - 1; i >= 0; i--) {
2330
- const line = lines[i].trim();
2331
- if (line === "") break;
2332
- if (line === "*/") continue;
2333
- if (line.startsWith("//") || line.startsWith("/*") || line.startsWith("*")) {
2334
- if (/@generated/.test(line)) return true;
2335
- continue;
2336
- }
1633
+ function regionHasGeneratedMarker(stmts, exportIdx, src) {
1634
+ const exportStart = stmts[exportIdx].start;
1635
+ if (exportStart == null) return false;
1636
+ let regionStart = 0;
1637
+ for (let j = exportIdx - 1; j >= 0; j--) {
1638
+ const prev = stmts[j];
1639
+ if (prev.type === "ImportDeclaration" || prev.type === "VariableDeclaration") continue;
1640
+ regionStart = prev.end ?? 0;
2337
1641
  break;
2338
1642
  }
2339
- return false;
1643
+ return src.slice(regionStart, exportStart).split("\n").some((line) => {
1644
+ const t = line.trim();
1645
+ return (t.startsWith("//") || t.startsWith("/*") || t.startsWith("*")) && /@generated/.test(t);
1646
+ });
2340
1647
  }
2341
1648
  function sidecarAutoBindAllowed(sidecarPath, autoBind) {
2342
1649
  if (isNodeModulesPath(sidecarPath)) return false;
@@ -3074,14 +2381,14 @@ function generalizeMemoSet(key, value, depPaths) {
3074
2381
  function isCacheableAbs(a) {
3075
2382
  return a.conf === "exact" || a.conf === "path" || a.conf === "widened" || a.conf === "mock";
3076
2383
  }
3077
- function termKey(t, rename) {
2384
+ function termKey2(t, rename) {
3078
2385
  switch (t.op) {
3079
2386
  case "lit":
3080
2387
  return `L:${typeof t.value}:${String(t.value)}`;
3081
2388
  case "var":
3082
2389
  return `V:${rename?.get(t.id) ?? t.id}`;
3083
2390
  case "app":
3084
- return `A:${t.fn}(${t.args.map((a) => termKey(a, rename)).join(",")})`;
2391
+ return `A:${t.fn}(${t.args.map((a) => termKey2(a, rename)).join(",")})`;
3085
2392
  }
3086
2393
  }
3087
2394
  function predKey(p, rename) {
@@ -3096,7 +2403,7 @@ function predKey(p, rename) {
3096
2403
  case "le":
3097
2404
  case "gt":
3098
2405
  case "ge":
3099
- return `${p.op}(${termKey(p.a, rename)},${termKey(p.b, rename)})`;
2406
+ return `${p.op}(${termKey2(p.a, rename)},${termKey2(p.b, rename)})`;
3100
2407
  case "and":
3101
2408
  case "or": {
3102
2409
  const keys = p.args.map((a) => predKey(a, rename)).sort();
@@ -3105,7 +2412,7 @@ function predKey(p, rename) {
3105
2412
  case "not":
3106
2413
  return `not(${predKey(p.arg, rename)})`;
3107
2414
  case "typeof":
3108
- return `typeof(${termKey(p.t, rename)},${p.type})`;
2415
+ return `typeof(${termKey2(p.t, rename)},${p.type})`;
3109
2416
  }
3110
2417
  }
3111
2418
  function shapeKey(s, seen, rename) {
@@ -3150,7 +2457,7 @@ function shapeKey(s, seen, rename) {
3150
2457
  function absKeyInner(a, seen, rename) {
3151
2458
  if (seen.has(a)) return "cycle";
3152
2459
  seen.add(a);
3153
- const t = a.term ? `=${termKey(a.term, rename)}` : "";
2460
+ const t = a.term ? `=${termKey2(a.term, rename)}` : "";
3154
2461
  const p = a.pred ? `@${predKey(a.pred, rename)}` : "";
3155
2462
  return `${shapeKey(a.shape, seen, rename)}${t}${p}`;
3156
2463
  }
@@ -3530,9 +2837,8 @@ function formatPoly(name, params, typeParams, symbolic, entryReqs, entryShapes,
3530
2837
  return `${p}: ${id}`;
3531
2838
  }).join(", ");
3532
2839
  const ret = formatShapeSlot(symbolic);
3533
- const termPart = symbolic.term && symbolic.term.op !== "lit" ? ` = ${termToString(symbolic.term)}` : "";
3534
2840
  const predPart = symbolic.pred && symbolic.pred.op !== "true" ? ` where ${predToString(symbolic.pred)}` : "";
3535
- return `${name}: (${ps}) => ${ret}${termPart}${predPart}`;
2841
+ return `${name}: (${ps}) => ${ret}${predPart}`;
3536
2842
  }
3537
2843
  function generalizeAll(source, opts = {}) {
3538
2844
  const file = parseSource(source);
@@ -3849,7 +3155,7 @@ function boundsSatisfiable(bounds) {
3849
3155
  loStrict = true;
3850
3156
  }
3851
3157
  } else if (b.op === "ge") {
3852
- if (b.n > lo || b.n === lo && loStrict) {
3158
+ if (b.n > lo) {
3853
3159
  lo = b.n;
3854
3160
  loStrict = false;
3855
3161
  }
@@ -3859,7 +3165,7 @@ function boundsSatisfiable(bounds) {
3859
3165
  hiStrict = true;
3860
3166
  }
3861
3167
  } else if (b.op === "le") {
3862
- if (b.n < hi || b.n === hi && hiStrict) {
3168
+ if (b.n < hi) {
3863
3169
  hi = b.n;
3864
3170
  hiStrict = false;
3865
3171
  }
@@ -4189,281 +3495,6 @@ function isLengthSelf(t) {
4189
3495
  return t.op === "app" && t.fn === "length" && t.args.length === 1 && isSelfVar(t.args[0]);
4190
3496
  }
4191
3497
 
4192
- // src/algebra/bridge.ts
4193
- var confByTv = /* @__PURE__ */ new WeakMap();
4194
- function setTvConfidence(tv, conf) {
4195
- if (tv && typeof tv === "object") confByTv.set(tv, conf);
4196
- }
4197
- function getTvConfidence(tv) {
4198
- if (tv && typeof tv === "object") return confByTv.get(tv);
4199
- return void 0;
4200
- }
4201
- function absToTypeValue(a) {
4202
- let conf = a.conf;
4203
- let result;
4204
- switch (a.shape.k) {
4205
- case "never":
4206
- result = T.never;
4207
- break;
4208
- case "unknown":
4209
- if (a.term?.op === "lit" && a.term.value === null) {
4210
- result = T.literal(null);
4211
- break;
4212
- }
4213
- result = T.unknown;
4214
- break;
4215
- case "any":
4216
- result = T.unknown;
4217
- break;
4218
- case "prim": {
4219
- const lv = litValue(a);
4220
- if (lv !== void 0) {
4221
- result = T.literal(lv);
4222
- break;
4223
- }
4224
- if (isTemplateLike(a) && a.shape.k === "prim" && a.shape.type === "string") {
4225
- const parts = templatePartsOf(a).map(absToTypeValue);
4226
- result = createTemplate(parts);
4227
- break;
4228
- }
4229
- const prim = primToT(a.shape.type);
4230
- if (a.pred && a.pred.op !== "true") {
4231
- const refined = tryEncodeRefined(prim, a);
4232
- if (refined) {
4233
- result = refined;
4234
- } else {
4235
- result = prim;
4236
- conf = confJoin(conf, "widened");
4237
- }
4238
- } else {
4239
- result = prim;
4240
- if (a.term && a.term.op !== "lit") conf = confJoin(conf, "widened");
4241
- }
4242
- break;
4243
- }
4244
- case "obj": {
4245
- const props = {};
4246
- for (const [k, slot] of Object.entries(a.shape.slots)) {
4247
- let v2 = absToTypeValue(slot.value);
4248
- if (slot.optional) {
4249
- v2 = T.union(v2, T.undefined);
4250
- }
4251
- props[k] = v2;
4252
- }
4253
- result = T.object(props);
4254
- if (a.shape.open) conf = confJoin(conf, "widened");
4255
- break;
4256
- }
4257
- case "arr":
4258
- result = T.array(absToTypeValue(a.shape.element));
4259
- break;
4260
- case "tuple":
4261
- result = T.tuple(a.shape.elements.map(absToTypeValue));
4262
- break;
4263
- case "fn": {
4264
- const body = { type: "BlockStatement", body: [], directives: [] };
4265
- result = T.fn(a.shape.params, body, null);
4266
- break;
4267
- }
4268
- case "brand":
4269
- result = T.instanceOf(a.shape.name, brandProps(a.shape.shape));
4270
- break;
4271
- case "eff":
4272
- result = T.promise(absToTypeValue(a.shape.inner));
4273
- break;
4274
- case "sum":
4275
- result = T.union(...a.shape.members.map(absToTypeValue));
4276
- break;
4277
- default:
4278
- result = T.unknown;
4279
- conf = confJoin(conf, "partial");
4280
- }
4281
- setTvConfidence(result, conf);
4282
- return result;
4283
- }
4284
- function primToT(type) {
4285
- switch (type) {
4286
- case "number":
4287
- return T.number;
4288
- case "string":
4289
- return T.string;
4290
- case "boolean":
4291
- return T.boolean;
4292
- case "bigint":
4293
- return T.bigint;
4294
- case "symbol":
4295
- return T.symbol;
4296
- default:
4297
- return T.unknown;
4298
- }
4299
- }
4300
- function brandProps(shape2) {
4301
- if (shape2.shape.k === "obj") {
4302
- const out = {};
4303
- for (const [k, slot] of Object.entries(shape2.shape.slots)) {
4304
- out[k] = absToTypeValue(slot.value);
4305
- }
4306
- return out;
4307
- }
4308
- return {};
4309
- }
4310
- function tryEncodeRefined(base, a) {
4311
- if (base.kind !== "primitive" || base.type !== "number") return void 0;
4312
- const p = a.pred;
4313
- if (!p) return void 0;
4314
- if ((p.op === "gt" || p.op === "ge" || p.op === "lt" || p.op === "le") && p.b.op === "lit" && typeof p.b.value === "number") {
4315
- const n = p.b.value;
4316
- const op = p.op;
4317
- const check = (value) => {
4318
- if (typeof value !== "number") return false;
4319
- switch (op) {
4320
- case "gt":
4321
- return value > n;
4322
- case "ge":
4323
- return value >= n;
4324
- case "lt":
4325
- return value < n;
4326
- case "le":
4327
- return value <= n;
4328
- }
4329
- };
4330
- const opSym = op === "gt" ? ">" : op === "ge" ? ">=" : op === "lt" ? "<" : "<=";
4331
- return T.refine(base, {
4332
- name: `number (${opSym} ${n})`,
4333
- meta: { op, n, pred: predToString(p) },
4334
- check
4335
- });
4336
- }
4337
- return void 0;
4338
- }
4339
- function typeValueToAbs(tv) {
4340
- if (!tv) return abs({ k: "unknown" }, void 0, void 0, "partial");
4341
- const confOr = (fallback) => getTvConfidence(tv) ?? fallback;
4342
- switch (tv.kind) {
4343
- case "never":
4344
- return abs({ k: "never" }, void 0, void 0, confOr("exact"));
4345
- case "unknown":
4346
- return abs(
4347
- { k: "unknown" },
4348
- void 0,
4349
- void 0,
4350
- confOr("partial")
4351
- );
4352
- case "literal":
4353
- if (typeof tv.value === "bigint") {
4354
- return abs(
4355
- { k: "prim", type: "bigint" },
4356
- void 0,
4357
- void 0,
4358
- confOr("exact")
4359
- );
4360
- }
4361
- return abs(
4362
- shapeOfLit(tv.value),
4363
- lit(tv.value),
4364
- pTrue,
4365
- confOr("exact")
4366
- );
4367
- case "primitive":
4368
- return abs({ k: "prim", type: tv.type }, void 0, void 0, confOr("exact"));
4369
- case "refined": {
4370
- const tplParts = getTemplateParts(tv);
4371
- if (tplParts) {
4372
- return createTemplateAbs(tplParts.map(typeValueToAbs));
4373
- }
4374
- const base = typeValueToAbs(tv.base);
4375
- const decoded = tryDecodeRefinedPred(tv, base.term);
4376
- return abs(
4377
- base.shape,
4378
- base.term ?? (decoded ? v("_r") : void 0),
4379
- decoded ?? base.pred,
4380
- confOr(confJoin(base.conf, "path"))
4381
- );
4382
- }
4383
- case "object": {
4384
- const slots = {};
4385
- for (const [k, v2] of Object.entries(tv.properties)) {
4386
- slots[k] = { value: typeValueToAbs(v2) };
4387
- }
4388
- return abs({ k: "obj", slots }, void 0, void 0, confOr("exact"));
4389
- }
4390
- case "array":
4391
- return abs(
4392
- { k: "arr", element: typeValueToAbs(tv.element) },
4393
- void 0,
4394
- void 0,
4395
- confOr("exact")
4396
- );
4397
- case "tuple":
4398
- return abs(
4399
- { k: "tuple", elements: tv.elements.map(typeValueToAbs) },
4400
- void 0,
4401
- void 0,
4402
- confOr("exact")
4403
- );
4404
- case "function": {
4405
- const params = tv.params ?? [];
4406
- return abs({ k: "fn", params }, void 0, void 0, confOr("exact"));
4407
- }
4408
- case "promise":
4409
- return abs(
4410
- { k: "eff", eff: "promise", inner: typeValueToAbs(tv.value) },
4411
- void 0,
4412
- void 0,
4413
- confOr("exact")
4414
- );
4415
- case "instance": {
4416
- const slots = {};
4417
- for (const [k, v2] of Object.entries(tv.properties ?? {})) {
4418
- slots[k] = { value: typeValueToAbs(v2) };
4419
- }
4420
- const inner = abs({ k: "obj", slots }, void 0, void 0, confOr("exact"));
4421
- return abs(
4422
- { k: "brand", name: tv.className, shape: inner },
4423
- void 0,
4424
- void 0,
4425
- confOr("exact")
4426
- );
4427
- }
4428
- case "union":
4429
- return abs(
4430
- { k: "sum", members: tv.members.map(typeValueToAbs) },
4431
- void 0,
4432
- void 0,
4433
- confOr("path")
4434
- );
4435
- default:
4436
- return abs({ k: "unknown" }, void 0, void 0, confOr("partial"));
4437
- }
4438
- }
4439
- function tryDecodeRefinedPred(tv, term) {
4440
- if (tv.kind !== "refined") return void 0;
4441
- const meta = tv.refinement.meta;
4442
- const op = meta?.op;
4443
- const n = meta?.n;
4444
- if (typeof n !== "number") return void 0;
4445
- if (op !== "gt" && op !== "ge" && op !== "lt" && op !== "le") return void 0;
4446
- const t = term ?? v("_r");
4447
- const b = lit(n);
4448
- switch (op) {
4449
- case "gt":
4450
- return gt(t, b);
4451
- case "ge":
4452
- return ge(t, b);
4453
- case "lt":
4454
- return lt(t, b);
4455
- case "le":
4456
- return le(t, b);
4457
- }
4458
- }
4459
- function shapeOfLit(v2) {
4460
- if (typeof v2 === "number") return { k: "prim", type: "number" };
4461
- if (typeof v2 === "string") return { k: "prim", type: "string" };
4462
- if (typeof v2 === "boolean") return { k: "prim", type: "boolean" };
4463
- if (typeof v2 === "bigint") return { k: "prim", type: "bigint" };
4464
- return { k: "unknown" };
4465
- }
4466
-
4467
3498
  // src/algebra/scan.ts
4468
3499
  function hofFnArgOk(src, tgt) {
4469
3500
  if (src.shape.k !== "fn") return false;
@@ -5670,9 +4701,13 @@ function evidenceToString(v2) {
5670
4701
  return typeof v2 === "string" ? JSON.stringify(v2) : String(v2);
5671
4702
  }
5672
4703
  function checkInjectedDomainEvidence(fnName, source, records, opts) {
5673
- const usable = records.filter(
5674
- (r) => !(r.resultType?.kind === "never" && r.throws?.kind === "never")
5675
- );
4704
+ const isLeaked = (r) => {
4705
+ if (r.resultAbs && r.throwsAbs) {
4706
+ return r.resultAbs.shape.k === "never" && r.throwsAbs.shape.k === "never";
4707
+ }
4708
+ return false;
4709
+ };
4710
+ const usable = records.filter((r) => !isLeaked(r));
5676
4711
  if (usable.length === 0) return [];
5677
4712
  let ei;
5678
4713
  try {
@@ -5701,15 +4736,9 @@ function checkInjectedDomainEvidence(fnName, source, records, opts) {
5701
4736
  if (idx < 0) continue;
5702
4737
  const failures = [];
5703
4738
  for (const rec of usable) {
5704
- const arg = rec.argTypes[idx];
5705
- if (!arg || arg.kind !== "literal") continue;
5706
- const v2 = arg.value;
5707
- if (typeof v2 !== "number" && typeof v2 !== "string" && typeof v2 !== "boolean") {
5708
- continue;
5709
- }
5710
- const conf = getTvConfidence(arg);
5711
- if (conf !== void 0 && conf !== "exact" && conf !== "path") continue;
5712
- if (!literalMeetsConstraint(v2, constraint)) failures.push(v2);
4739
+ const lit3 = extractLiteralEvidence(rec, idx);
4740
+ if (lit3 === void 0) continue;
4741
+ if (!literalMeetsConstraint(lit3, constraint)) failures.push(lit3);
5713
4742
  }
5714
4743
  if (failures.length === 0) continue;
5715
4744
  const shown = [...new Set(failures)].map(evidenceToString).join(", ");
@@ -5727,6 +4756,16 @@ function checkInjectedDomainEvidence(fnName, source, records, opts) {
5727
4756
  }
5728
4757
  return out;
5729
4758
  }
4759
+ function extractLiteralEvidence(rec, idx) {
4760
+ const absArg = rec.argAbs?.[idx];
4761
+ if (!absArg) return void 0;
4762
+ if (absArg.conf !== "exact" && absArg.conf !== "path") return void 0;
4763
+ const lv = litValue(absArg);
4764
+ if (typeof lv === "number" || typeof lv === "string" || typeof lv === "boolean") {
4765
+ return lv;
4766
+ }
4767
+ return void 0;
4768
+ }
5730
4769
 
5731
4770
  // src/algebra/check.ts
5732
4771
  var checkReportMemo = /* @__PURE__ */ new Map();
@@ -6046,14 +5085,14 @@ function checkSourceInner(filePath, source, file, phi, opts, issues, signatures,
6046
5085
  const varAbs = /* @__PURE__ */ new Map();
6047
5086
  const callRecords = [];
6048
5087
  setAbsAssignCollector((r) => records.push(r));
6049
- setAbsCallCollector((r) => callRecords.push(r));
5088
+ const prevCallCollector = setAbsCallCollector((r) => callRecords.push(r));
6050
5089
  try {
6051
5090
  const { env } = evalProgramAbs(source, { file });
6052
5091
  for (const [k, v2] of env.vars) varAbs.set(k, v2);
6053
5092
  } catch {
6054
5093
  } finally {
6055
5094
  setAbsAssignCollector(null);
6056
- setAbsCallCollector(null);
5095
+ setAbsCallCollector(prevCallCollector);
6057
5096
  }
6058
5097
  const callIssues = canSkipLiteralCallScan(source, file) ? [] : scanLiteralCalls(source, names, phi, {
6059
5098
  loadModule: opts.loadModule,
@@ -6676,7 +5715,7 @@ function collectAbsInlays(source, refineOpts) {
6676
5715
  function denoteGuard(a, v2) {
6677
5716
  const lv = litValue(a);
6678
5717
  if (lv !== void 0 && (!a.pred || a.pred.op === "true")) {
6679
- return `${v2} === ${JSON.stringify(lv)}`;
5718
+ return eqGuard(v2, lv);
6680
5719
  }
6681
5720
  const shape2 = denoteShape(a.shape, v2);
6682
5721
  const pred = denotePred(a, v2);
@@ -6755,7 +5794,7 @@ function denotePred(a, v2) {
6755
5794
  const p = a.pred;
6756
5795
  if (!p || p.op === "true") {
6757
5796
  const lv = litValue(a);
6758
- if (lv !== void 0) return `${v2} === ${JSON.stringify(lv)}`;
5797
+ if (lv !== void 0) return eqGuard(v2, lv);
6759
5798
  return "true";
6760
5799
  }
6761
5800
  return predAsJs(p, v2, a);
@@ -6784,15 +5823,15 @@ function predAsJs(p, v2, a) {
6784
5823
  const leftIsValue = termIsValue(p.a, a);
6785
5824
  const rightLit = litOfTerm(p.b);
6786
5825
  if (leftIsValue && rightLit !== void 0) {
6787
- return `${v2} ${op} ${JSON.stringify(rightLit)}`;
5826
+ return cmpOp(v2, op, rightLit);
6788
5827
  }
6789
5828
  const leftLit = litOfTerm(p.a);
6790
5829
  const rightIsValue = termIsValue(p.b, a);
6791
5830
  if (rightIsValue && leftLit !== void 0) {
6792
- return `${JSON.stringify(leftLit)} ${op} ${v2}`;
5831
+ return cmpLitValue(leftLit, op, v2);
6793
5832
  }
6794
5833
  if (leftLit !== void 0 && rightLit !== void 0) {
6795
- return `${JSON.stringify(leftLit)} ${op} ${JSON.stringify(rightLit)}`;
5834
+ return `${jsLit(leftLit)} ${op} ${jsLit(rightLit)}`;
6796
5835
  }
6797
5836
  return "true";
6798
5837
  }
@@ -6803,6 +5842,35 @@ function predAsJs(p, v2, a) {
6803
5842
  function litOfTerm(t) {
6804
5843
  return t.op === "lit" ? t.value : void 0;
6805
5844
  }
5845
+ function jsLit(v2) {
5846
+ if (v2 === void 0) return "undefined";
5847
+ if (v2 === null) return "null";
5848
+ if (typeof v2 === "number") {
5849
+ if (Number.isNaN(v2)) return "NaN";
5850
+ if (v2 === Infinity) return "Infinity";
5851
+ if (v2 === -Infinity) return "-Infinity";
5852
+ return String(v2);
5853
+ }
5854
+ return JSON.stringify(v2);
5855
+ }
5856
+ function eqGuard(v2, lv) {
5857
+ if (typeof lv === "number" && Number.isNaN(lv)) return `Number.isNaN(${v2})`;
5858
+ return `${v2} === ${jsLit(lv)}`;
5859
+ }
5860
+ function cmpOp(v2, op, lit3) {
5861
+ if (typeof lit3 === "number" && Number.isNaN(lit3)) {
5862
+ if (op === "===") return `Number.isNaN(${v2})`;
5863
+ if (op === "!==") return `!Number.isNaN(${v2})`;
5864
+ }
5865
+ return `${v2} ${op} ${jsLit(lit3)}`;
5866
+ }
5867
+ function cmpLitValue(lit3, op, v2) {
5868
+ if (typeof lit3 === "number" && Number.isNaN(lit3)) {
5869
+ if (op === "===") return `Number.isNaN(${v2})`;
5870
+ if (op === "!==") return `!Number.isNaN(${v2})`;
5871
+ }
5872
+ return `${jsLit(lit3)} ${op} ${v2}`;
5873
+ }
6806
5874
  function termIsValue(t, a) {
6807
5875
  if (t.op === "var") return true;
6808
5876
  if (t.op === "lit") {
@@ -6873,30 +5941,30 @@ export {
6873
5941
  MAX_TOTAL_CALLS,
6874
5942
  NudoSidecarError,
6875
5943
  NudoThrow,
6876
- Ops,
6877
5944
  SELF,
6878
- T,
5945
+ abortDerivationSession,
6879
5946
  abs,
6880
5947
  absFunction,
5948
+ absShapeKey,
6881
5949
  absTemplateViews,
6882
5950
  absToConstraint,
6883
5951
  absToString,
6884
- absToTypeValue,
6885
5952
  add,
6886
5953
  allFixedTextOfViews,
6887
5954
  alphaOf,
6888
5955
  analyzeFn,
5956
+ analyzeFnFull,
6889
5957
  and,
6890
5958
  anyVar,
6891
5959
  app,
6892
5960
  applyAbsFn,
6893
- applyBinaryOp,
6894
5961
  applyCallbackAbs,
6895
5962
  array,
6896
5963
  asAbs,
6897
5964
  asAbsVal,
6898
5965
  attachFnImpl,
6899
5966
  awaitAbs,
5967
+ beginDerivationSession,
6900
5968
  betaOf,
6901
5969
  bindImports,
6902
5970
  bool,
@@ -6905,6 +5973,7 @@ export {
6905
5973
  buildArgsFromAssume,
6906
5974
  callAbsMethod,
6907
5975
  callFunction,
5976
+ callFunctionFull,
6908
5977
  callTranspiledExport,
6909
5978
  callTranspiledExportFull,
6910
5979
  canSkipLiteralCallScan,
@@ -6916,37 +5985,31 @@ export {
6916
5985
  clearBClasses,
6917
5986
  cmp,
6918
5987
  coerceAsyncReturn,
6919
- collapseLiteralUnion,
6920
5988
  collectAbsExports,
6921
5989
  collectAbsInlays,
6922
5990
  collectAbsNodeTypes,
6923
5991
  concatString,
6924
- concatTemplates,
6925
5992
  confJoin,
6926
5993
  constraintToEntryAbs,
6927
5994
  createEnvironment,
6928
5995
  createHofCollectCtx,
6929
- createRange,
6930
- createTemplate,
6931
5996
  createTemplateAbs,
6932
5997
  currentExecPhi,
6933
5998
  currentPhi,
6934
5999
  decideEndsWith,
6935
6000
  decideIncludes,
6936
6001
  decideStartsWith,
6937
- deepCloneTypeValue,
6938
6002
  defaultLeakBudget,
6939
6003
  defineClass,
6940
6004
  definitelyNotNullishShape,
6941
6005
  denoteGuard,
6006
+ derivationChain,
6942
6007
  describePhi,
6943
- dispatchBinaryOp,
6944
- dispatchMethod,
6945
- dispatchProperty,
6946
6008
  div,
6947
6009
  effectiveInterface,
6948
6010
  emptyEnv,
6949
6011
  emptyPhi,
6012
+ endDerivationSession,
6950
6013
  eq,
6951
6014
  evalArrayStatic,
6952
6015
  evalBuiltinInstanceMethod,
@@ -7004,20 +6067,16 @@ export {
7004
6067
  getBClass,
7005
6068
  getClass,
7006
6069
  getClassChain,
6070
+ getDerivation,
7007
6071
  getFnImpl,
7008
6072
  getFnNameAndBodies,
7009
- getFnSig,
7010
6073
  getGeneralizeMemoSize,
7011
6074
  getParseSourceCacheSize,
7012
- getPrimitiveTypeOf,
7013
- getRangeMeta,
7014
- getRefinedBase,
7015
6075
  getSlot,
7016
- getTemplateParts,
7017
6076
  getTerm,
7018
- getTvConfidence,
7019
6077
  gt,
7020
6078
  gtNum,
6079
+ hasDerivationSession,
7021
6080
  hashSource,
7022
6081
  implies,
7023
6082
  instanceOf,
@@ -7028,7 +6087,6 @@ export {
7028
6087
  isDefinitelyFalse,
7029
6088
  isDefinitelyTrue,
7030
6089
  isExactLit,
7031
- isFnSig,
7032
6090
  isIntFlag,
7033
6091
  isNodeModulesPath,
7034
6092
  isNudoConstraint,
@@ -7036,11 +6094,8 @@ export {
7036
6094
  isNullishLitAbs,
7037
6095
  isNumPrim,
7038
6096
  isObj,
7039
- isRange,
7040
6097
  isRelFn,
7041
6098
  isStrPrim,
7042
- isSubtypeOf,
7043
- isTemplate,
7044
6099
  isTemplateLike,
7045
6100
  joinAbs,
7046
6101
  joinFunctions,
@@ -7071,19 +6126,18 @@ export {
7071
6126
  matchRelIdentLit,
7072
6127
  maybeLeak,
7073
6128
  mergeAdjacentFixedViews,
7074
- mergeObjectProperties,
7075
6129
  mock,
7076
- mockHelperToTypeValue,
7077
6130
  mod,
7078
6131
  mul,
7079
6132
  namespaceNameOf,
7080
- narrowType,
7081
6133
  ne,
7082
6134
  negAbs,
7083
6135
  never,
7084
6136
  normPath,
7085
6137
  not,
7086
6138
  notAbs,
6139
+ noteDerivationAdd,
6140
+ noteDerivationJoin,
7087
6141
  noteMemberDispatchMiss,
7088
6142
  notePrimMemberMissing,
7089
6143
  noteUnknownMemberMissing,
@@ -7106,6 +6160,7 @@ export {
7106
6160
  predToString,
7107
6161
  predVars,
7108
6162
  projectBrand,
6163
+ projectDerivationDsl,
7109
6164
  projectFlatMapResult,
7110
6165
  promoteParamShape,
7111
6166
  ptypeof,
@@ -7135,10 +6190,11 @@ export {
7135
6190
  setAbsTruncationCollector,
7136
6191
  setApplyCallbackHost,
7137
6192
  setBCallCollector,
6193
+ setDerivation,
6194
+ setDerivationCollector,
7138
6195
  setInterfaceDiagCollector,
7139
6196
  setMemberDiagCollector,
7140
6197
  setRefineDiagCollector,
7141
- setTvConfidence,
7142
6198
  shape,
7143
6199
  shapeOfTerm,
7144
6200
  shapeOnlyFn,
@@ -7147,7 +6203,6 @@ export {
7147
6203
  sidecarPathOf,
7148
6204
  sidecarSpecsOf,
7149
6205
  simplifyTerm,
7150
- simplifyUnion,
7151
6206
  snapshotAbs,
7152
6207
  spread,
7153
6208
  spy,
@@ -7162,9 +6217,9 @@ export {
7162
6217
  substAbs,
7163
6218
  substPred,
7164
6219
  substPredAbs,
7165
- subtractType,
7166
6220
  superNameOf,
7167
6221
  tagAbsOrigin,
6222
+ tagDerivationRoot,
7168
6223
  takeInterfaceDiags,
7169
6224
  takeInterfaceDiagsSince,
7170
6225
  takeRefineDiags,
@@ -7173,6 +6228,7 @@ export {
7173
6228
  templatePartsOf,
7174
6229
  termDepth,
7175
6230
  termEquals,
6231
+ termKey,
7176
6232
  termNodes,
7177
6233
  termToString,
7178
6234
  transpile,
@@ -7184,16 +6240,12 @@ export {
7184
6240
  tryPromoteForOfIteratee,
7185
6241
  tryPromoteHofCallback,
7186
6242
  tryPromoteReceiverAsArr,
7187
- typeValueEquals,
7188
- typeValueToAbs,
7189
- typeValueToString,
7190
6243
  typeofAbs,
7191
6244
  undefAbs,
7192
6245
  union,
7193
6246
  unknown,
7194
6247
  v,
7195
6248
  viewTemplateParts,
7196
- widenLiteral,
7197
6249
  withExecPhi,
7198
6250
  withPhiConstraint,
7199
6251
  withVar,