@nudojs/core 1.7.10 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-MJP4P5J3.js → chunk-3SLNJPNY.js} +1472 -427
- package/dist/{chunk-45WFXDZD.js → chunk-UDIJKTYG.js} +80 -716
- package/dist/exec.d.ts +9 -1
- package/dist/exec.js +3 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +180 -64
- package/dist/internal.d.ts +2 -2
- package/dist/internal.js +2 -2
- package/dist/{projection-budget-CtwnzYLG.d.ts → projection-budget-vi5Ssjdr.d.ts} +37 -8
- package/package.json +1 -1
|
@@ -12,7 +12,7 @@ var lit = (value) => ({
|
|
|
12
12
|
value
|
|
13
13
|
});
|
|
14
14
|
var v = (id) => ({ op: "var", id });
|
|
15
|
-
var app = (
|
|
15
|
+
var app = (fn2, args) => ({ op: "app", fn: fn2, args });
|
|
16
16
|
function termEquals(a, b) {
|
|
17
17
|
if (a === b) return true;
|
|
18
18
|
if (a.op !== b.op) return false;
|
|
@@ -60,13 +60,13 @@ function termToString(t) {
|
|
|
60
60
|
function simplifyTerm(t) {
|
|
61
61
|
if (t.op !== "app") return t;
|
|
62
62
|
const args = t.args.map(simplifyTerm);
|
|
63
|
-
const
|
|
63
|
+
const fn2 = t.fn;
|
|
64
64
|
if (args.every((a) => a.op === "lit")) {
|
|
65
65
|
const xs = args.map((a) => a.value);
|
|
66
|
-
const folded = foldLiterals(
|
|
66
|
+
const folded = foldLiterals(fn2, xs);
|
|
67
67
|
if (folded !== void 0) return lit(folded);
|
|
68
68
|
}
|
|
69
|
-
if (
|
|
69
|
+
if (fn2 === "*" && args.length === 2) {
|
|
70
70
|
const [a, b] = args;
|
|
71
71
|
const one = (t2) => t2.op === "lit" && t2.value === 1;
|
|
72
72
|
const surviveMulOne = (t2) => {
|
|
@@ -76,36 +76,36 @@ function simplifyTerm(t) {
|
|
|
76
76
|
if (typeof v2 === "boolean") return lit(v2 ? 1 : 0);
|
|
77
77
|
if (v2 === null) return lit(0);
|
|
78
78
|
if (typeof v2 === "string") return lit(Number(v2));
|
|
79
|
-
if (typeof v2 === "bigint") return app(
|
|
79
|
+
if (typeof v2 === "bigint") return app(fn2, args);
|
|
80
80
|
return lit(NaN);
|
|
81
81
|
};
|
|
82
82
|
if (one(b)) return surviveMulOne(a);
|
|
83
83
|
if (one(a)) return surviveMulOne(b);
|
|
84
84
|
}
|
|
85
|
-
if (
|
|
85
|
+
if (fn2 === "-" && args.length === 2) {
|
|
86
86
|
const [a, b] = args;
|
|
87
87
|
if (b.op === "lit" && Object.is(b.value, 0)) return a;
|
|
88
88
|
}
|
|
89
|
-
return app(
|
|
89
|
+
return app(fn2, args);
|
|
90
90
|
}
|
|
91
|
-
function foldLiterals(
|
|
92
|
-
if (
|
|
91
|
+
function foldLiterals(fn2, xs) {
|
|
92
|
+
if (fn2 === "+" && xs.length === 2) {
|
|
93
93
|
const [a, b] = xs;
|
|
94
94
|
if (typeof a === "number" && typeof b === "number") return a + b;
|
|
95
95
|
if (typeof a === "string" || typeof b === "string") return String(a) + String(b);
|
|
96
96
|
return void 0;
|
|
97
97
|
}
|
|
98
|
-
if (
|
|
98
|
+
if (fn2 === "-" && xs.length === 2) {
|
|
99
99
|
const [a, b] = xs;
|
|
100
100
|
if (typeof a === "number" && typeof b === "number") return a - b;
|
|
101
101
|
return void 0;
|
|
102
102
|
}
|
|
103
|
-
if (
|
|
103
|
+
if (fn2 === "*" && xs.length === 2) {
|
|
104
104
|
const [a, b] = xs;
|
|
105
105
|
if (typeof a === "number" && typeof b === "number") return a * b;
|
|
106
106
|
return void 0;
|
|
107
107
|
}
|
|
108
|
-
if (
|
|
108
|
+
if (fn2 === "neg" && xs.length === 1) {
|
|
109
109
|
const a = xs[0];
|
|
110
110
|
if (typeof a === "number") return -a;
|
|
111
111
|
return void 0;
|
|
@@ -378,8 +378,8 @@ var implicationOracleSlot = createScopedSlot(
|
|
|
378
378
|
() => void 0
|
|
379
379
|
);
|
|
380
380
|
registerCollectorScopeParticipant((body) => implicationOracleSlot.runScoped(body));
|
|
381
|
-
function setImplicationOracle(
|
|
382
|
-
implicationOracleSlot.set(
|
|
381
|
+
function setImplicationOracle(fn2) {
|
|
382
|
+
implicationOracleSlot.set(fn2);
|
|
383
383
|
}
|
|
384
384
|
function getImplicationOracle() {
|
|
385
385
|
return implicationOracleSlot.get();
|
|
@@ -1172,9 +1172,9 @@ function shapeOfTerm(t) {
|
|
|
1172
1172
|
}
|
|
1173
1173
|
return { k: "unknown" };
|
|
1174
1174
|
}
|
|
1175
|
-
function abs(
|
|
1175
|
+
function abs(shape2, term, pred, conf) {
|
|
1176
1176
|
return {
|
|
1177
|
-
shape,
|
|
1177
|
+
shape: shape2,
|
|
1178
1178
|
term,
|
|
1179
1179
|
pred: pred && pred.op !== "true" ? pred : void 0,
|
|
1180
1180
|
conf
|
|
@@ -1455,11 +1455,11 @@ function markPureFn(target, name) {
|
|
|
1455
1455
|
const impl = implByAbs.get(target);
|
|
1456
1456
|
if (impl) impl.pureName = name;
|
|
1457
1457
|
}
|
|
1458
|
-
function pureFnNameOf(
|
|
1459
|
-
if (!
|
|
1460
|
-
const impl = implByAbs.get(
|
|
1458
|
+
function pureFnNameOf(fn2) {
|
|
1459
|
+
if (!fn2 || typeof fn2 !== "object" && typeof fn2 !== "function") return void 0;
|
|
1460
|
+
const impl = implByAbs.get(fn2);
|
|
1461
1461
|
if (impl?.pureName) return impl.pureName;
|
|
1462
|
-
return
|
|
1462
|
+
return fn2._memoize;
|
|
1463
1463
|
}
|
|
1464
1464
|
function absFunction(params, impl, opts) {
|
|
1465
1465
|
const a = {
|
|
@@ -1608,8 +1608,8 @@ var derivationSlot = createScopedSlot(() => ({
|
|
|
1608
1608
|
}));
|
|
1609
1609
|
registerCollectorScopeParticipant((body) => derivationSlot.runScoped(body));
|
|
1610
1610
|
var byAbs = /* @__PURE__ */ new WeakMap();
|
|
1611
|
-
function setDerivationCollector(
|
|
1612
|
-
derivationSlot.get().collector =
|
|
1611
|
+
function setDerivationCollector(fn2) {
|
|
1612
|
+
derivationSlot.get().collector = fn2;
|
|
1613
1613
|
}
|
|
1614
1614
|
function hasDerivationSession() {
|
|
1615
1615
|
return derivationSlot.get().sessionNodes !== null;
|
|
@@ -1764,10 +1764,10 @@ function propertyKeyOf(a) {
|
|
|
1764
1764
|
return String(v2);
|
|
1765
1765
|
}
|
|
1766
1766
|
function objOf(slots, opts) {
|
|
1767
|
-
const
|
|
1768
|
-
if (opts?.index)
|
|
1769
|
-
if (opts?.open)
|
|
1770
|
-
return { shape, conf: "exact" };
|
|
1767
|
+
const shape2 = { k: "obj", slots };
|
|
1768
|
+
if (opts?.index) shape2.index = opts.index;
|
|
1769
|
+
if (opts?.open) shape2.open = true;
|
|
1770
|
+
return { shape: shape2, conf: "exact" };
|
|
1771
1771
|
}
|
|
1772
1772
|
function isObj(a) {
|
|
1773
1773
|
return a.shape.k === "obj";
|
|
@@ -1819,9 +1819,9 @@ function spread(base, over) {
|
|
|
1819
1819
|
if (indexSlots && isObj(base)) {
|
|
1820
1820
|
const slots2 = { ...base.shape.slots };
|
|
1821
1821
|
for (const [k, s] of Object.entries(indexSlots)) setSlot(slots2, k, s);
|
|
1822
|
-
const
|
|
1823
|
-
if (base.shape.open)
|
|
1824
|
-
return { shape:
|
|
1822
|
+
const shape3 = { k: "obj", slots: slots2 };
|
|
1823
|
+
if (base.shape.open) shape3.open = true;
|
|
1824
|
+
return { shape: shape3, conf: confJoin(base.conf, over.conf) };
|
|
1825
1825
|
}
|
|
1826
1826
|
if (!isObj(base)) return unknown;
|
|
1827
1827
|
return {
|
|
@@ -1837,12 +1837,12 @@ function spread(base, over) {
|
|
|
1837
1837
|
setSlot(slots, k, s);
|
|
1838
1838
|
}
|
|
1839
1839
|
const open = base.shape.open || over.shape.open || false;
|
|
1840
|
-
const
|
|
1841
|
-
if (open)
|
|
1840
|
+
const shape2 = { k: "obj", slots };
|
|
1841
|
+
if (open) shape2.open = true;
|
|
1842
1842
|
if (base.shape.index || over.shape.index) {
|
|
1843
|
-
|
|
1843
|
+
shape2.index = over.shape.index ?? base.shape.index;
|
|
1844
1844
|
}
|
|
1845
|
-
return { shape, conf: confJoin(base.conf, over.conf) };
|
|
1845
|
+
return { shape: shape2, conf: confJoin(base.conf, over.conf) };
|
|
1846
1846
|
}
|
|
1847
1847
|
function spreadIndexSlots(over) {
|
|
1848
1848
|
const s = over.shape;
|
|
@@ -2006,9 +2006,9 @@ function absShapeKey(a, seen = /* @__PURE__ */ new Set()) {
|
|
|
2006
2006
|
}
|
|
2007
2007
|
}
|
|
2008
2008
|
function fnOf(params, name) {
|
|
2009
|
-
const
|
|
2010
|
-
if (name)
|
|
2011
|
-
return { shape, conf: "exact" };
|
|
2009
|
+
const shape2 = { k: "fn", params };
|
|
2010
|
+
if (name) shape2.name = name;
|
|
2011
|
+
return { shape: shape2, conf: "exact" };
|
|
2012
2012
|
}
|
|
2013
2013
|
function joinFunctions(a, b) {
|
|
2014
2014
|
const sa = a.shape;
|
|
@@ -2487,7 +2487,7 @@ function tryPromoteHofCallback(env, cevalName, method, argAbses, loc) {
|
|
|
2487
2487
|
return env.vars.get(cevalName);
|
|
2488
2488
|
}
|
|
2489
2489
|
function snapshotAbs(a) {
|
|
2490
|
-
const
|
|
2490
|
+
const shape2 = a.shape;
|
|
2491
2491
|
const copyShape = (s) => {
|
|
2492
2492
|
switch (s.k) {
|
|
2493
2493
|
case "arr":
|
|
@@ -2542,7 +2542,7 @@ function snapshotAbs(a) {
|
|
|
2542
2542
|
}
|
|
2543
2543
|
};
|
|
2544
2544
|
return {
|
|
2545
|
-
shape: copyShape(
|
|
2545
|
+
shape: copyShape(shape2),
|
|
2546
2546
|
term: a.term,
|
|
2547
2547
|
pred: a.pred,
|
|
2548
2548
|
conf: a.conf
|
|
@@ -2657,17 +2657,17 @@ function mapHasShapeOnlyVar(p, map) {
|
|
|
2657
2657
|
function substPredAbs(p, map) {
|
|
2658
2658
|
if (!predUsesMappedVars(p, map)) return { pred: p, dropped: false };
|
|
2659
2659
|
if (mapHasShapeOnlyVar(p, map)) return { pred: pTrue, dropped: true };
|
|
2660
|
-
const
|
|
2660
|
+
const substTerm2 = (t) => {
|
|
2661
2661
|
if (t.op === "var") {
|
|
2662
2662
|
const arg = map.get(t.id);
|
|
2663
2663
|
return arg?.term ?? t;
|
|
2664
2664
|
}
|
|
2665
2665
|
if (t.op === "app") {
|
|
2666
|
-
return { op: "app", fn: t.fn, args: t.args.map(
|
|
2666
|
+
return { op: "app", fn: t.fn, args: t.args.map(substTerm2) };
|
|
2667
2667
|
}
|
|
2668
2668
|
return t;
|
|
2669
2669
|
};
|
|
2670
|
-
const replaced = substPred(p,
|
|
2670
|
+
const replaced = substPred(p, substTerm2);
|
|
2671
2671
|
const fold = (q) => {
|
|
2672
2672
|
switch (q.op) {
|
|
2673
2673
|
case "true":
|
|
@@ -2807,7 +2807,7 @@ function substAbsInner(a, map, cache, visiting) {
|
|
|
2807
2807
|
if (hit !== void 0) return hit;
|
|
2808
2808
|
if (visiting.has(a)) return a;
|
|
2809
2809
|
visiting.add(a);
|
|
2810
|
-
const
|
|
2810
|
+
const shape2 = substShape(a.shape, map, cache, visiting);
|
|
2811
2811
|
const term = a.term ? substTermAbs(a.term, map) : void 0;
|
|
2812
2812
|
let pred = a.pred;
|
|
2813
2813
|
let conf = a.conf;
|
|
@@ -2817,7 +2817,7 @@ function substAbsInner(a, map, cache, visiting) {
|
|
|
2817
2817
|
if (r.dropped) conf = confJoin(conf, "partial");
|
|
2818
2818
|
}
|
|
2819
2819
|
visiting.delete(a);
|
|
2820
|
-
const result = abs(
|
|
2820
|
+
const result = abs(shape2, term, pred, conf);
|
|
2821
2821
|
cache.set(a, result);
|
|
2822
2822
|
return result;
|
|
2823
2823
|
}
|
|
@@ -2872,13 +2872,13 @@ function bindTypeVars(pattern, arg, map, depth = 0) {
|
|
|
2872
2872
|
return;
|
|
2873
2873
|
}
|
|
2874
2874
|
}
|
|
2875
|
-
function instantiateReturn(
|
|
2876
|
-
const
|
|
2877
|
-
if (!
|
|
2878
|
-
const impl = getFnImpl(
|
|
2875
|
+
function instantiateReturn(fn2, args) {
|
|
2876
|
+
const shape2 = fn2.shape;
|
|
2877
|
+
if (!shape2 || shape2.k !== "fn") return unknown;
|
|
2878
|
+
const impl = getFnImpl(fn2);
|
|
2879
2879
|
const src = impl?.relation ?? {
|
|
2880
|
-
paramTypes:
|
|
2881
|
-
returnType:
|
|
2880
|
+
paramTypes: shape2.paramTypes ?? [],
|
|
2881
|
+
returnType: shape2.returnType ?? unknown
|
|
2882
2882
|
};
|
|
2883
2883
|
const map = /* @__PURE__ */ new Map();
|
|
2884
2884
|
src.paramTypes.forEach((p, i) => {
|
|
@@ -2897,16 +2897,16 @@ function instantiateReturn(fn, args) {
|
|
|
2897
2897
|
return substAbs(src.returnType, map);
|
|
2898
2898
|
}
|
|
2899
2899
|
var applyCallbackHost;
|
|
2900
|
-
function setApplyCallbackHost(
|
|
2901
|
-
applyCallbackHost =
|
|
2900
|
+
function setApplyCallbackHost(fn2) {
|
|
2901
|
+
applyCallbackHost = fn2;
|
|
2902
2902
|
}
|
|
2903
|
-
function applyCallbackValue(
|
|
2904
|
-
if (typeof
|
|
2905
|
-
const r =
|
|
2903
|
+
function applyCallbackValue(fn2, args, env, phi2, budget) {
|
|
2904
|
+
if (typeof fn2 === "function") {
|
|
2905
|
+
const r = fn2(...args);
|
|
2906
2906
|
if (r && typeof r === "object" && "shape" in r) return r;
|
|
2907
2907
|
return unknown;
|
|
2908
2908
|
}
|
|
2909
|
-
const absFn = asAbs(
|
|
2909
|
+
const absFn = asAbs(fn2);
|
|
2910
2910
|
if (absFn) return applyCallbackAbs(absFn, args, env, phi2, budget);
|
|
2911
2911
|
return unknown;
|
|
2912
2912
|
}
|
|
@@ -4411,8 +4411,8 @@ function str2(conf = "path") {
|
|
|
4411
4411
|
function boolPrim(conf = "partial") {
|
|
4412
4412
|
return abs({ k: "prim", type: "boolean" }, void 0, void 0, conf);
|
|
4413
4413
|
}
|
|
4414
|
-
function peelBrand(
|
|
4415
|
-
let s =
|
|
4414
|
+
function peelBrand(shape2) {
|
|
4415
|
+
let s = shape2;
|
|
4416
4416
|
while (s.k === "brand") s = s.shape.shape;
|
|
4417
4417
|
return s;
|
|
4418
4418
|
}
|
|
@@ -5792,8 +5792,8 @@ function matchAsOverride(stmt, opts) {
|
|
|
5792
5792
|
}
|
|
5793
5793
|
return null;
|
|
5794
5794
|
}
|
|
5795
|
-
function fnBodyHasThis(
|
|
5796
|
-
const body =
|
|
5795
|
+
function fnBodyHasThis(fn2) {
|
|
5796
|
+
const body = fn2.body;
|
|
5797
5797
|
if (!body) return false;
|
|
5798
5798
|
const seen = /* @__PURE__ */ new Set();
|
|
5799
5799
|
const walk = (n) => {
|
|
@@ -5817,8 +5817,8 @@ function fnBodyHasThis(fn) {
|
|
|
5817
5817
|
};
|
|
5818
5818
|
return walk(body);
|
|
5819
5819
|
}
|
|
5820
|
-
function fnBodyHasOwnArguments(
|
|
5821
|
-
const body =
|
|
5820
|
+
function fnBodyHasOwnArguments(fn2) {
|
|
5821
|
+
const body = fn2.body;
|
|
5822
5822
|
if (!body) return false;
|
|
5823
5823
|
const seen = /* @__PURE__ */ new Set();
|
|
5824
5824
|
const walk = (n) => {
|
|
@@ -6343,16 +6343,16 @@ function isExpression(n) {
|
|
|
6343
6343
|
|
|
6344
6344
|
// src/algebra/exec/transpile/transpile-dispatch.ts
|
|
6345
6345
|
var dispatch = {};
|
|
6346
|
-
function bindTranspileExpression(
|
|
6347
|
-
dispatch.expr =
|
|
6346
|
+
function bindTranspileExpression(fn2) {
|
|
6347
|
+
dispatch.expr = fn2;
|
|
6348
6348
|
}
|
|
6349
|
-
function bindTranspileShortCircuit(
|
|
6350
|
-
dispatch.shortCircuit =
|
|
6349
|
+
function bindTranspileShortCircuit(fn2) {
|
|
6350
|
+
dispatch.shortCircuit = fn2;
|
|
6351
6351
|
}
|
|
6352
6352
|
function emitTranspileExpression(expr, opts = {}) {
|
|
6353
|
-
const
|
|
6354
|
-
if (!
|
|
6355
|
-
return
|
|
6353
|
+
const fn2 = dispatch.expr;
|
|
6354
|
+
if (!fn2) throw new Error("transpileExpression not bound (expr.ts not loaded)");
|
|
6355
|
+
return fn2(expr, opts);
|
|
6356
6356
|
}
|
|
6357
6357
|
|
|
6358
6358
|
// src/algebra/exec/transpile/member-path.ts
|
|
@@ -6547,7 +6547,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
6547
6547
|
}
|
|
6548
6548
|
if (node.type === "UpdateExpression" && node.argument) {
|
|
6549
6549
|
const arg = node.argument;
|
|
6550
|
-
const
|
|
6550
|
+
const fn2 = node.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
6551
6551
|
if (arg.type === "MemberExpression") {
|
|
6552
6552
|
const path = memberPathOf(
|
|
6553
6553
|
arg,
|
|
@@ -6555,7 +6555,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
6555
6555
|
);
|
|
6556
6556
|
if (path) {
|
|
6557
6557
|
const readSrc = readPathSrc(path);
|
|
6558
|
-
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${
|
|
6558
|
+
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn2}(${readSrc})`)};`);
|
|
6559
6559
|
}
|
|
6560
6560
|
}
|
|
6561
6561
|
}
|
|
@@ -6987,6 +6987,13 @@ var memberGuardTarget = (n) => {
|
|
|
6987
6987
|
if (key === void 0) return void 0;
|
|
6988
6988
|
return { name: m.object.name, key };
|
|
6989
6989
|
};
|
|
6990
|
+
var assignGuardTarget = (n) => {
|
|
6991
|
+
const t = n;
|
|
6992
|
+
if (t?.type === "AssignmentExpression" && t.operator === "=" && t.left?.type === "Identifier" && t.left.name) {
|
|
6993
|
+
return t.left.name;
|
|
6994
|
+
}
|
|
6995
|
+
return void 0;
|
|
6996
|
+
};
|
|
6990
6997
|
function nullishGuardOf(test) {
|
|
6991
6998
|
const t = test;
|
|
6992
6999
|
if (t?.type === "LogicalExpression") return compositeNullishGuardOf(t);
|
|
@@ -6996,12 +7003,16 @@ function nullishGuardOf(test) {
|
|
|
6996
7003
|
if (t?.type === "UnaryExpression" && t.operator === "!") {
|
|
6997
7004
|
const m = memberGuardTarget(t.argument);
|
|
6998
7005
|
if (m) return { name: m.name, arm: "alt", grain: "nullish", memberKey: m.key };
|
|
7006
|
+
const a = assignGuardTarget(t.argument);
|
|
7007
|
+
if (a) return { name: a, arm: "alt", grain: "nullish" };
|
|
6999
7008
|
}
|
|
7000
7009
|
if (t?.type === "Identifier" && t.name) {
|
|
7001
7010
|
return { name: t.name, arm: "cons", grain: "nullish" };
|
|
7002
7011
|
}
|
|
7003
7012
|
const bare = memberGuardTarget(t);
|
|
7004
7013
|
if (bare) return { name: bare.name, arm: "cons", grain: "nullish", memberKey: bare.key };
|
|
7014
|
+
const bareAssign = assignGuardTarget(t);
|
|
7015
|
+
if (bareAssign) return { name: bareAssign, arm: "cons", grain: "nullish" };
|
|
7005
7016
|
if (t?.type !== "BinaryExpression") return void 0;
|
|
7006
7017
|
const op = t.operator;
|
|
7007
7018
|
if (op !== "===" && op !== "!==" && op !== "==" && op !== "!=") return void 0;
|
|
@@ -7033,6 +7044,20 @@ function nullishGuardOf(test) {
|
|
|
7033
7044
|
const grain = litGrain(l);
|
|
7034
7045
|
if (grain !== void 0) return { name: r.name, arm: truthyArm, grain };
|
|
7035
7046
|
}
|
|
7047
|
+
if (op === "==" || op === "!=") {
|
|
7048
|
+
const nullishLit = (n) => {
|
|
7049
|
+
const ln = n;
|
|
7050
|
+
return ln?.type === "NullLiteral" || ln?.name === "undefined";
|
|
7051
|
+
};
|
|
7052
|
+
const lm = memberGuardTarget(t.left);
|
|
7053
|
+
const rm = memberGuardTarget(t.right);
|
|
7054
|
+
if (lm && nullishLit(t.right)) {
|
|
7055
|
+
return { name: lm.name, arm: truthyArm, grain: "nullish", memberKey: lm.key };
|
|
7056
|
+
}
|
|
7057
|
+
if (rm && nullishLit(t.left)) {
|
|
7058
|
+
return { name: rm.name, arm: truthyArm, grain: "nullish", memberKey: rm.key };
|
|
7059
|
+
}
|
|
7060
|
+
}
|
|
7036
7061
|
return void 0;
|
|
7037
7062
|
}
|
|
7038
7063
|
function compositeNullishGuardOf(test) {
|
|
@@ -7053,6 +7078,31 @@ function compositeNullishGuardOf(test) {
|
|
|
7053
7078
|
}
|
|
7054
7079
|
return lg ?? rg;
|
|
7055
7080
|
}
|
|
7081
|
+
function mergeGuardInto(list, g) {
|
|
7082
|
+
const prev = list.find((x) => x.name === g.name);
|
|
7083
|
+
if (!prev) {
|
|
7084
|
+
list.push(g);
|
|
7085
|
+
return;
|
|
7086
|
+
}
|
|
7087
|
+
const grainA = prev.grain ?? "nullish";
|
|
7088
|
+
const grainB = g.grain ?? "nullish";
|
|
7089
|
+
if (grainA !== grainB) prev.grain = "nullish";
|
|
7090
|
+
if (prev.memberKey === void 0 && g.memberKey !== void 0) prev.memberKey = g.memberKey;
|
|
7091
|
+
}
|
|
7092
|
+
function nullishGuardsOf(test) {
|
|
7093
|
+
const t = test;
|
|
7094
|
+
if (t?.type === "LogicalExpression" && (t.operator === "||" || t.operator === "&&")) {
|
|
7095
|
+
const wantArm = t.operator === "||" ? "alt" : "cons";
|
|
7096
|
+
const out = [];
|
|
7097
|
+
for (const g2 of [...nullishGuardsOf(t.left), ...nullishGuardsOf(t.right)]) {
|
|
7098
|
+
if (g2.arm !== wantArm) continue;
|
|
7099
|
+
mergeGuardInto(out, g2);
|
|
7100
|
+
}
|
|
7101
|
+
return out;
|
|
7102
|
+
}
|
|
7103
|
+
const g = nullishGuardOf(test);
|
|
7104
|
+
return g ? [g] : [];
|
|
7105
|
+
}
|
|
7056
7106
|
function typeGuardOf(test) {
|
|
7057
7107
|
const t = test;
|
|
7058
7108
|
if (t?.type !== "BinaryExpression") return void 0;
|
|
@@ -7074,11 +7124,15 @@ function nullishRemoveCallOf(guard) {
|
|
|
7074
7124
|
if (guard.grain === "null") return `$removeNull(${guard.name})`;
|
|
7075
7125
|
return `$removeNullish(${guard.name})`;
|
|
7076
7126
|
}
|
|
7077
|
-
function
|
|
7078
|
-
if (!
|
|
7127
|
+
function narrowNullishArmThunks(thunk, guards, arm, forkBindingNames) {
|
|
7128
|
+
if (!guards || guards.length === 0) return thunk;
|
|
7129
|
+
const matching = guards.filter((g) => g.arm === arm);
|
|
7130
|
+
if (matching.length === 0) return thunk;
|
|
7079
7131
|
const names = forkBindingNames instanceof Set ? forkBindingNames : new Set(forkBindingNames);
|
|
7080
|
-
if (names.has(
|
|
7081
|
-
|
|
7132
|
+
if (matching.some((g) => names.has(g.name))) return thunk;
|
|
7133
|
+
const params = matching.map((g) => g.name).join(", ");
|
|
7134
|
+
const args = matching.map((g) => nullishRemoveCallOf(g)).join(", ");
|
|
7135
|
+
return `((${params}) => ${thunk})(${args})`;
|
|
7082
7136
|
}
|
|
7083
7137
|
function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
|
|
7084
7138
|
if (!guard) return thunk;
|
|
@@ -7087,6 +7141,64 @@ function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
|
|
|
7087
7141
|
const keep = arm === guard.arm;
|
|
7088
7142
|
return `((${guard.name}) => ${thunk})($narrowTypeOf(${guard.name}, ${JSON.stringify(guard.typeOf)}, ${keep}))`;
|
|
7089
7143
|
}
|
|
7144
|
+
var isPrimLitNode = (n) => {
|
|
7145
|
+
const t = n;
|
|
7146
|
+
if (t?.type === "StringLiteral") return typeof t.value === "string";
|
|
7147
|
+
if (t?.type === "NumericLiteral") return typeof t.value === "number";
|
|
7148
|
+
if (t?.type === "BooleanLiteral") return typeof t.value === "boolean";
|
|
7149
|
+
return false;
|
|
7150
|
+
};
|
|
7151
|
+
function discriminantGuardOf(test) {
|
|
7152
|
+
const t = test;
|
|
7153
|
+
if (t?.type !== "BinaryExpression") return void 0;
|
|
7154
|
+
if (t.operator !== "===" && t.operator !== "!==") return void 0;
|
|
7155
|
+
const lm = memberGuardTarget(t.left);
|
|
7156
|
+
const rm = memberGuardTarget(t.right);
|
|
7157
|
+
const m = lm !== void 0 && isPrimLitNode(t.right) ? { target: lm, lit: t.right } : rm !== void 0 && isPrimLitNode(t.left) ? { target: rm, lit: t.left } : void 0;
|
|
7158
|
+
if (!m) return void 0;
|
|
7159
|
+
return {
|
|
7160
|
+
name: m.target.name,
|
|
7161
|
+
key: m.target.key,
|
|
7162
|
+
value: m.lit.value,
|
|
7163
|
+
arm: t.operator === "===" ? "cons" : "alt"
|
|
7164
|
+
};
|
|
7165
|
+
}
|
|
7166
|
+
function discriminantGuardsOf(test) {
|
|
7167
|
+
const t = test;
|
|
7168
|
+
if (t?.type === "LogicalExpression" && (t.operator === "&&" || t.operator === "||")) {
|
|
7169
|
+
const wantArm = t.operator === "&&" ? "cons" : "alt";
|
|
7170
|
+
const out = [];
|
|
7171
|
+
for (const g2 of [...discriminantGuardsOf(t.left), ...discriminantGuardsOf(t.right)]) {
|
|
7172
|
+
if (g2.arm !== wantArm) continue;
|
|
7173
|
+
if (out.some((x) => x.name === g2.name && x.key === g2.key && x.value === g2.value)) continue;
|
|
7174
|
+
out.push(g2);
|
|
7175
|
+
}
|
|
7176
|
+
return out;
|
|
7177
|
+
}
|
|
7178
|
+
const g = discriminantGuardOf(test);
|
|
7179
|
+
return g ? [g] : [];
|
|
7180
|
+
}
|
|
7181
|
+
function narrowDiscriminantArmThunks(thunk, guards, arm, forkBindingNames) {
|
|
7182
|
+
if (!guards || guards.length === 0) return thunk;
|
|
7183
|
+
const matching = guards.filter((g) => g.arm === arm);
|
|
7184
|
+
if (matching.length === 0) return thunk;
|
|
7185
|
+
const names = forkBindingNames instanceof Set ? forkBindingNames : new Set(forkBindingNames);
|
|
7186
|
+
if (matching.some((g) => names.has(g.name))) return thunk;
|
|
7187
|
+
const byName = /* @__PURE__ */ new Map();
|
|
7188
|
+
for (const g of matching) {
|
|
7189
|
+
const list = byName.get(g.name) ?? [];
|
|
7190
|
+
if (!list.some((x) => x.key === g.key && x.value === g.value)) list.push(g);
|
|
7191
|
+
byName.set(g.name, list);
|
|
7192
|
+
}
|
|
7193
|
+
const params = [...byName.keys()].join(", ");
|
|
7194
|
+
const args = [...byName.entries()].map(
|
|
7195
|
+
([name, gs]) => gs.reduce(
|
|
7196
|
+
(acc, g) => `$narrowMemberEq(${acc}, ${JSON.stringify(g.key)}, ${JSON.stringify(g.value)}, true)`,
|
|
7197
|
+
name
|
|
7198
|
+
)
|
|
7199
|
+
).join(", ");
|
|
7200
|
+
return `((${params}) => ${thunk})(${args})`;
|
|
7201
|
+
}
|
|
7090
7202
|
|
|
7091
7203
|
// src/algebra/exec/transpile/stmt.ts
|
|
7092
7204
|
var switchBodySeq = 0;
|
|
@@ -7181,16 +7293,22 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
|
|
|
7181
7293
|
};
|
|
7182
7294
|
const testRecvs = collectArrMutatorReceivers(stmt.test);
|
|
7183
7295
|
const testRebinds = testRecvs.size ? emitArrMutatorRebinds(stmt.test, scopedOpts, pad) : [];
|
|
7184
|
-
const
|
|
7296
|
+
const earlyGuards = nullishGuardsOf(stmt.test);
|
|
7185
7297
|
const earlyTGuard = typeGuardOf(stmt.test);
|
|
7186
|
-
const
|
|
7187
|
-
|
|
7188
|
-
|
|
7189
|
-
|
|
7298
|
+
const earlyDGuards = discriminantGuardsOf(stmt.test);
|
|
7299
|
+
const consNarrowed = narrowDiscriminantArmThunks(
|
|
7300
|
+
narrowTypeArmThunk(
|
|
7301
|
+
narrowNullishArmThunks(
|
|
7302
|
+
transpileBlockAsThunk(stmt.consequent, depth, scopedOpts),
|
|
7303
|
+
earlyGuards,
|
|
7304
|
+
"cons",
|
|
7305
|
+
recvSet
|
|
7306
|
+
),
|
|
7307
|
+
earlyTGuard,
|
|
7190
7308
|
"cons",
|
|
7191
7309
|
recvSet
|
|
7192
7310
|
),
|
|
7193
|
-
|
|
7311
|
+
earlyDGuards,
|
|
7194
7312
|
"cons",
|
|
7195
7313
|
recvSet
|
|
7196
7314
|
);
|
|
@@ -7199,9 +7317,14 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
|
|
|
7199
7317
|
const altThunk = `() => {
|
|
7200
7318
|
${altBody}
|
|
7201
7319
|
${pad}}`;
|
|
7202
|
-
const altNarrowed =
|
|
7203
|
-
|
|
7204
|
-
|
|
7320
|
+
const altNarrowed = narrowDiscriminantArmThunks(
|
|
7321
|
+
narrowTypeArmThunk(
|
|
7322
|
+
narrowNullishArmThunks(altThunk, earlyGuards, "alt", recvSet),
|
|
7323
|
+
earlyTGuard,
|
|
7324
|
+
"alt",
|
|
7325
|
+
recvSet
|
|
7326
|
+
),
|
|
7327
|
+
earlyDGuards,
|
|
7205
7328
|
"alt",
|
|
7206
7329
|
recvSet
|
|
7207
7330
|
);
|
|
@@ -7530,17 +7653,28 @@ ${pad}export default ${name};`;
|
|
|
7530
7653
|
...opts,
|
|
7531
7654
|
conditionalFlow: (opts.conditionalFlow ?? 0) + 1
|
|
7532
7655
|
}) : null;
|
|
7533
|
-
const
|
|
7656
|
+
const guards = nullishGuardsOf(stmt.test);
|
|
7534
7657
|
const tguard = typeGuardOf(stmt.test);
|
|
7535
|
-
const
|
|
7536
|
-
|
|
7537
|
-
|
|
7658
|
+
const dguards = discriminantGuardsOf(stmt.test);
|
|
7659
|
+
const consNarrowed = narrowDiscriminantArmThunks(
|
|
7660
|
+
narrowTypeArmThunk(
|
|
7661
|
+
narrowNullishArmThunks(consRaw, guards, "cons", recvSet),
|
|
7662
|
+
tguard,
|
|
7663
|
+
"cons",
|
|
7664
|
+
recvSet
|
|
7665
|
+
),
|
|
7666
|
+
dguards,
|
|
7538
7667
|
"cons",
|
|
7539
7668
|
recvSet
|
|
7540
7669
|
);
|
|
7541
|
-
const altNarrowed = altRaw === null ? null :
|
|
7542
|
-
|
|
7543
|
-
|
|
7670
|
+
const altNarrowed = altRaw === null ? null : narrowDiscriminantArmThunks(
|
|
7671
|
+
narrowTypeArmThunk(
|
|
7672
|
+
narrowNullishArmThunks(altRaw, guards, "alt", recvSet),
|
|
7673
|
+
tguard,
|
|
7674
|
+
"alt",
|
|
7675
|
+
recvSet
|
|
7676
|
+
),
|
|
7677
|
+
dguards,
|
|
7544
7678
|
"alt",
|
|
7545
7679
|
recvSet
|
|
7546
7680
|
);
|
|
@@ -7987,13 +8121,24 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
7987
8121
|
collectAssignedIds(stmt.test, assigned);
|
|
7988
8122
|
const bodyLocalDecls = /* @__PURE__ */ new Set();
|
|
7989
8123
|
collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
|
|
8124
|
+
const bodyWrites = /* @__PURE__ */ new Set();
|
|
8125
|
+
collectAssignedIds(stmt.body, bodyWrites);
|
|
8126
|
+
collectArrMutatorReceivers(stmt.body, bodyWrites);
|
|
8127
|
+
const loopGuards = nullishGuardsOf(stmt.test).filter(
|
|
8128
|
+
(g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
|
|
8129
|
+
);
|
|
8130
|
+
const bodyNarrowed = loopGuards.length === 0 ? body : [
|
|
8131
|
+
`${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
|
|
8132
|
+
body,
|
|
8133
|
+
`${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
|
|
8134
|
+
].join("\n");
|
|
7990
8135
|
const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
|
|
7991
8136
|
const loopOpts = opts.loopLabel ? `label: ${JSON.stringify(opts.loopLabel)}` : "";
|
|
7992
8137
|
if (names.length === 0) {
|
|
7993
8138
|
return [
|
|
7994
8139
|
`${pad}// while \u2192 $whileSeq (bounded, max=${max})`,
|
|
7995
8140
|
`${pad}$whileSeq(() => ${test}, () => {`,
|
|
7996
|
-
|
|
8141
|
+
bodyNarrowed,
|
|
7997
8142
|
`${pad}}, ${max}${loopOpts ? `, { ${loopOpts} }` : ""});`
|
|
7998
8143
|
].join("\n");
|
|
7999
8144
|
}
|
|
@@ -8002,7 +8147,7 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
8002
8147
|
return [
|
|
8003
8148
|
`${pad}// while \u2192 $whileSeq (instrumented bindings: ${names.join(", ")})`,
|
|
8004
8149
|
`${pad}$whileSeq(() => ${test}, () => {`,
|
|
8005
|
-
|
|
8150
|
+
bodyNarrowed,
|
|
8006
8151
|
`${pad}}, ${max}, { pack: () => ${packSrc}, unpack: ${unpackSrc}${loopOpts ? `, ${loopOpts}` : ""} });`
|
|
8007
8152
|
].join("\n");
|
|
8008
8153
|
}
|
|
@@ -8021,6 +8166,17 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
8021
8166
|
collectArrMutatorReceivers(stmt.body, assigned);
|
|
8022
8167
|
const bodyLocalDecls = /* @__PURE__ */ new Set();
|
|
8023
8168
|
collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
|
|
8169
|
+
const bodyWrites = /* @__PURE__ */ new Set();
|
|
8170
|
+
collectAssignedIds(stmt.body, bodyWrites);
|
|
8171
|
+
collectArrMutatorReceivers(stmt.body, bodyWrites);
|
|
8172
|
+
const loopGuards = nullishGuardsOf(stmt.test).filter(
|
|
8173
|
+
(g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
|
|
8174
|
+
);
|
|
8175
|
+
const innerBody = loopGuards.length === 0 ? bodyStmts : [
|
|
8176
|
+
`${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
|
|
8177
|
+
bodyStmts,
|
|
8178
|
+
`${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
|
|
8179
|
+
].join("\n");
|
|
8024
8180
|
const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
|
|
8025
8181
|
const packSrc = names.length === 0 ? null : `$obj({ ${names.map((n) => `${JSON.stringify(n)}: $copy(${n})`).join(", ")} })`;
|
|
8026
8182
|
const unpackSrc = names.length === 0 ? null : `(__lp) => { ${names.map((n) => `${n} = $get(__lp, ${JSON.stringify(n)});`).join(" ")} }`;
|
|
@@ -8031,7 +8187,7 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
8031
8187
|
`{`,
|
|
8032
8188
|
bodyStmts,
|
|
8033
8189
|
`${indent(depth + 1)}$whileSeq(() => ${test}, () => {`,
|
|
8034
|
-
|
|
8190
|
+
innerBody,
|
|
8035
8191
|
`${indent(depth + 1)}}, ${max}${optsSrc});`,
|
|
8036
8192
|
`${pad}}`
|
|
8037
8193
|
].join("\n");
|
|
@@ -8437,27 +8593,42 @@ function transpileShortCircuitExpr(opts, parts) {
|
|
|
8437
8593
|
const forkTest2 = parts.testSrc ?? parts.alwaysSrc;
|
|
8438
8594
|
let consExpr = parts.consSrc === "__test" ? parts.alwaysSrc : parts.consSrc;
|
|
8439
8595
|
let altExpr = parts.altSrc === "__test" ? parts.alwaysSrc : parts.altSrc;
|
|
8440
|
-
|
|
8441
|
-
|
|
8442
|
-
|
|
8443
|
-
|
|
8444
|
-
|
|
8445
|
-
}
|
|
8446
|
-
}
|
|
8596
|
+
const applyGuards = (src, arm) => {
|
|
8597
|
+
const gs = (parts.narrowGuards ?? []).filter((g) => g.arm === arm);
|
|
8598
|
+
if (gs.length === 0) return src;
|
|
8599
|
+
const params = gs.map((g) => g.name).join(", ");
|
|
8600
|
+
const args = gs.map((g) => nullishRemoveCallOf(g)).join(", ");
|
|
8601
|
+
return `((${params}) => (${src}))(${args})`;
|
|
8602
|
+
};
|
|
8603
|
+
consExpr = applyGuards(consExpr, "cons");
|
|
8604
|
+
altExpr = applyGuards(altExpr, "alt");
|
|
8447
8605
|
if (parts.typeGuard) {
|
|
8448
8606
|
const g = parts.typeGuard;
|
|
8449
8607
|
const apply = (src, arm) => `((${g.name}) => (${src}))($narrowTypeOf(${g.name}, ${JSON.stringify(g.typeOf)}, ${arm === g.arm}))`;
|
|
8450
8608
|
consExpr = apply(consExpr, "cons");
|
|
8451
8609
|
altExpr = apply(altExpr, "alt");
|
|
8452
8610
|
}
|
|
8611
|
+
const applyDisc = (src, arm) => narrowDiscriminantArmThunks(src, parts.discGuards, arm, []);
|
|
8612
|
+
consExpr = applyDisc(consExpr, "cons");
|
|
8613
|
+
altExpr = applyDisc(altExpr, "alt");
|
|
8453
8614
|
return `$fork(${forkTest2}, () => ${consExpr}, () => ${altExpr})`;
|
|
8454
8615
|
}
|
|
8455
8616
|
const consLines = parts.consSrc === "__test" ? [`return __test;`] : consRebinds.length === 0 ? [`return (${parts.consSrc});`] : [`const __v = (${parts.consSrc});`, ...consRebinds, `return __v;`];
|
|
8456
8617
|
const altLines = parts.altSrc === "__test" ? [`return __test;`] : altRebinds.length === 0 ? [`return (${parts.altSrc});`] : [`const __v = (${parts.altSrc});`, ...altRebinds, `return __v;`];
|
|
8457
8618
|
const forkTest = parts.testSrc ?? "__test";
|
|
8458
|
-
const
|
|
8459
|
-
const consFinal =
|
|
8460
|
-
|
|
8619
|
+
const guards = parts.narrowGuards;
|
|
8620
|
+
const consFinal = narrowDiscriminantArmThunks(
|
|
8621
|
+
narrowNullishArmThunks(forkArmThunk(consLines, "fk1_", names), guards, "cons", names),
|
|
8622
|
+
parts.discGuards,
|
|
8623
|
+
"cons",
|
|
8624
|
+
names
|
|
8625
|
+
);
|
|
8626
|
+
const altFinal = narrowDiscriminantArmThunks(
|
|
8627
|
+
narrowNullishArmThunks(forkArmThunk(altLines, "fk2_", names), guards, "alt", names),
|
|
8628
|
+
parts.discGuards,
|
|
8629
|
+
"alt",
|
|
8630
|
+
names
|
|
8631
|
+
);
|
|
8461
8632
|
return [
|
|
8462
8633
|
`(() => {`,
|
|
8463
8634
|
` const __test = (${parts.alwaysSrc});`,
|
|
@@ -8679,8 +8850,9 @@ ${inner}
|
|
|
8679
8850
|
testSrc: `$nullishTest(${l})`
|
|
8680
8851
|
});
|
|
8681
8852
|
}
|
|
8682
|
-
const
|
|
8853
|
+
const leftGuards = nullishGuardsOf(expr.left);
|
|
8683
8854
|
const andTypeGuard = typeGuardOf(expr.left);
|
|
8855
|
+
const leftDiscGuards = discriminantGuardsOf(expr.left);
|
|
8684
8856
|
return op === "&&" ? transpileShortCircuitExpr(opts, {
|
|
8685
8857
|
alwaysNodes: [lNode],
|
|
8686
8858
|
alwaysSrc: l,
|
|
@@ -8688,8 +8860,9 @@ ${inner}
|
|
|
8688
8860
|
consNodes: [rNode],
|
|
8689
8861
|
altSrc: "__test",
|
|
8690
8862
|
altNodes: [],
|
|
8691
|
-
|
|
8692
|
-
typeGuard: andTypeGuard
|
|
8863
|
+
narrowGuards: leftGuards.filter((g) => g.arm === "cons"),
|
|
8864
|
+
typeGuard: andTypeGuard,
|
|
8865
|
+
discGuards: leftDiscGuards.filter((g) => g.arm === "cons")
|
|
8693
8866
|
}) : transpileShortCircuitExpr(opts, {
|
|
8694
8867
|
alwaysNodes: [lNode],
|
|
8695
8868
|
alwaysSrc: l,
|
|
@@ -8697,8 +8870,9 @@ ${inner}
|
|
|
8697
8870
|
consNodes: [],
|
|
8698
8871
|
altSrc: r,
|
|
8699
8872
|
altNodes: [rNode],
|
|
8700
|
-
|
|
8701
|
-
typeGuard: andTypeGuard
|
|
8873
|
+
narrowGuards: leftGuards.filter((g) => g.arm === "alt"),
|
|
8874
|
+
typeGuard: andTypeGuard,
|
|
8875
|
+
discGuards: leftDiscGuards.filter((g) => g.arm === "alt")
|
|
8702
8876
|
});
|
|
8703
8877
|
}
|
|
8704
8878
|
case "ConditionalExpression": {
|
|
@@ -8716,9 +8890,12 @@ ${inner}
|
|
|
8716
8890
|
altSrc: a,
|
|
8717
8891
|
altNodes: [altNode],
|
|
8718
8892
|
// 三元的 nullish/typeof 守卫臂收窄(issue #97:`p === null ? -1 : p.major`;
|
|
8719
|
-
// Bug 23:`typeof v === "string" ? v + "!" : 0
|
|
8720
|
-
|
|
8721
|
-
|
|
8893
|
+
// Bug 23:`typeof v === "string" ? v + "!" : 0`;#118 v3/#120:多名复合
|
|
8894
|
+
// `obj == null || node.p == null ? … : node.p.name` 一臂多事实);
|
|
8895
|
+
// 判别等值守卫(issue #126):`node.type === 'TL' ? node.quasis[0] : null`
|
|
8896
|
+
narrowGuards: nullishGuardsOf(expr.test),
|
|
8897
|
+
typeGuard: typeGuardOf(expr.test),
|
|
8898
|
+
discGuards: discriminantGuardsOf(expr.test)
|
|
8722
8899
|
});
|
|
8723
8900
|
}
|
|
8724
8901
|
case "RegExpLiteral": {
|
|
@@ -8733,8 +8910,8 @@ ${inner}
|
|
|
8733
8910
|
const r2 = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
|
|
8734
8911
|
return `$instanceofNonIdent(${l2}, ${r2})`;
|
|
8735
8912
|
}
|
|
8736
|
-
const
|
|
8737
|
-
if (!
|
|
8913
|
+
const fn2 = BIN_OPS[expr.operator];
|
|
8914
|
+
if (!fn2) {
|
|
8738
8915
|
throw new NudoUnsupportedError(
|
|
8739
8916
|
`binary:${expr.operator}`,
|
|
8740
8917
|
expr.loc ? { line: expr.loc.start.line, column: expr.loc.start.column } : void 0
|
|
@@ -8742,7 +8919,7 @@ ${inner}
|
|
|
8742
8919
|
}
|
|
8743
8920
|
const l = isExpression(expr.left) ? transpileExpression(expr.left, opts) : "$lit(void 0)";
|
|
8744
8921
|
const r = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
|
|
8745
|
-
return `${
|
|
8922
|
+
return `${fn2}(${l}, ${r})`;
|
|
8746
8923
|
}
|
|
8747
8924
|
case "UnaryExpression": {
|
|
8748
8925
|
if (expr.operator === "delete") {
|
|
@@ -8778,20 +8955,20 @@ ${inner}
|
|
|
8778
8955
|
}
|
|
8779
8956
|
case "UpdateExpression": {
|
|
8780
8957
|
const arg = expr.argument;
|
|
8781
|
-
const
|
|
8958
|
+
const fn2 = expr.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
8782
8959
|
if (arg.type === "Identifier") {
|
|
8783
8960
|
if (isConstAssignTarget(arg.name, opts)) {
|
|
8784
8961
|
return `$throwConstAssign()`;
|
|
8785
8962
|
}
|
|
8786
|
-
if (expr.prefix) return `${arg.name} = ${
|
|
8787
|
-
return `((__old) => (${arg.name} = ${
|
|
8963
|
+
if (expr.prefix) return `${arg.name} = ${fn2}(${arg.name})`;
|
|
8964
|
+
return `((__old) => (${arg.name} = ${fn2}(__old), __old))($toNumeric(${arg.name}))`;
|
|
8788
8965
|
}
|
|
8789
8966
|
if (arg.type === "MemberExpression") {
|
|
8790
8967
|
const m = arg;
|
|
8791
8968
|
const path = memberPathOf(m, opts);
|
|
8792
8969
|
if (path) {
|
|
8793
8970
|
const readSrc = readPathSrc(path);
|
|
8794
|
-
if (expr.prefix) return `${
|
|
8971
|
+
if (expr.prefix) return `${fn2}(${readSrc})`;
|
|
8795
8972
|
return `$toNumeric(${readSrc})`;
|
|
8796
8973
|
}
|
|
8797
8974
|
}
|
|
@@ -8971,23 +9148,23 @@ ${mBodyInner}
|
|
|
8971
9148
|
continue;
|
|
8972
9149
|
}
|
|
8973
9150
|
if (prop.value.type === "FunctionExpression" && !prop.value.async) {
|
|
8974
|
-
const
|
|
8975
|
-
if (!
|
|
8976
|
-
const displayNames = paramDisplayNames(
|
|
8977
|
-
const bindNames = methodBindNames(
|
|
8978
|
-
const mHasArgs = fnBodyHasOwnArguments({ body:
|
|
9151
|
+
const fn2 = prop.value;
|
|
9152
|
+
if (!fn2.generator) {
|
|
9153
|
+
const displayNames = paramDisplayNames(fn2.params);
|
|
9154
|
+
const bindNames = methodBindNames(fn2.params);
|
|
9155
|
+
const mHasArgs = fnBodyHasOwnArguments({ body: fn2.body });
|
|
8979
9156
|
const methodOpts = {
|
|
8980
9157
|
...opts,
|
|
8981
9158
|
inLoop: 0,
|
|
8982
9159
|
thisParam: "__this",
|
|
8983
9160
|
argsBinding: mHasArgs ? "__nudoArgs" : void 0
|
|
8984
9161
|
};
|
|
8985
|
-
let mBodyInner = emitFnBlockBody(
|
|
8986
|
-
varParams: paramNamesOfFn(
|
|
9162
|
+
let mBodyInner = emitFnBlockBody(fn2.body, 1, methodOpts, {
|
|
9163
|
+
varParams: paramNamesOfFn(fn2.params)
|
|
8987
9164
|
});
|
|
8988
9165
|
let mParams = ["__this", ...bindNames];
|
|
8989
9166
|
if (mHasArgs) {
|
|
8990
|
-
const bound = emitParamBindingFromArgs(
|
|
9167
|
+
const bound = emitParamBindingFromArgs(fn2.params, " ", methodOpts, "__nudoArgs");
|
|
8991
9168
|
mBodyInner = [
|
|
8992
9169
|
` let __nudoArgs = $arguments(__margs);`,
|
|
8993
9170
|
...bound.prologue,
|
|
@@ -9329,14 +9506,14 @@ ${mBodyInner}
|
|
|
9329
9506
|
}
|
|
9330
9507
|
case "ArrowFunctionExpression":
|
|
9331
9508
|
case "FunctionExpression": {
|
|
9332
|
-
const
|
|
9509
|
+
const fn2 = expr;
|
|
9333
9510
|
const isArrow = expr.type === "ArrowFunctionExpression";
|
|
9334
|
-
const nfeName = !isArrow &&
|
|
9511
|
+
const nfeName = !isArrow && fn2.id?.name ? fn2.id.name : null;
|
|
9335
9512
|
const fnValSrc = (() => {
|
|
9336
|
-
const fnCtor = isArrow || !!
|
|
9337
|
-
const hasThis = !isArrow && fnBodyHasThis(
|
|
9338
|
-
const hasArgs = !isArrow && fnBodyHasOwnArguments(
|
|
9339
|
-
const { sig, rest, prologue } = emitParamBinding(
|
|
9513
|
+
const fnCtor = isArrow || !!fn2.async || !!fn2.generator ? false : true;
|
|
9514
|
+
const hasThis = !isArrow && fnBodyHasThis(fn2);
|
|
9515
|
+
const hasArgs = !isArrow && fnBodyHasOwnArguments(fn2);
|
|
9516
|
+
const { sig, rest, prologue } = emitParamBinding(fn2.params, indent(1), opts);
|
|
9340
9517
|
const fnBodyOpts = {
|
|
9341
9518
|
...opts,
|
|
9342
9519
|
inLoop: 0,
|
|
@@ -9348,12 +9525,12 @@ ${mBodyInner}
|
|
|
9348
9525
|
const restRaw = rest && !useArgsSlot ? `__rest_raw` : rest;
|
|
9349
9526
|
const restPrologue = rest && !useArgsSlot && restRaw ? [` const ${rest} = $arr(${restRaw});`] : [];
|
|
9350
9527
|
const paramParts = restRaw ? [...sig, `...${restRaw}`] : sig;
|
|
9351
|
-
const nameList = `[${paramDisplayNames(
|
|
9528
|
+
const nameList = `[${paramDisplayNames(fn2.params).map((p) => JSON.stringify(p)).join(", ")}]`;
|
|
9352
9529
|
const thisPrologue = hasThis ? [`let __this = $rawThis(this);`] : [];
|
|
9353
9530
|
let argsSlotPrologue = [];
|
|
9354
9531
|
let argsParamParts = paramParts;
|
|
9355
9532
|
if (useArgsSlot) {
|
|
9356
|
-
const bound = emitParamBindingFromArgs(
|
|
9533
|
+
const bound = emitParamBindingFromArgs(fn2.params, " ", fnBodyOpts, "__nudoArgs");
|
|
9357
9534
|
argsSlotPrologue = [` let __nudoArgs = $arguments(__allArgs);`, ...bound.prologue];
|
|
9358
9535
|
argsParamParts = ["...__allArgs"];
|
|
9359
9536
|
} else if (hasArgs && hasThis) {
|
|
@@ -9370,27 +9547,27 @@ ${mBodyInner}
|
|
|
9370
9547
|
...thisPrologue,
|
|
9371
9548
|
...argsSlotPrologue
|
|
9372
9549
|
];
|
|
9373
|
-
if (
|
|
9550
|
+
if (fn2.body.type === "BlockStatement") {
|
|
9374
9551
|
const raw = withImplicitReturn(
|
|
9375
|
-
|
|
9376
|
-
[...allPrologue, transpileFnBodyStmts(
|
|
9552
|
+
fn2.body,
|
|
9553
|
+
[...allPrologue, transpileFnBodyStmts(fn2.body.body, 1, fnBodyOpts, {
|
|
9377
9554
|
// Bug 21:函数体 var 提升边界——参数模式名已绑定,不得提升
|
|
9378
|
-
skip: paramNamesOfFn(
|
|
9555
|
+
skip: paramNamesOfFn(fn2.params)
|
|
9379
9556
|
})].join("\n"),
|
|
9380
9557
|
1
|
|
9381
9558
|
);
|
|
9382
|
-
const inner =
|
|
9559
|
+
const inner = fn2.generator ? `return $gen(() => {
|
|
9383
9560
|
${raw}
|
|
9384
9561
|
});` : raw;
|
|
9385
9562
|
if (hasThis) {
|
|
9386
|
-
const wrap =
|
|
9563
|
+
const wrap = fn2.async && !fn2.generator ? `function (${argsParamParts.join(", ")}) { return $async(() => {
|
|
9387
9564
|
${inner}
|
|
9388
9565
|
}); }` : `function (${argsParamParts.join(", ")}) {
|
|
9389
9566
|
${inner}
|
|
9390
9567
|
}`;
|
|
9391
9568
|
return `$fnVal(${nameList}, ${wrap}, { ctor: ${fnCtor}${hasArgs ? ", padArgs: false" : ""} })`;
|
|
9392
9569
|
}
|
|
9393
|
-
if (
|
|
9570
|
+
if (fn2.async && !fn2.generator) {
|
|
9394
9571
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => {
|
|
9395
9572
|
${inner}
|
|
9396
9573
|
}), { ctor: ${fnCtor} })`;
|
|
@@ -9399,13 +9576,13 @@ ${inner}
|
|
|
9399
9576
|
${inner}
|
|
9400
9577
|
}, { ctor: ${fnCtor} })`;
|
|
9401
9578
|
}
|
|
9402
|
-
const bodySrc = transpileExpression(
|
|
9579
|
+
const bodySrc = transpileExpression(fn2.body, fnBodyOpts);
|
|
9403
9580
|
if (allPrologue.length > 0 || hasThis) {
|
|
9404
|
-
const rebinds2 = emitArrMutatorRebinds(
|
|
9581
|
+
const rebinds2 = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
|
|
9405
9582
|
const inner = [
|
|
9406
9583
|
...allPrologue,
|
|
9407
9584
|
...rebinds2.map((l) => ` ${l}`),
|
|
9408
|
-
` return ${
|
|
9585
|
+
` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
|
|
9409
9586
|
].join("\n");
|
|
9410
9587
|
if (hasThis) {
|
|
9411
9588
|
const wrap = `function (${argsParamParts.join(", ")}) {
|
|
@@ -9417,17 +9594,17 @@ ${inner}
|
|
|
9417
9594
|
${inner}
|
|
9418
9595
|
}, { ctor: ${fnCtor} })`;
|
|
9419
9596
|
}
|
|
9420
|
-
const rebinds = emitArrMutatorRebinds(
|
|
9597
|
+
const rebinds = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
|
|
9421
9598
|
if (rebinds.length > 0) {
|
|
9422
9599
|
const inner = [
|
|
9423
9600
|
...rebinds.map((l) => ` ${l}`),
|
|
9424
|
-
` return ${
|
|
9601
|
+
` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
|
|
9425
9602
|
].join("\n");
|
|
9426
9603
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => {
|
|
9427
9604
|
${inner}
|
|
9428
9605
|
}, { ctor: ${fnCtor} })`;
|
|
9429
9606
|
}
|
|
9430
|
-
if (
|
|
9607
|
+
if (fn2.async) {
|
|
9431
9608
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => ${bodySrc}), { ctor: ${fnCtor} })`;
|
|
9432
9609
|
}
|
|
9433
9610
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => ${bodySrc}, { ctor: ${fnCtor} })`;
|
|
@@ -9461,7 +9638,7 @@ function transpileSource(source, opts = {}) {
|
|
|
9461
9638
|
return transpileFile(file, { ...opts, source: opts.source ?? source });
|
|
9462
9639
|
}
|
|
9463
9640
|
function runtimeImportOf(runtime) {
|
|
9464
|
-
return `import { $absVal, $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $objAccessorKey, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $invokeSuperObj, $invokeSuperKey, $getSuper, $getSuperObj, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $iterCheck, $catchVal, $switch, $staticInvoke, $setKey, $gen, $newTarget, $staticInit, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $removeNullish, $removeNull, $removeUndefined, $removeMemberNullish, $narrowTypeOf, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $elems, $arguments, $isForkExit, $rawThis, $isBreakTo, $yieldStar, $tpl } from ${JSON.stringify(runtime)};`;
|
|
9641
|
+
return `import { $absVal, $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $objAccessorKey, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $invokeSuperObj, $invokeSuperKey, $getSuper, $getSuperObj, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $iterCheck, $catchVal, $switch, $staticInvoke, $setKey, $gen, $newTarget, $staticInit, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $removeNullish, $removeNull, $removeUndefined, $removeMemberNullish, $narrowMemberEq, $narrowTypeOf, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $elems, $arguments, $isForkExit, $rawThis, $isBreakTo, $yieldStar, $tpl } from ${JSON.stringify(runtime)};`;
|
|
9465
9642
|
}
|
|
9466
9643
|
function transpileFile(file, opts = {}) {
|
|
9467
9644
|
const runtime = opts.runtimeImport ?? "@nudojs/core/exec";
|
|
@@ -9482,7 +9659,7 @@ function transpileFile(file, opts = {}) {
|
|
|
9482
9659
|
};
|
|
9483
9660
|
const lines = [
|
|
9484
9661
|
`// nudo evaluator transpile \u2014 values are Abs; operators are overloaded calls`,
|
|
9485
|
-
`import { $absVal, $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $objAccessorKey, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $invokeSuperObj, $invokeSuperKey, $getSuper, $getSuperObj, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $iterCheck, $catchVal, $switch, $staticInvoke, $setKey, $gen, $newTarget, $staticInit, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $removeNullish, $removeNull, $removeUndefined, $removeMemberNullish, $narrowTypeOf, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $elems, $arguments, $isForkExit, $rawThis, $isBreakTo, $yieldStar, $tpl } from ${JSON.stringify(runtime)};`,
|
|
9662
|
+
`import { $absVal, $add, $sub, $mul, $div, $mod, $bitand, $bitor, $bitxor, $bitnot, $shl, $shr, $ushr, $pow, $toNumber, $toNumeric, $updateAdd, $updateSub, $in, $instanceof, $instanceofNonIdent, $classExpr, $del, $delRes, $objAccessor, $objAccessorKey, $neg, $typeof, $not, $eq, $ne, $eqLoose, $neLoose, $lt, $le, $gt, $ge, $join, $lit, $fork, $for, $forIter, $obj, $get, $set, $setProto, $while, $whileSeq, $arr, $arrWithHoles, $arrMutContainer, $idx, $idxSet, $len, $call, $throw, $loopReturn, $loopBreak, $loopContinue, $class, $new, $invoke, $invokeSuper, $invokeSuperObj, $invokeSuperKey, $getSuper, $getSuperObj, $super, $async, $copy, $await, $asyncReturn, $orDefault, $callNamed, $optionalGet, $optionalInvoke, $spread, $concat, $forOf, $forInKeys, $iterCheck, $catchVal, $switch, $staticInvoke, $setKey, $gen, $newTarget, $staticInit, $yield, $fnVal, $regex, $reStateCall, $rethrowIfNudoReturn, $nullishTest, $removeNullish, $removeNull, $removeUndefined, $removeMemberNullish, $narrowMemberEq, $narrowTypeOf, $tryMark, $assignRecord, $recordBinding, $unknown, $importMeta, $dynamicImport, $tryTakeSince, $tryCurrentMark, $tryPopMark, $tryDigestSoftCatch, $tryReleaseSoftOut, $tryDetachSoftCatch, $tryDiscardSoft, $tryOrphanSoft, $pushLoopExit, $objRest, $arrRest, $elems, $arguments, $isForkExit, $rawThis, $isBreakTo, $yieldStar, $tpl } from ${JSON.stringify(runtime)};`,
|
|
9486
9663
|
``
|
|
9487
9664
|
];
|
|
9488
9665
|
if (varHoistLine) lines.push(varHoistLine);
|
|
@@ -9563,6 +9740,7 @@ __export(runtime_exports, {
|
|
|
9563
9740
|
$lt: () => $lt,
|
|
9564
9741
|
$mod: () => $mod,
|
|
9565
9742
|
$mul: () => $mul,
|
|
9743
|
+
$narrowMemberEq: () => $narrowMemberEq,
|
|
9566
9744
|
$narrowTypeOf: () => $narrowTypeOf,
|
|
9567
9745
|
$ne: () => $ne,
|
|
9568
9746
|
$neLoose: () => $neLoose,
|
|
@@ -9742,9 +9920,9 @@ var BOOLEAN_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
|
|
|
9742
9920
|
var SYMBOL_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
|
|
9743
9921
|
var BIGINT_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "toLocaleString", "valueOf"]);
|
|
9744
9922
|
function notePrimMemberMissing(recv, name, kind, loc) {
|
|
9745
|
-
const
|
|
9746
|
-
if (!
|
|
9747
|
-
const t =
|
|
9923
|
+
const shape2 = recv?.shape;
|
|
9924
|
+
if (!shape2 || shape2.k !== "prim") return false;
|
|
9925
|
+
const t = shape2.type;
|
|
9748
9926
|
if (OBJECT_PROTO_NAMES.has(name)) return false;
|
|
9749
9927
|
const protoMethods = t === "string" ? STRING_METHODS : t === "number" ? NUMBER_PROTO_METHODS : t === "boolean" ? BOOLEAN_PROTO_METHODS : t === "symbol" ? SYMBOL_PROTO_METHODS : t === "bigint" ? BIGINT_PROTO_METHODS : void 0;
|
|
9750
9928
|
if (!protoMethods) return false;
|
|
@@ -9866,9 +10044,9 @@ function runWithEvalMissingSlot(enabled, body) {
|
|
|
9866
10044
|
}
|
|
9867
10045
|
function noteObjSlotMissing(recv, name, loc) {
|
|
9868
10046
|
if (!isEvalMissingSlotEnabled()) return false;
|
|
9869
|
-
const
|
|
9870
|
-
if (!
|
|
9871
|
-
const obj2 =
|
|
10047
|
+
const shape2 = recv?.shape;
|
|
10048
|
+
if (!shape2 || shape2.k !== "obj") return false;
|
|
10049
|
+
const obj2 = shape2;
|
|
9872
10050
|
if (obj2.open) return false;
|
|
9873
10051
|
if (obj2.slots && Object.prototype.hasOwnProperty.call(obj2.slots, name)) return false;
|
|
9874
10052
|
const conf = recv?.conf;
|
|
@@ -10760,23 +10938,23 @@ function clampWindow(len, target, start, end) {
|
|
|
10760
10938
|
if (count <= 0) return null;
|
|
10761
10939
|
return { t, s, e: s + count };
|
|
10762
10940
|
}
|
|
10763
|
-
function copyWithinTuple(
|
|
10941
|
+
function copyWithinTuple(shape2, vals) {
|
|
10764
10942
|
validateIndexArg(vals[0], "copyWithin target may not be convertible to a number");
|
|
10765
10943
|
validateIndexArg(vals[1], "copyWithin start may not be convertible to a number");
|
|
10766
10944
|
validateIndexArg(vals[2], "copyWithin end may not be convertible to a number");
|
|
10767
10945
|
const t = toIOI(vals[0]);
|
|
10768
10946
|
const s = toIOI(vals[1]);
|
|
10769
10947
|
const e = toIOI(vals[2]);
|
|
10770
|
-
if (
|
|
10948
|
+
if (shape2.k === "tuple") {
|
|
10771
10949
|
if (t === null || s === null || e === null) {
|
|
10772
|
-
const joined =
|
|
10950
|
+
const joined = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
10773
10951
|
return abs({ k: "arr", element: joined }, void 0, void 0, "partial");
|
|
10774
10952
|
}
|
|
10775
|
-
const len =
|
|
10953
|
+
const len = shape2.elements.length;
|
|
10776
10954
|
const win = clampWindow(len, t ?? 0, s ?? 0, e ?? len);
|
|
10777
|
-
const origHoles =
|
|
10955
|
+
const origHoles = shape2.holes ?? [];
|
|
10778
10956
|
if (win) {
|
|
10779
|
-
const els = [...
|
|
10957
|
+
const els = [...shape2.elements];
|
|
10780
10958
|
const holesSet = new Set(origHoles);
|
|
10781
10959
|
const backwards = win.s < win.t && win.s + (win.e - win.s) > win.t;
|
|
10782
10960
|
const count = win.e - win.s;
|
|
@@ -10804,7 +10982,7 @@ function copyWithinTuple(shape, vals) {
|
|
|
10804
10982
|
return abs(
|
|
10805
10983
|
{
|
|
10806
10984
|
k: "tuple",
|
|
10807
|
-
elements: [...
|
|
10985
|
+
elements: [...shape2.elements],
|
|
10808
10986
|
holes: origHoles.length > 0 ? [...origHoles] : void 0
|
|
10809
10987
|
},
|
|
10810
10988
|
void 0,
|
|
@@ -10812,19 +10990,19 @@ function copyWithinTuple(shape, vals) {
|
|
|
10812
10990
|
"path"
|
|
10813
10991
|
);
|
|
10814
10992
|
}
|
|
10815
|
-
return abs({ k: "arr", element:
|
|
10993
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
10816
10994
|
}
|
|
10817
|
-
function fillTuple(
|
|
10995
|
+
function fillTuple(shape2, vals, arr) {
|
|
10818
10996
|
validateIndexArg(vals[1], "fill start may not be convertible to a number");
|
|
10819
10997
|
validateIndexArg(vals[2], "fill end may not be convertible to a number");
|
|
10820
10998
|
const v2 = vals[0] ?? unknown;
|
|
10821
10999
|
const s = toIOI(vals[1]);
|
|
10822
11000
|
const e = toIOI(vals[2]);
|
|
10823
|
-
if (
|
|
10824
|
-
const len =
|
|
11001
|
+
if (shape2.k === "tuple") {
|
|
11002
|
+
const len = shape2.elements.length;
|
|
10825
11003
|
if (s === null || e === null) {
|
|
10826
11004
|
return abs(
|
|
10827
|
-
{ k: "tuple", elements:
|
|
11005
|
+
{ k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
|
|
10828
11006
|
void 0,
|
|
10829
11007
|
void 0,
|
|
10830
11008
|
"partial"
|
|
@@ -10832,16 +11010,16 @@ function fillTuple(shape, vals, arr) {
|
|
|
10832
11010
|
}
|
|
10833
11011
|
const start = Math.max(Math.min((s ?? 0) < 0 ? len + (s ?? 0) : s ?? 0, len), 0);
|
|
10834
11012
|
const end = Math.max(Math.min((e ?? len) < 0 ? len + (e ?? len) : e ?? len, len), 0);
|
|
10835
|
-
const holes = (
|
|
11013
|
+
const holes = (shape2.holes ?? []).filter((h) => h < start || h >= end);
|
|
10836
11014
|
if (end <= start) {
|
|
10837
11015
|
return abs(
|
|
10838
|
-
{ k: "tuple", elements: [...
|
|
11016
|
+
{ k: "tuple", elements: [...shape2.elements], holes: holes.length > 0 ? holes : void 0 },
|
|
10839
11017
|
void 0,
|
|
10840
11018
|
void 0,
|
|
10841
11019
|
"path"
|
|
10842
11020
|
);
|
|
10843
11021
|
}
|
|
10844
|
-
const els =
|
|
11022
|
+
const els = shape2.elements.map((el, i) => i >= start && i < end ? v2 : el);
|
|
10845
11023
|
return abs(
|
|
10846
11024
|
{ k: "tuple", elements: els, holes: holes.length > 0 ? holes : void 0 },
|
|
10847
11025
|
void 0,
|
|
@@ -10851,7 +11029,7 @@ function fillTuple(shape, vals, arr) {
|
|
|
10851
11029
|
}
|
|
10852
11030
|
const coversAll = (s === void 0 || s === 0) && e === void 0;
|
|
10853
11031
|
return abs(
|
|
10854
|
-
{ k: "arr", element: coversAll ? v2 : joinAbs(
|
|
11032
|
+
{ k: "arr", element: coversAll ? v2 : joinAbs(shape2.element, v2) },
|
|
10855
11033
|
void 0,
|
|
10856
11034
|
void 0,
|
|
10857
11035
|
confJoin(arr.conf, coversAll ? arr.conf : "path")
|
|
@@ -10890,6 +11068,8 @@ function $copy(a) {
|
|
|
10890
11068
|
open: s.open
|
|
10891
11069
|
});
|
|
10892
11070
|
next.conf = a.conf;
|
|
11071
|
+
next.term = a.term;
|
|
11072
|
+
next.pred = a.pred;
|
|
10893
11073
|
migrateAccessors(a, next);
|
|
10894
11074
|
migrateInvariants(a, next);
|
|
10895
11075
|
migrateNullProto(a, next);
|
|
@@ -10914,8 +11094,8 @@ function $copy(a) {
|
|
|
10914
11094
|
return a;
|
|
10915
11095
|
}
|
|
10916
11096
|
function $arrMutContainer(arr, method, args) {
|
|
10917
|
-
const
|
|
10918
|
-
if (
|
|
11097
|
+
const shape2 = arr.shape;
|
|
11098
|
+
if (shape2.k !== "tuple" && shape2.k !== "arr") return arr;
|
|
10919
11099
|
const st = extStateOf(arr);
|
|
10920
11100
|
if (st === "frozen") throwStrictWrite();
|
|
10921
11101
|
if ((st === "sealed" || st === "nonext") && (method === "push" || method === "unshift" || method === "splice")) {
|
|
@@ -10925,9 +11105,9 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10925
11105
|
const asArrEl = (els) => els.length > 0 ? els.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
10926
11106
|
const writeBack = (next) => writeInPlace(arr, next);
|
|
10927
11107
|
if (method === "push" || method === "unshift") {
|
|
10928
|
-
if (
|
|
10929
|
-
const els = method === "push" ? [...
|
|
10930
|
-
const holes =
|
|
11108
|
+
if (shape2.k === "tuple") {
|
|
11109
|
+
const els = method === "push" ? [...shape2.elements, ...vals] : [...vals, ...shape2.elements];
|
|
11110
|
+
const holes = shape2.holes ? shape2.holes.map((h) => method === "push" ? h : h + vals.length) : void 0;
|
|
10931
11111
|
const conf = vals.reduce(
|
|
10932
11112
|
(acc, v2) => confJoin(acc, v2.conf),
|
|
10933
11113
|
arr.conf
|
|
@@ -10936,19 +11116,19 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10936
11116
|
abs({ k: "tuple", elements: els, holes }, void 0, void 0, conf)
|
|
10937
11117
|
);
|
|
10938
11118
|
}
|
|
10939
|
-
const el = vals.reduce((acc, v2) => joinAbs(acc, v2),
|
|
11119
|
+
const el = vals.reduce((acc, v2) => joinAbs(acc, v2), shape2.element);
|
|
10940
11120
|
return writeBack(
|
|
10941
11121
|
abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"))
|
|
10942
11122
|
);
|
|
10943
11123
|
}
|
|
10944
11124
|
if (method === "pop") {
|
|
10945
|
-
if (
|
|
10946
|
-
if (
|
|
10947
|
-
const newLen =
|
|
10948
|
-
const holes =
|
|
11125
|
+
if (shape2.k === "tuple") {
|
|
11126
|
+
if (shape2.elements.length === 0) return arr;
|
|
11127
|
+
const newLen = shape2.elements.length - 1;
|
|
11128
|
+
const holes = shape2.holes ? shape2.holes.filter((h) => h < newLen) : void 0;
|
|
10949
11129
|
return writeBack(
|
|
10950
11130
|
abs(
|
|
10951
|
-
{ k: "tuple", elements:
|
|
11131
|
+
{ k: "tuple", elements: shape2.elements.slice(0, -1), holes: holes && holes.length > 0 ? holes : void 0 },
|
|
10952
11132
|
void 0,
|
|
10953
11133
|
void 0,
|
|
10954
11134
|
arr.conf
|
|
@@ -10958,12 +11138,12 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10958
11138
|
return arr;
|
|
10959
11139
|
}
|
|
10960
11140
|
if (method === "shift") {
|
|
10961
|
-
if (
|
|
10962
|
-
if (
|
|
10963
|
-
const holes =
|
|
11141
|
+
if (shape2.k === "tuple") {
|
|
11142
|
+
if (shape2.elements.length === 0) return arr;
|
|
11143
|
+
const holes = shape2.holes ? shape2.holes.map((h) => h - 1).filter((h) => h >= 0) : void 0;
|
|
10964
11144
|
return writeBack(
|
|
10965
11145
|
abs(
|
|
10966
|
-
{ k: "tuple", elements:
|
|
11146
|
+
{ k: "tuple", elements: shape2.elements.slice(1), holes: holes && holes.length > 0 ? holes : void 0 },
|
|
10967
11147
|
void 0,
|
|
10968
11148
|
void 0,
|
|
10969
11149
|
arr.conf
|
|
@@ -10975,10 +11155,10 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10975
11155
|
if (method === "splice") {
|
|
10976
11156
|
validateIndexArg(vals[0], "splice start may not be convertible to a number");
|
|
10977
11157
|
validateIndexArg(vals[1], "splice deleteCount may not be convertible to a number");
|
|
10978
|
-
if (
|
|
11158
|
+
if (shape2.k === "tuple") {
|
|
10979
11159
|
return writeBack(
|
|
10980
11160
|
abs(
|
|
10981
|
-
{ k: "arr", element: asArrEl(
|
|
11161
|
+
{ k: "arr", element: asArrEl(shape2.elements) },
|
|
10982
11162
|
void 0,
|
|
10983
11163
|
void 0,
|
|
10984
11164
|
confJoin(arr.conf, "path")
|
|
@@ -10988,12 +11168,12 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10988
11168
|
return arr;
|
|
10989
11169
|
}
|
|
10990
11170
|
if (method === "reverse") {
|
|
10991
|
-
if (
|
|
10992
|
-
const len =
|
|
10993
|
-
const holes =
|
|
11171
|
+
if (shape2.k === "tuple") {
|
|
11172
|
+
const len = shape2.elements.length;
|
|
11173
|
+
const holes = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
|
|
10994
11174
|
return writeBack(
|
|
10995
11175
|
abs(
|
|
10996
|
-
{ k: "tuple", elements: [...
|
|
11176
|
+
{ k: "tuple", elements: [...shape2.elements].reverse(), holes },
|
|
10997
11177
|
void 0,
|
|
10998
11178
|
void 0,
|
|
10999
11179
|
arr.conf
|
|
@@ -11003,19 +11183,19 @@ function $arrMutContainer(arr, method, args) {
|
|
|
11003
11183
|
return arr;
|
|
11004
11184
|
}
|
|
11005
11185
|
if (method === "copyWithin") {
|
|
11006
|
-
return writeBack(copyWithinTuple(
|
|
11186
|
+
return writeBack(copyWithinTuple(shape2, vals));
|
|
11007
11187
|
}
|
|
11008
11188
|
if (method === "fill") {
|
|
11009
|
-
return writeBack(fillTuple(
|
|
11189
|
+
return writeBack(fillTuple(shape2, vals, arr));
|
|
11010
11190
|
}
|
|
11011
11191
|
if (method === "sort") {
|
|
11012
11192
|
validateCallableArg(vals[0], "sort comparator may not be callable", {
|
|
11013
11193
|
undefinedOk: true
|
|
11014
11194
|
});
|
|
11015
|
-
if (
|
|
11195
|
+
if (shape2.k === "tuple") {
|
|
11016
11196
|
return writeBack(
|
|
11017
11197
|
abs(
|
|
11018
|
-
{ k: "arr", element: asArrEl(
|
|
11198
|
+
{ k: "arr", element: asArrEl(shape2.elements) },
|
|
11019
11199
|
void 0,
|
|
11020
11200
|
void 0,
|
|
11021
11201
|
confJoin(arr.conf, "path")
|
|
@@ -11282,9 +11462,9 @@ function $spread(a, b) {
|
|
|
11282
11462
|
if (acc && bb.shape.k === "obj") {
|
|
11283
11463
|
let changed = false;
|
|
11284
11464
|
const slots = { ...bb.shape.slots };
|
|
11285
|
-
for (const [k,
|
|
11286
|
-
if (
|
|
11287
|
-
setSlot(slots, k, { value:
|
|
11465
|
+
for (const [k, fn2] of acc) {
|
|
11466
|
+
if (fn2.get) {
|
|
11467
|
+
setSlot(slots, k, { value: fn2.get(bb) });
|
|
11288
11468
|
changed = true;
|
|
11289
11469
|
}
|
|
11290
11470
|
}
|
|
@@ -11342,8 +11522,8 @@ function $objRest(o, keys) {
|
|
|
11342
11522
|
}
|
|
11343
11523
|
if (!isObj(o)) {
|
|
11344
11524
|
if (o.shape.k === "any") {
|
|
11345
|
-
const
|
|
11346
|
-
return { shape:
|
|
11525
|
+
const shape3 = { k: "obj", slots: {}, open: true };
|
|
11526
|
+
return { shape: shape3, conf: "partial" };
|
|
11347
11527
|
}
|
|
11348
11528
|
return unknown;
|
|
11349
11529
|
}
|
|
@@ -11355,9 +11535,9 @@ function $objRest(o, keys) {
|
|
|
11355
11535
|
setSlot(slots, k, s);
|
|
11356
11536
|
}
|
|
11357
11537
|
if (o.shape.open) openRest = true;
|
|
11358
|
-
const
|
|
11359
|
-
if (openRest)
|
|
11360
|
-
return { shape, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
|
|
11538
|
+
const shape2 = { k: "obj", slots };
|
|
11539
|
+
if (openRest) shape2.open = true;
|
|
11540
|
+
return { shape: shape2, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
|
|
11361
11541
|
}
|
|
11362
11542
|
function $arrRest(a, start) {
|
|
11363
11543
|
const mi = matchIterElements(a);
|
|
@@ -11563,30 +11743,30 @@ function elemsOf(a) {
|
|
|
11563
11743
|
return [unknown];
|
|
11564
11744
|
}
|
|
11565
11745
|
function $forInKeys(o) {
|
|
11566
|
-
const
|
|
11567
|
-
if (
|
|
11568
|
-
const members =
|
|
11746
|
+
const shape2 = o.shape;
|
|
11747
|
+
if (shape2.k === "sum") {
|
|
11748
|
+
const members = shape2.members.map((m) => $forInKeys(m));
|
|
11569
11749
|
return members.length ? members.reduce((a, b) => joinAbs(a, b)) : unknown;
|
|
11570
11750
|
}
|
|
11571
11751
|
const isArrayIndexKey = (k) => {
|
|
11572
11752
|
const n = Number(k);
|
|
11573
11753
|
return k !== "" && String(n) === k && Number.isInteger(n) && n >= 0 && n < 4294967295;
|
|
11574
11754
|
};
|
|
11575
|
-
if (
|
|
11576
|
-
const keys = enumOwnKeys(o,
|
|
11755
|
+
if (shape2.k === "obj") {
|
|
11756
|
+
const keys = enumOwnKeys(o, shape2.slots);
|
|
11577
11757
|
const intKeys = keys.filter(isArrayIndexKey).sort((a, b) => Number(a) - Number(b));
|
|
11578
11758
|
const strKeys = keys.filter((k) => !isArrayIndexKey(k));
|
|
11579
11759
|
return $arr([...intKeys, ...strKeys].map((k) => $lit(k)));
|
|
11580
11760
|
}
|
|
11581
|
-
if (
|
|
11761
|
+
if (shape2.k === "tuple") {
|
|
11582
11762
|
const idxs = [];
|
|
11583
|
-
for (let i = 0; i <
|
|
11584
|
-
if (
|
|
11763
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
11764
|
+
if (shape2.holes?.includes(i)) continue;
|
|
11585
11765
|
idxs.push(i);
|
|
11586
11766
|
}
|
|
11587
11767
|
return $arr(idxs.map((i) => $lit(String(i))));
|
|
11588
11768
|
}
|
|
11589
|
-
if (
|
|
11769
|
+
if (shape2.k === "arr") {
|
|
11590
11770
|
return abs({ k: "arr", element: $lit("0") }, void 0, void 0, "partial");
|
|
11591
11771
|
}
|
|
11592
11772
|
const svR = litValue(o);
|
|
@@ -11595,11 +11775,11 @@ function $forInKeys(o) {
|
|
|
11595
11775
|
return $arr(Array.from({ length: sv.length }, (_, i) => $lit(String(i))));
|
|
11596
11776
|
}
|
|
11597
11777
|
const isNullishLit2 = o.term?.op === "lit" && (o.term.value === null || o.term.value === void 0);
|
|
11598
|
-
if (!isNullishLit2 && (
|
|
11778
|
+
if (!isNullishLit2 && (shape2.k === "any" || shape2.k === "unknown" || shape2.k === "prim" && shape2.type === "string")) {
|
|
11599
11779
|
return abs({ k: "arr", element: str() }, void 0, void 0, "partial");
|
|
11600
11780
|
}
|
|
11601
|
-
if (
|
|
11602
|
-
const inner =
|
|
11781
|
+
if (shape2.k === "brand") {
|
|
11782
|
+
const inner = shape2.shape;
|
|
11603
11783
|
if (inner.shape.k === "obj") {
|
|
11604
11784
|
const keys = enumOwnKeys(inner, inner.shape.slots);
|
|
11605
11785
|
return $arr(keys.map((k) => $lit(k)));
|
|
@@ -11625,9 +11805,9 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
|
|
|
11625
11805
|
if (!exitJoin || !pack || !unpack) return;
|
|
11626
11806
|
unpack(joinAbs(exitJoin, pack()));
|
|
11627
11807
|
};
|
|
11628
|
-
const
|
|
11808
|
+
const shape2 = iterable.shape;
|
|
11629
11809
|
const forAwait = opts?.forAwait === true;
|
|
11630
|
-
const asyncOnly = forAwait &&
|
|
11810
|
+
const asyncOnly = forAwait && shape2.k === "obj" && !shape2.slots["@@iterator"] && !!shape2.slots["@@asyncIterator"];
|
|
11631
11811
|
if (forAwait) {
|
|
11632
11812
|
const kind = asyncIterabilityKind(iterable);
|
|
11633
11813
|
if (kind === "definite") throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -11642,7 +11822,7 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
|
|
|
11642
11822
|
const items = asyncOnly ? [unknown] : forAwait ? elemsOf(iterable).map(awaitElem) : $elems(iterable);
|
|
11643
11823
|
const svR = litValue(iterable);
|
|
11644
11824
|
const sv = svR.ok ? svR.value : void 0;
|
|
11645
|
-
const knownLen =
|
|
11825
|
+
const knownLen = shape2.k === "tuple" ? shape2.elements.length : typeof sv === "string" ? [...sv].length : collectionExactLen(iterable) ?? sideIterLen(iterable);
|
|
11646
11826
|
const unbounded = knownLen === void 0;
|
|
11647
11827
|
if (unbounded) snapExit();
|
|
11648
11828
|
const concreteCap = Math.max(maxIters, MAX_CONCRETE_LOOP_ITERS);
|
|
@@ -12061,9 +12241,9 @@ function $set(o, key, value) {
|
|
|
12061
12241
|
}
|
|
12062
12242
|
return o;
|
|
12063
12243
|
}
|
|
12064
|
-
const
|
|
12244
|
+
const shape2 = o.shape;
|
|
12065
12245
|
const st = extStateOf(o);
|
|
12066
|
-
const hasKey = Object.prototype.hasOwnProperty.call(
|
|
12246
|
+
const hasKey = Object.prototype.hasOwnProperty.call(shape2.slots, key);
|
|
12067
12247
|
if (st === "frozen") throwStrictWrite();
|
|
12068
12248
|
if ((st === "sealed" || st === "nonext") && !hasKey) throwStrictWrite();
|
|
12069
12249
|
if (getPropFlags(o)?.get(key)?.writable === false) throwStrictWrite();
|
|
@@ -12075,7 +12255,7 @@ function $set(o, key, value) {
|
|
|
12075
12255
|
if (key === "__proto__" && !isNullProtoObj(o)) {
|
|
12076
12256
|
return $setProto(o, value);
|
|
12077
12257
|
}
|
|
12078
|
-
setSlot(
|
|
12258
|
+
setSlot(shape2.slots, key, { value: asAbsVal(value) });
|
|
12079
12259
|
o.conf = confJoin(o.conf, value.conf);
|
|
12080
12260
|
clearStaleTermPred(o);
|
|
12081
12261
|
return o;
|
|
@@ -12235,7 +12415,7 @@ function instanceOf(left, rightClassName, env) {
|
|
|
12235
12415
|
term: { op: "lit", value: v2 },
|
|
12236
12416
|
conf: "exact"
|
|
12237
12417
|
});
|
|
12238
|
-
const
|
|
12418
|
+
const partial2 = () => ({ shape: { k: "prim", type: "boolean" }, conf: "partial" });
|
|
12239
12419
|
switch (left.shape.k) {
|
|
12240
12420
|
case "brand": {
|
|
12241
12421
|
if (rightClassName === "Object") return t(true);
|
|
@@ -12245,28 +12425,28 @@ function instanceOf(left, rightClassName, env) {
|
|
|
12245
12425
|
case "tuple":
|
|
12246
12426
|
if (rightClassName === "Array" || rightClassName === "Object") return t(true);
|
|
12247
12427
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12248
|
-
return
|
|
12428
|
+
return partial2();
|
|
12249
12429
|
// 可能是 Array 子类
|
|
12250
12430
|
case "obj":
|
|
12251
12431
|
if (rightClassName === "Object") return t(true);
|
|
12252
12432
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12253
|
-
return
|
|
12433
|
+
return partial2();
|
|
12254
12434
|
case "fn":
|
|
12255
12435
|
if (rightClassName === "Function" || rightClassName === "Object") return t(true);
|
|
12256
12436
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12257
|
-
return
|
|
12437
|
+
return partial2();
|
|
12258
12438
|
case "eff":
|
|
12259
12439
|
if (left.shape.eff === "promise") {
|
|
12260
12440
|
if (rightClassName === "Promise" || rightClassName === "Object") return t(true);
|
|
12261
12441
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12262
|
-
return
|
|
12442
|
+
return partial2();
|
|
12263
12443
|
}
|
|
12264
12444
|
if (left.shape.eff === "generator") {
|
|
12265
12445
|
if (rightClassName === "Generator" || rightClassName === "Object") return t(true);
|
|
12266
12446
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12267
|
-
return
|
|
12447
|
+
return partial2();
|
|
12268
12448
|
}
|
|
12269
|
-
return
|
|
12449
|
+
return partial2();
|
|
12270
12450
|
case "prim":
|
|
12271
12451
|
return t(false);
|
|
12272
12452
|
// 原始值无装箱
|
|
@@ -12625,13 +12805,13 @@ function setGenJoinOverride(v2) {
|
|
|
12625
12805
|
function bumpGenPathSensitive() {
|
|
12626
12806
|
genPathSensitive++;
|
|
12627
12807
|
}
|
|
12628
|
-
function withIsolatedYields(
|
|
12808
|
+
function withIsolatedYields(fn2) {
|
|
12629
12809
|
const top = yieldStack[yieldStack.length - 1];
|
|
12630
|
-
if (!top) return { v:
|
|
12810
|
+
if (!top) return { v: fn2(), ys: null };
|
|
12631
12811
|
const armYs = [];
|
|
12632
12812
|
yieldStack[yieldStack.length - 1] = armYs;
|
|
12633
12813
|
try {
|
|
12634
|
-
return { v:
|
|
12814
|
+
return { v: fn2(), ys: armYs };
|
|
12635
12815
|
} finally {
|
|
12636
12816
|
yieldStack[yieldStack.length - 1] = top;
|
|
12637
12817
|
}
|
|
@@ -13054,10 +13234,10 @@ function $switch(disc, cases, dflt) {
|
|
|
13054
13234
|
beginCollectionFork();
|
|
13055
13235
|
const armOverlays2 = [];
|
|
13056
13236
|
const armYsList = [];
|
|
13057
|
-
const runArm = (
|
|
13237
|
+
const runArm = (fn2) => {
|
|
13058
13238
|
pushCollectionArm();
|
|
13059
13239
|
try {
|
|
13060
|
-
const r = withIsolatedYields(() => runForkArm(
|
|
13240
|
+
const r = withIsolatedYields(() => runForkArm(fn2, exits));
|
|
13061
13241
|
armYsList.push(r.ys);
|
|
13062
13242
|
return r.v;
|
|
13063
13243
|
} finally {
|
|
@@ -13374,6 +13554,58 @@ function $narrowTypeOf(a, typeOf, keep) {
|
|
|
13374
13554
|
if (kept.length === 0) return a;
|
|
13375
13555
|
return kept.length === 1 ? kept[0] : { ...a, shape: { k: "sum", members: kept } };
|
|
13376
13556
|
}
|
|
13557
|
+
function litRefutesEq(other, v2) {
|
|
13558
|
+
return other !== v2;
|
|
13559
|
+
}
|
|
13560
|
+
function memberEqClass(m, key, litAbs, value) {
|
|
13561
|
+
const sh = m.shape;
|
|
13562
|
+
if (sh.k === "obj") {
|
|
13563
|
+
const slots = sh.slots;
|
|
13564
|
+
if (!Object.prototype.hasOwnProperty.call(slots, key)) {
|
|
13565
|
+
return sh.open ? "may" : "never";
|
|
13566
|
+
}
|
|
13567
|
+
const slotValue = slots[key].value;
|
|
13568
|
+
if (slotValue.shape.k === "any" || slotValue.shape.k === "unknown") return "may";
|
|
13569
|
+
const shapeOnly = (s) => abs(s, void 0, void 0, "exact");
|
|
13570
|
+
if (!leqAbs(shapeOnly(litAbs.shape), shapeOnly(slotValue.shape)).ok) return "never";
|
|
13571
|
+
const t = slotValue.term;
|
|
13572
|
+
const p = slotValue.pred;
|
|
13573
|
+
if (!t || !p || p.op === "true") return "may";
|
|
13574
|
+
const litTerm = lit(value);
|
|
13575
|
+
if (implies(p, { op: "eq", a: t, b: litTerm })) return "only";
|
|
13576
|
+
if (implies(p, { op: "ne", a: t, b: litTerm })) return "never";
|
|
13577
|
+
const conjuncts = [];
|
|
13578
|
+
const visit = (c) => {
|
|
13579
|
+
if (c.op === "and") {
|
|
13580
|
+
c.args.forEach(visit);
|
|
13581
|
+
return;
|
|
13582
|
+
}
|
|
13583
|
+
conjuncts.push(c);
|
|
13584
|
+
};
|
|
13585
|
+
visit(p);
|
|
13586
|
+
for (const c of conjuncts) {
|
|
13587
|
+
if (c.op !== "eq") continue;
|
|
13588
|
+
const other = termEquals(c.a, t) && c.b.op === "lit" ? c.b.value : termEquals(c.b, t) && c.a.op === "lit" ? c.a.value : void 0;
|
|
13589
|
+
if (other !== void 0 && litRefutesEq(other, value)) return "never";
|
|
13590
|
+
}
|
|
13591
|
+
return "may";
|
|
13592
|
+
}
|
|
13593
|
+
if (m.term?.op === "lit") return "never";
|
|
13594
|
+
return "may";
|
|
13595
|
+
}
|
|
13596
|
+
function $narrowMemberEq(a, key, value, keep) {
|
|
13597
|
+
if (!a || typeof a !== "object" || !("shape" in a)) return a;
|
|
13598
|
+
if (a.shape.k !== "sum") return a;
|
|
13599
|
+
const litAbs = typeof value === "string" ? strLit(value) : typeof value === "number" ? numLit(value) : boolLit(value);
|
|
13600
|
+
const members = a.shape.members;
|
|
13601
|
+
const kept = members.filter((m) => {
|
|
13602
|
+
const c = memberEqClass(m, key, litAbs, value);
|
|
13603
|
+
return keep ? c !== "never" : c !== "only";
|
|
13604
|
+
});
|
|
13605
|
+
if (kept.length === members.length) return a;
|
|
13606
|
+
if (kept.length === 0) return a;
|
|
13607
|
+
return kept.length === 1 ? kept[0] : { ...a, shape: { k: "sum", members: kept } };
|
|
13608
|
+
}
|
|
13377
13609
|
function primShapeOfTypeOf(typeOf) {
|
|
13378
13610
|
switch (typeOf) {
|
|
13379
13611
|
case "string":
|
|
@@ -13503,6 +13735,773 @@ var BoundedLruMap = class {
|
|
|
13503
13735
|
}
|
|
13504
13736
|
};
|
|
13505
13737
|
|
|
13738
|
+
// src/algebra/constraint.ts
|
|
13739
|
+
var SELF = "__nudo_self__";
|
|
13740
|
+
function selfTerm() {
|
|
13741
|
+
return v(SELF);
|
|
13742
|
+
}
|
|
13743
|
+
function getTerm(obj2, key) {
|
|
13744
|
+
return app("get", [obj2, lit(key)]);
|
|
13745
|
+
}
|
|
13746
|
+
function lenTerm(t) {
|
|
13747
|
+
return app("length", [t]);
|
|
13748
|
+
}
|
|
13749
|
+
function isConstraint(x) {
|
|
13750
|
+
return !!x && typeof x === "object" && x.__nudoConstraint === true;
|
|
13751
|
+
}
|
|
13752
|
+
function isNudoConstraint(x) {
|
|
13753
|
+
return isConstraint(x);
|
|
13754
|
+
}
|
|
13755
|
+
var intFlaggedBuilders = /* @__PURE__ */ new WeakSet();
|
|
13756
|
+
function isIntFlag(c) {
|
|
13757
|
+
return c.int === true || intFlaggedBuilders.has(c);
|
|
13758
|
+
}
|
|
13759
|
+
function makeBuilder(prim, preds, extra) {
|
|
13760
|
+
const fields = extra?.fields;
|
|
13761
|
+
const element = extra?.element;
|
|
13762
|
+
const isInt = extra?.int;
|
|
13763
|
+
const optional = extra?.optional;
|
|
13764
|
+
const members = extra?.members;
|
|
13765
|
+
const fnSlot = extra?.fn;
|
|
13766
|
+
const lazySlot = extra?.lazy;
|
|
13767
|
+
const base = {
|
|
13768
|
+
__nudoConstraint: true,
|
|
13769
|
+
...prim ? { prim } : {},
|
|
13770
|
+
preds: [...preds],
|
|
13771
|
+
...fields ? { fields } : {},
|
|
13772
|
+
...element ? { element } : {},
|
|
13773
|
+
...optional ? { isOptional: true } : {},
|
|
13774
|
+
...members ? { members } : {},
|
|
13775
|
+
...fnSlot ? { fn: fnSlot } : {},
|
|
13776
|
+
...lazySlot ? { lazy: lazySlot } : {}
|
|
13777
|
+
};
|
|
13778
|
+
const add2 = (p) => makeBuilder(prim, [...preds, p], extra);
|
|
13779
|
+
const builder = Object.assign(
|
|
13780
|
+
/* @__PURE__ */ Object.create(null),
|
|
13781
|
+
base,
|
|
13782
|
+
{
|
|
13783
|
+
gt: (n) => add2(gt(selfTerm(), lit(n))),
|
|
13784
|
+
ge: (n) => add2(ge(selfTerm(), lit(n))),
|
|
13785
|
+
lt: (n) => add2(lt(selfTerm(), lit(n))),
|
|
13786
|
+
le: (n) => add2(le(selfTerm(), lit(n))),
|
|
13787
|
+
int: () => makeBuilder(prim ?? "number", preds, { ...extra, int: true }),
|
|
13788
|
+
min: (n) => add2(ge(lenTerm(selfTerm()), lit(n))),
|
|
13789
|
+
max: (n) => add2(le(lenTerm(selfTerm()), lit(n))),
|
|
13790
|
+
length: (n) => add2(and(ge(lenTerm(selfTerm()), lit(n)), le(lenTerm(selfTerm()), lit(n)))),
|
|
13791
|
+
shift: (n) => {
|
|
13792
|
+
if (!Number.isFinite(n))
|
|
13793
|
+
throw new Error("nudo shift(): offset must be a finite number");
|
|
13794
|
+
if (fields || element || members || fnSlot || lazySlot)
|
|
13795
|
+
throw new Error("nudo shift(): only numeric scalar constraint chains are allowed (shape/array/union/fn are not supported)");
|
|
13796
|
+
if (prim !== void 0 && prim !== "number")
|
|
13797
|
+
throw new Error(`nudo shift(): only numeric chains are allowed (prim=${prim})`);
|
|
13798
|
+
return makeBuilder(prim, shiftBoundPreds(preds, n), extra);
|
|
13799
|
+
},
|
|
13800
|
+
optional: () => makeBuilder(prim, preds, { ...extra, optional: true })
|
|
13801
|
+
}
|
|
13802
|
+
);
|
|
13803
|
+
if (isInt) intFlaggedBuilders.add(builder);
|
|
13804
|
+
return builder;
|
|
13805
|
+
}
|
|
13806
|
+
function shiftBoundPreds(preds, n) {
|
|
13807
|
+
return preds.map((p) => {
|
|
13808
|
+
if (p.op !== "gt" && p.op !== "ge" && p.op !== "lt" && p.op !== "le")
|
|
13809
|
+
throw new Error(`nudo shift(): predicate ${p.op} is not supported (only gt/ge/lt/le constant bounds)`);
|
|
13810
|
+
const { a, b } = p;
|
|
13811
|
+
if (b.op !== "lit" || typeof b.value !== "number")
|
|
13812
|
+
throw new Error("nudo shift(): the right-hand side of a constant bound must be a numeric literal");
|
|
13813
|
+
if (termHasApp(a, "length") || termHasApp(b, "length"))
|
|
13814
|
+
throw new Error("nudo shift(): length(...) bounds are not supported");
|
|
13815
|
+
return { op: p.op, a, b: lit(b.value + n) };
|
|
13816
|
+
});
|
|
13817
|
+
}
|
|
13818
|
+
function termHasApp(t, fn2) {
|
|
13819
|
+
if (t.op !== "app") return false;
|
|
13820
|
+
if (t.fn === fn2) return true;
|
|
13821
|
+
return t.args.some((x) => termHasApp(x, fn2));
|
|
13822
|
+
}
|
|
13823
|
+
function number() {
|
|
13824
|
+
return makeBuilder("number", []);
|
|
13825
|
+
}
|
|
13826
|
+
function string() {
|
|
13827
|
+
return makeBuilder("string", []);
|
|
13828
|
+
}
|
|
13829
|
+
function boolean() {
|
|
13830
|
+
return makeBuilder("boolean", []);
|
|
13831
|
+
}
|
|
13832
|
+
function any() {
|
|
13833
|
+
return makeBuilder(void 0, []);
|
|
13834
|
+
}
|
|
13835
|
+
function array(item) {
|
|
13836
|
+
return makeBuilder(void 0, [], {
|
|
13837
|
+
element: asNestedConstraint(item, "array(item)")
|
|
13838
|
+
});
|
|
13839
|
+
}
|
|
13840
|
+
function shape(fields) {
|
|
13841
|
+
const mapped = {};
|
|
13842
|
+
for (const [k, v2] of Object.entries(fields)) {
|
|
13843
|
+
const constraint = asNestedConstraint(v2, `shape \u5B57\u6BB5 '${k}'`);
|
|
13844
|
+
mapped[k] = {
|
|
13845
|
+
constraint,
|
|
13846
|
+
...constraint.isOptional ? { optional: true } : {}
|
|
13847
|
+
};
|
|
13848
|
+
}
|
|
13849
|
+
return makeBuilder(void 0, [], { fields: mapped });
|
|
13850
|
+
}
|
|
13851
|
+
function toPlainConstraint(c) {
|
|
13852
|
+
if (!isConstraint(c))
|
|
13853
|
+
throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
|
|
13854
|
+
return {
|
|
13855
|
+
__nudoConstraint: true,
|
|
13856
|
+
...c.prim ? { prim: c.prim } : {},
|
|
13857
|
+
preds: [...c.preds],
|
|
13858
|
+
...c.fields ? { fields: c.fields } : {},
|
|
13859
|
+
...c.element ? { element: c.element } : {},
|
|
13860
|
+
// isIntFlag 统一读取:builder(int 是方法)查 WeakSet,纯数据看 === true
|
|
13861
|
+
...isIntFlag(c) ? { int: true } : {},
|
|
13862
|
+
...c.isOptional ? { isOptional: true } : {},
|
|
13863
|
+
...c.members ? { members: c.members } : {},
|
|
13864
|
+
...c.fn ? { fn: c.fn } : {},
|
|
13865
|
+
...c.lazy ? { lazy: c.lazy } : {}
|
|
13866
|
+
};
|
|
13867
|
+
}
|
|
13868
|
+
function litC(v2) {
|
|
13869
|
+
const prim = typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : typeof v2 === "boolean" ? "boolean" : void 0;
|
|
13870
|
+
return makeBuilder(prim, [eq(selfTerm(), lit(v2))]);
|
|
13871
|
+
}
|
|
13872
|
+
function asNestedConstraint(x, ctx2) {
|
|
13873
|
+
if (isConstraint(x)) return toPlainConstraint(x);
|
|
13874
|
+
if (x === null || x === void 0 || typeof x === "number" || typeof x === "string" || typeof x === "boolean") {
|
|
13875
|
+
return toPlainConstraint(litC(x));
|
|
13876
|
+
}
|
|
13877
|
+
throw new Error(
|
|
13878
|
+
`nudo: ${ctx2} expects a constraint value (number()/string()/\u2026) or a concrete literal; received a non-constraint`
|
|
13879
|
+
);
|
|
13880
|
+
}
|
|
13881
|
+
function union(...cs) {
|
|
13882
|
+
if (cs.length === 0)
|
|
13883
|
+
throw new Error("nudo union(): at least one member constraint is required");
|
|
13884
|
+
return makeBuilder(void 0, [], {
|
|
13885
|
+
members: cs.map((c) => asNestedConstraint(c, "union member"))
|
|
13886
|
+
});
|
|
13887
|
+
}
|
|
13888
|
+
function nullable(c) {
|
|
13889
|
+
return makeBuilder(void 0, [], {
|
|
13890
|
+
members: [
|
|
13891
|
+
asNestedConstraint(c, "nullable()"),
|
|
13892
|
+
toPlainConstraint(litC(null)),
|
|
13893
|
+
toPlainConstraint(litC(void 0))
|
|
13894
|
+
]
|
|
13895
|
+
});
|
|
13896
|
+
}
|
|
13897
|
+
function lazy(thunk) {
|
|
13898
|
+
if (typeof thunk !== "function")
|
|
13899
|
+
throw new Error("nudo lazy(): expects a thunk function () => constraint");
|
|
13900
|
+
return makeBuilder(void 0, [], { lazy: thunk });
|
|
13901
|
+
}
|
|
13902
|
+
var LAZY_TEMPLATE_DEPTH = 3;
|
|
13903
|
+
var lazyDerefMemo = /* @__PURE__ */ new WeakMap();
|
|
13904
|
+
function derefConstraint(c) {
|
|
13905
|
+
const thunk = c.lazy;
|
|
13906
|
+
if (!thunk) return c;
|
|
13907
|
+
const memoized = lazyDerefMemo.get(thunk);
|
|
13908
|
+
if (memoized) return memoized;
|
|
13909
|
+
const out = thunk();
|
|
13910
|
+
if (!isConstraint(out))
|
|
13911
|
+
throw new Error(
|
|
13912
|
+
"nudo lazy(): the thunk must return a constraint (number()/string()/shape()/\u2026)"
|
|
13913
|
+
);
|
|
13914
|
+
const normalized = toPlainConstraint(out);
|
|
13915
|
+
lazyDerefMemo.set(thunk, normalized);
|
|
13916
|
+
return normalized;
|
|
13917
|
+
}
|
|
13918
|
+
function constraintAdmitsNullish(c, seen) {
|
|
13919
|
+
if (c.lazy) {
|
|
13920
|
+
const s = seen ?? /* @__PURE__ */ new Set();
|
|
13921
|
+
if (s.has(c.lazy)) return false;
|
|
13922
|
+
s.add(c.lazy);
|
|
13923
|
+
return constraintAdmitsNullish(derefConstraint(c), s);
|
|
13924
|
+
}
|
|
13925
|
+
if (c.members)
|
|
13926
|
+
return c.members.some((m) => constraintAdmitsNullish(m, seen));
|
|
13927
|
+
if (!c.prim && c.preds.length === 0 && !c.fields && !c.element && !c.fn) return true;
|
|
13928
|
+
for (const p of c.preds) {
|
|
13929
|
+
for (const flat of p.op === "and" ? p.args : [p]) {
|
|
13930
|
+
if (flat.op !== "eq") continue;
|
|
13931
|
+
for (const side of [flat.a, flat.b]) {
|
|
13932
|
+
if (side.op === "lit" && (side.value === null || side.value === void 0)) return true;
|
|
13933
|
+
}
|
|
13934
|
+
}
|
|
13935
|
+
}
|
|
13936
|
+
return false;
|
|
13937
|
+
}
|
|
13938
|
+
function fn(params, returns, opts) {
|
|
13939
|
+
const normalized = {};
|
|
13940
|
+
for (const [k, v2] of Object.entries(params)) {
|
|
13941
|
+
normalized[k] = asNestedConstraint(v2, `fn param '${k}'`);
|
|
13942
|
+
}
|
|
13943
|
+
return makeBuilder(void 0, [], {
|
|
13944
|
+
fn: {
|
|
13945
|
+
params: normalized,
|
|
13946
|
+
...returns !== void 0 ? { returns: asNestedConstraint(returns, "fn return value") } : {},
|
|
13947
|
+
...opts?.throws !== void 0 ? { throws: asNestedConstraint(opts.throws, "fn throws") } : {}
|
|
13948
|
+
}
|
|
13949
|
+
});
|
|
13950
|
+
}
|
|
13951
|
+
function andC(...cs) {
|
|
13952
|
+
if (cs.length === 0)
|
|
13953
|
+
throw new Error("nudo and(): at least one constraint is required");
|
|
13954
|
+
let prim;
|
|
13955
|
+
let isInt = false;
|
|
13956
|
+
let allOptional = true;
|
|
13957
|
+
const preds = [];
|
|
13958
|
+
for (const c0 of cs) {
|
|
13959
|
+
if (!isConstraint(c0))
|
|
13960
|
+
throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
|
|
13961
|
+
const c = derefConstraint(c0);
|
|
13962
|
+
if (c.fields || c.element || c.members || c.fn)
|
|
13963
|
+
throw new Error("nudo and(): Phase 1 supports scalar constraint conjunction only (shape/array/union/fn are not supported)");
|
|
13964
|
+
if (c.prim) {
|
|
13965
|
+
if (prim !== void 0 && prim !== c.prim)
|
|
13966
|
+
throw new Error(`nudo and(): inconsistent prim (${prim} vs ${c.prim})`);
|
|
13967
|
+
prim = c.prim;
|
|
13968
|
+
}
|
|
13969
|
+
preds.push(...c.preds);
|
|
13970
|
+
if (isIntFlag(c)) isInt = true;
|
|
13971
|
+
if (!c.isOptional) allOptional = false;
|
|
13972
|
+
}
|
|
13973
|
+
return makeBuilder(prim, preds, {
|
|
13974
|
+
...isInt ? { int: true } : {},
|
|
13975
|
+
...allOptional ? { optional: true } : {}
|
|
13976
|
+
});
|
|
13977
|
+
}
|
|
13978
|
+
function partial(c) {
|
|
13979
|
+
if (!isConstraint(c))
|
|
13980
|
+
throw new Error("nudo partial(): only shape(...) constraints are accepted");
|
|
13981
|
+
const d = derefConstraint(c);
|
|
13982
|
+
if (!d.fields)
|
|
13983
|
+
throw new Error("nudo partial(): only shape(...) constraints are accepted");
|
|
13984
|
+
const fields = {};
|
|
13985
|
+
for (const [k, f] of Object.entries(d.fields)) {
|
|
13986
|
+
fields[k] = {
|
|
13987
|
+
constraint: { ...toPlainConstraint(f.constraint), isOptional: true },
|
|
13988
|
+
optional: true
|
|
13989
|
+
};
|
|
13990
|
+
}
|
|
13991
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
13992
|
+
}
|
|
13993
|
+
function pick(c, keys) {
|
|
13994
|
+
if (!isConstraint(c))
|
|
13995
|
+
throw new Error("nudo pick(): only shape(...) constraints are accepted");
|
|
13996
|
+
const d = derefConstraint(c);
|
|
13997
|
+
if (!d.fields)
|
|
13998
|
+
throw new Error("nudo pick(): only shape(...) constraints are accepted");
|
|
13999
|
+
const fields = {};
|
|
14000
|
+
for (const k of keys) {
|
|
14001
|
+
const f = d.fields[k];
|
|
14002
|
+
if (f) fields[k] = f;
|
|
14003
|
+
}
|
|
14004
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
14005
|
+
}
|
|
14006
|
+
function omit(c, keys) {
|
|
14007
|
+
if (!isConstraint(c))
|
|
14008
|
+
throw new Error("nudo omit(): only shape(...) constraints are accepted");
|
|
14009
|
+
const d = derefConstraint(c);
|
|
14010
|
+
if (!d.fields)
|
|
14011
|
+
throw new Error("nudo omit(): only shape(...) constraints are accepted");
|
|
14012
|
+
const drop = new Set(keys);
|
|
14013
|
+
const fields = {};
|
|
14014
|
+
for (const [k, f] of Object.entries(d.fields)) {
|
|
14015
|
+
if (!drop.has(k)) fields[k] = f;
|
|
14016
|
+
}
|
|
14017
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
14018
|
+
}
|
|
14019
|
+
var CONSTRAINT_BUILDERS = {
|
|
14020
|
+
number,
|
|
14021
|
+
string,
|
|
14022
|
+
boolean,
|
|
14023
|
+
any,
|
|
14024
|
+
array,
|
|
14025
|
+
shape,
|
|
14026
|
+
lit: litC,
|
|
14027
|
+
union,
|
|
14028
|
+
nullable,
|
|
14029
|
+
lazy,
|
|
14030
|
+
fn,
|
|
14031
|
+
and: andC,
|
|
14032
|
+
partial,
|
|
14033
|
+
pick,
|
|
14034
|
+
omit
|
|
14035
|
+
};
|
|
14036
|
+
var CONSTRAINT_BUILDER_NAMES = Object.keys(
|
|
14037
|
+
CONSTRAINT_BUILDERS
|
|
14038
|
+
);
|
|
14039
|
+
var CONSTRAINT_EXPR_RE = new RegExp(
|
|
14040
|
+
`^(${CONSTRAINT_BUILDER_NAMES.join("|")})\\s*\\(`
|
|
14041
|
+
);
|
|
14042
|
+
function substTerm(t, paramName) {
|
|
14043
|
+
if (t.op === "var" && t.id === SELF) return v(paramName);
|
|
14044
|
+
if (t.op === "app" && t.fn === "get" && t.args.length === 2) {
|
|
14045
|
+
return getTerm(substTerm(t.args[0], paramName), String(
|
|
14046
|
+
t.args[1].op === "lit" ? t.args[1].value : ""
|
|
14047
|
+
));
|
|
14048
|
+
}
|
|
14049
|
+
return t;
|
|
14050
|
+
}
|
|
14051
|
+
function substPred2(p, paramName) {
|
|
14052
|
+
switch (p.op) {
|
|
14053
|
+
case "gt":
|
|
14054
|
+
case "ge":
|
|
14055
|
+
case "lt":
|
|
14056
|
+
case "le":
|
|
14057
|
+
case "eq":
|
|
14058
|
+
case "ne": {
|
|
14059
|
+
return { op: p.op, a: substTerm(p.a, paramName), b: substTerm(p.b, paramName) };
|
|
14060
|
+
}
|
|
14061
|
+
case "typeof": {
|
|
14062
|
+
return { op: "typeof", t: substTerm(p.t, paramName), type: p.type };
|
|
14063
|
+
}
|
|
14064
|
+
case "and":
|
|
14065
|
+
return and(...p.args.map((x) => substPred2(x, paramName)));
|
|
14066
|
+
default:
|
|
14067
|
+
return p;
|
|
14068
|
+
}
|
|
14069
|
+
}
|
|
14070
|
+
function instantiateConstraint(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
|
|
14071
|
+
if (c.lazy) {
|
|
14072
|
+
if (depth <= 0) return pTrue;
|
|
14073
|
+
return instantiateConstraint(derefConstraint(c), paramName, depth - 1);
|
|
14074
|
+
}
|
|
14075
|
+
if (c.fields) {
|
|
14076
|
+
const parts = [];
|
|
14077
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14078
|
+
if (field.optional || field.constraint.isOptional) continue;
|
|
14079
|
+
const fieldTerm = getTerm(v(paramName), key);
|
|
14080
|
+
parts.push(instantiateOnTerm(field.constraint, fieldTerm, depth));
|
|
14081
|
+
}
|
|
14082
|
+
if (c.prim) parts.push(ptypeof(v(paramName), primToTypeof(c.prim)));
|
|
14083
|
+
if (parts.length === 0) return { op: "true" };
|
|
14084
|
+
return parts.length === 1 ? parts[0] : and(...parts);
|
|
14085
|
+
}
|
|
14086
|
+
if (c.members) {
|
|
14087
|
+
const disj = or(
|
|
14088
|
+
...c.members.map((m) => instantiateOnTerm(m, v(paramName), depth))
|
|
14089
|
+
);
|
|
14090
|
+
const own = c.preds.map((p) => substPred2(p, paramName));
|
|
14091
|
+
return own.length === 0 ? disj : and(...own, disj);
|
|
14092
|
+
}
|
|
14093
|
+
if (c.fn) {
|
|
14094
|
+
const own = c.preds.map((p) => substPred2(p, paramName));
|
|
14095
|
+
return own.length === 0 ? pTrue : and(...own);
|
|
14096
|
+
}
|
|
14097
|
+
const preds = c.preds.map((p) => substPred2(p, paramName));
|
|
14098
|
+
if (c.prim && c.preds.length === 0) {
|
|
14099
|
+
return ptypeof(v(paramName), primToTypeof(c.prim));
|
|
14100
|
+
}
|
|
14101
|
+
return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
|
|
14102
|
+
}
|
|
14103
|
+
function instantiateOnTerm(c, t, depth = LAZY_TEMPLATE_DEPTH) {
|
|
14104
|
+
if (c.lazy) {
|
|
14105
|
+
if (depth <= 0) return pTrue;
|
|
14106
|
+
return instantiateOnTerm(derefConstraint(c), t, depth - 1);
|
|
14107
|
+
}
|
|
14108
|
+
const subst = (p) => {
|
|
14109
|
+
switch (p.op) {
|
|
14110
|
+
case "gt":
|
|
14111
|
+
case "ge":
|
|
14112
|
+
case "lt":
|
|
14113
|
+
case "le":
|
|
14114
|
+
case "eq":
|
|
14115
|
+
case "ne": {
|
|
14116
|
+
const a = p.a.op === "var" && p.a.id === SELF ? t : p.a;
|
|
14117
|
+
const b = p.b.op === "var" && p.b.id === SELF ? t : p.b;
|
|
14118
|
+
return { op: p.op, a, b };
|
|
14119
|
+
}
|
|
14120
|
+
case "typeof": {
|
|
14121
|
+
const tt = p.t.op === "var" && p.t.id === SELF ? t : p.t;
|
|
14122
|
+
return { op: "typeof", t: tt, type: p.type };
|
|
14123
|
+
}
|
|
14124
|
+
case "and":
|
|
14125
|
+
return and(...p.args.map(subst));
|
|
14126
|
+
default:
|
|
14127
|
+
return p;
|
|
14128
|
+
}
|
|
14129
|
+
};
|
|
14130
|
+
if (c.fields) {
|
|
14131
|
+
const parts = [];
|
|
14132
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14133
|
+
if (field.optional || field.constraint.isOptional) continue;
|
|
14134
|
+
parts.push(instantiateOnTerm(field.constraint, getTerm(t, key), depth));
|
|
14135
|
+
}
|
|
14136
|
+
if (parts.length === 0) return { op: "true" };
|
|
14137
|
+
return parts.length === 1 ? parts[0] : and(...parts);
|
|
14138
|
+
}
|
|
14139
|
+
if (c.members) {
|
|
14140
|
+
const disj = or(...c.members.map((m) => instantiateOnTerm(m, t, depth)));
|
|
14141
|
+
const own = c.preds.map(subst);
|
|
14142
|
+
return own.length === 0 ? disj : and(...own, disj);
|
|
14143
|
+
}
|
|
14144
|
+
if (c.fn) {
|
|
14145
|
+
const own = c.preds.map(subst);
|
|
14146
|
+
return own.length === 0 ? pTrue : and(...own);
|
|
14147
|
+
}
|
|
14148
|
+
const preds = c.preds.map(subst);
|
|
14149
|
+
if (c.prim && c.preds.length === 0) return ptypeof(t, primToTypeof(c.prim));
|
|
14150
|
+
return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
|
|
14151
|
+
}
|
|
14152
|
+
function constraintToEntryAbs(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
|
|
14153
|
+
const t = v(paramName);
|
|
14154
|
+
if (c.fields) {
|
|
14155
|
+
const slots = {};
|
|
14156
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14157
|
+
if (field.constraint.lazy && depth <= 0) continue;
|
|
14158
|
+
const fieldTerm = getTerm(t, key);
|
|
14159
|
+
slots[key] = {
|
|
14160
|
+
value: constraintOnTermAbs(field.constraint, fieldTerm, depth),
|
|
14161
|
+
...field.optional || field.constraint.isOptional ? { optional: true } : {}
|
|
14162
|
+
};
|
|
14163
|
+
}
|
|
14164
|
+
return abs({ k: "obj", slots }, t, void 0, "path");
|
|
14165
|
+
}
|
|
14166
|
+
return constraintOnTermAbs(c, t, depth);
|
|
14167
|
+
}
|
|
14168
|
+
function memberLitValue(m) {
|
|
14169
|
+
const leaves = [];
|
|
14170
|
+
const visit = (p2) => {
|
|
14171
|
+
if (p2.op === "and") {
|
|
14172
|
+
p2.args.forEach(visit);
|
|
14173
|
+
return;
|
|
14174
|
+
}
|
|
14175
|
+
leaves.push(p2);
|
|
14176
|
+
};
|
|
14177
|
+
m.preds.forEach(visit);
|
|
14178
|
+
if (leaves.length !== 1) return { ok: false };
|
|
14179
|
+
const p = leaves[0];
|
|
14180
|
+
if (p.op !== "eq") return { ok: false };
|
|
14181
|
+
if (p.a.op === "var" && p.b.op === "lit") {
|
|
14182
|
+
return { ok: true, v: p.b.value };
|
|
14183
|
+
}
|
|
14184
|
+
if (p.b.op === "var" && p.a.op === "lit") {
|
|
14185
|
+
return { ok: true, v: p.a.value };
|
|
14186
|
+
}
|
|
14187
|
+
return { ok: false };
|
|
14188
|
+
}
|
|
14189
|
+
function samePrimLiteralUnionAbs(members, t) {
|
|
14190
|
+
if (members.length === 0) return void 0;
|
|
14191
|
+
const values = [];
|
|
14192
|
+
let prim;
|
|
14193
|
+
for (const m of members) {
|
|
14194
|
+
const mk = memberLitValue(m);
|
|
14195
|
+
if (!mk.ok) return void 0;
|
|
14196
|
+
const v2 = mk.v;
|
|
14197
|
+
if (v2 === void 0 || v2 === null) return void 0;
|
|
14198
|
+
const mp = m.prim ?? (typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : "boolean");
|
|
14199
|
+
if (prim === void 0) prim = mp;
|
|
14200
|
+
else if (prim !== mp) return void 0;
|
|
14201
|
+
values.push(v2);
|
|
14202
|
+
}
|
|
14203
|
+
if (prim === void 0) return void 0;
|
|
14204
|
+
const uniq = [];
|
|
14205
|
+
for (const v2 of values) {
|
|
14206
|
+
if (!uniq.some((u) => Object.is(u, v2))) uniq.push(v2);
|
|
14207
|
+
}
|
|
14208
|
+
const disj = or(
|
|
14209
|
+
...uniq.map((v2) => eq(t, lit(v2)))
|
|
14210
|
+
);
|
|
14211
|
+
return abs({ k: "prim", type: prim }, t, disj, "path");
|
|
14212
|
+
}
|
|
14213
|
+
function constraintOnTermAbs(c, t, depth) {
|
|
14214
|
+
if (c.lazy) {
|
|
14215
|
+
if (depth <= 0) return abs({ k: "any" }, t, void 0, "path");
|
|
14216
|
+
return constraintOnTermAbs(derefConstraint(c), t, depth - 1);
|
|
14217
|
+
}
|
|
14218
|
+
if (c.fields) {
|
|
14219
|
+
const slots = {};
|
|
14220
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14221
|
+
if (field.constraint.lazy && depth <= 0) continue;
|
|
14222
|
+
slots[key] = {
|
|
14223
|
+
value: constraintOnTermAbs(field.constraint, getTerm(t, key), depth),
|
|
14224
|
+
...field.optional || field.constraint.isOptional ? { optional: true } : {}
|
|
14225
|
+
};
|
|
14226
|
+
}
|
|
14227
|
+
return abs({ k: "obj", slots }, t, void 0, "path");
|
|
14228
|
+
}
|
|
14229
|
+
if (c.members) {
|
|
14230
|
+
const litUnion = samePrimLiteralUnionAbs(c.members, t);
|
|
14231
|
+
if (litUnion) return litUnion;
|
|
14232
|
+
const joined = c.members.map((m) => constraintOnTermAbs(m, t, depth)).reduce((a, b) => joinAbs(a, b));
|
|
14233
|
+
if (joined.shape.k === "prim" && joined.pred === void 0 && c.members.every((m) => m.prim === joined.shape.type)) {
|
|
14234
|
+
const type = joined.shape.type;
|
|
14235
|
+
return abs({ k: "prim", type }, t, ptypeof(t, primToTypeof(type)), "path");
|
|
14236
|
+
}
|
|
14237
|
+
return joined;
|
|
14238
|
+
}
|
|
14239
|
+
if (c.fn) {
|
|
14240
|
+
const paramNames = Object.keys(c.fn.params);
|
|
14241
|
+
const paramTypes = paramNames.map(
|
|
14242
|
+
(p, i) => constraintOnTermAbs(c.fn.params[p], v(`x${i}`), depth)
|
|
14243
|
+
);
|
|
14244
|
+
const returnType = c.fn.returns ? constraintOnTermAbs(c.fn.returns, v("ret"), depth) : unknown;
|
|
14245
|
+
return abs(
|
|
14246
|
+
{ k: "fn", params: paramNames, paramTypes, returnType },
|
|
14247
|
+
t,
|
|
14248
|
+
void 0,
|
|
14249
|
+
"path"
|
|
14250
|
+
);
|
|
14251
|
+
}
|
|
14252
|
+
if (c.element) {
|
|
14253
|
+
const elem = constraintOnTermAbs(c.element, v("x[]"), depth);
|
|
14254
|
+
return abs({ k: "arr", element: elem }, t, void 0, "path");
|
|
14255
|
+
}
|
|
14256
|
+
const pred = instantiateOnTerm(c, t, depth);
|
|
14257
|
+
const predOut = pred.op === "true" ? void 0 : pred;
|
|
14258
|
+
if (c.prim) {
|
|
14259
|
+
return abs({ k: "prim", type: c.prim }, t, predOut, "path");
|
|
14260
|
+
}
|
|
14261
|
+
const allEqNullish = c.preds.length > 0 && c.preds.every(
|
|
14262
|
+
(p) => p.op === "eq" && (p.b.op === "lit" && (p.b.value === null || p.b.value === void 0) || p.a.op === "lit" && (p.a.value === null || p.a.value === void 0))
|
|
14263
|
+
);
|
|
14264
|
+
if (allEqNullish) {
|
|
14265
|
+
let nullish = null;
|
|
14266
|
+
for (const p of c.preds) {
|
|
14267
|
+
if (p.op !== "eq") continue;
|
|
14268
|
+
if (p.b.op === "lit" && (p.b.value === null || p.b.value === void 0)) {
|
|
14269
|
+
nullish = p.b.value;
|
|
14270
|
+
break;
|
|
14271
|
+
}
|
|
14272
|
+
if (p.a.op === "lit" && (p.a.value === null || p.a.value === void 0)) {
|
|
14273
|
+
nullish = p.a.value;
|
|
14274
|
+
break;
|
|
14275
|
+
}
|
|
14276
|
+
}
|
|
14277
|
+
return abs({ k: "unknown" }, lit(nullish), void 0, "path");
|
|
14278
|
+
}
|
|
14279
|
+
if (c.preds.length > 0) {
|
|
14280
|
+
return abs({ k: "prim", type: "number" }, t, predOut, "path");
|
|
14281
|
+
}
|
|
14282
|
+
return abs({ k: "any" }, t, void 0, "path");
|
|
14283
|
+
}
|
|
14284
|
+
function fnConstraintToEntryReqs(c) {
|
|
14285
|
+
if (!c.fn) throw new Error("nudo fnConstraintToEntryReqs(): constraint is not in fn() form");
|
|
14286
|
+
return Object.entries(c.fn.params).map(([param, constraint]) => ({
|
|
14287
|
+
param,
|
|
14288
|
+
constraint
|
|
14289
|
+
}));
|
|
14290
|
+
}
|
|
14291
|
+
function throwConstraintToKinds(c) {
|
|
14292
|
+
if (!c) return void 0;
|
|
14293
|
+
const out = /* @__PURE__ */ new Set();
|
|
14294
|
+
let any2 = false;
|
|
14295
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14296
|
+
const note2 = (s) => {
|
|
14297
|
+
if (s === "*" || s === "any") any2 = true;
|
|
14298
|
+
else if (s) out.add(s);
|
|
14299
|
+
};
|
|
14300
|
+
const walk = (x) => {
|
|
14301
|
+
if (x.lazy) {
|
|
14302
|
+
if (seen.has(x.lazy)) return;
|
|
14303
|
+
seen.add(x.lazy);
|
|
14304
|
+
walk(derefConstraint(x));
|
|
14305
|
+
return;
|
|
14306
|
+
}
|
|
14307
|
+
if (x.members) {
|
|
14308
|
+
for (const m of x.members) walk(m);
|
|
14309
|
+
return;
|
|
14310
|
+
}
|
|
14311
|
+
for (const p of x.preds) {
|
|
14312
|
+
if (p.op !== "eq" && p.op !== "ne") continue;
|
|
14313
|
+
for (const side of [p.a, p.b]) {
|
|
14314
|
+
if (side.op === "lit" && typeof side.value === "string") note2(side.value);
|
|
14315
|
+
}
|
|
14316
|
+
}
|
|
14317
|
+
};
|
|
14318
|
+
walk(c);
|
|
14319
|
+
if (any2) return "*";
|
|
14320
|
+
if (out.size > 0) return [...out];
|
|
14321
|
+
return void 0;
|
|
14322
|
+
}
|
|
14323
|
+
|
|
14324
|
+
// src/algebra/domain-membership.ts
|
|
14325
|
+
function literalMeetsConstraint(lv, c, seen) {
|
|
14326
|
+
if (c.lazy) {
|
|
14327
|
+
const s = seen ?? /* @__PURE__ */ new Set();
|
|
14328
|
+
if (s.has(c.lazy)) return false;
|
|
14329
|
+
s.add(c.lazy);
|
|
14330
|
+
return literalMeetsConstraint(lv, derefConstraint(c), s);
|
|
14331
|
+
}
|
|
14332
|
+
const ext = c;
|
|
14333
|
+
if (c.fields || c.element) return false;
|
|
14334
|
+
if (ext.fn) return false;
|
|
14335
|
+
if (Array.isArray(ext.members) && ext.members.length > 0) {
|
|
14336
|
+
return ext.members.some((m) => literalMeetsConstraint(lv, m, seen));
|
|
14337
|
+
}
|
|
14338
|
+
if (c.prim === void 0) {
|
|
14339
|
+
return c.preds.every((p) => predHolds(lv, p));
|
|
14340
|
+
}
|
|
14341
|
+
if (!primMatches(c.prim, lv)) return false;
|
|
14342
|
+
if (isIntFlag(c) && c.prim === "number" && !(typeof lv === "number" && Number.isInteger(lv))) {
|
|
14343
|
+
return false;
|
|
14344
|
+
}
|
|
14345
|
+
return c.preds.every((p) => predHolds(lv, p));
|
|
14346
|
+
}
|
|
14347
|
+
function primMatches(prim, lv) {
|
|
14348
|
+
switch (prim) {
|
|
14349
|
+
case "number":
|
|
14350
|
+
return typeof lv === "number";
|
|
14351
|
+
case "string":
|
|
14352
|
+
return typeof lv === "string";
|
|
14353
|
+
case "boolean":
|
|
14354
|
+
return typeof lv === "boolean";
|
|
14355
|
+
case "object":
|
|
14356
|
+
return lv === null;
|
|
14357
|
+
case "undefined":
|
|
14358
|
+
return lv === void 0;
|
|
14359
|
+
default:
|
|
14360
|
+
return false;
|
|
14361
|
+
}
|
|
14362
|
+
}
|
|
14363
|
+
function predHolds(lv, p) {
|
|
14364
|
+
switch (p.op) {
|
|
14365
|
+
case "eq": {
|
|
14366
|
+
const litT = isSelfVar(p.a) && p.b.op === "lit" ? p.b : isSelfVar(p.b) && p.a.op === "lit" ? p.a : void 0;
|
|
14367
|
+
if (!litT) return false;
|
|
14368
|
+
return Object.is(lv, litT.value);
|
|
14369
|
+
}
|
|
14370
|
+
case "gt":
|
|
14371
|
+
case "ge":
|
|
14372
|
+
case "lt":
|
|
14373
|
+
case "le":
|
|
14374
|
+
return boundHolds(lv, p);
|
|
14375
|
+
case "typeof":
|
|
14376
|
+
return p.t.op === "var" && p.t.id === SELF && primMatches(p.type, lv);
|
|
14377
|
+
// and 是合取:逐参数按同一规则判定(string().length(n) 的 preds 是
|
|
14378
|
+
// and 包裹的两个长度界,叶子仍是 gt/ge/lt/le,无假阳性风险)
|
|
14379
|
+
case "and":
|
|
14380
|
+
return p.args.every((x) => predHolds(lv, x));
|
|
14381
|
+
// ne / or / not / true / false 等其余形态:保守不满足
|
|
14382
|
+
default:
|
|
14383
|
+
return false;
|
|
14384
|
+
}
|
|
14385
|
+
}
|
|
14386
|
+
function cmpHolds(x, op, n) {
|
|
14387
|
+
switch (op) {
|
|
14388
|
+
case "gt":
|
|
14389
|
+
return x > n;
|
|
14390
|
+
case "ge":
|
|
14391
|
+
return x >= n;
|
|
14392
|
+
case "lt":
|
|
14393
|
+
return x < n;
|
|
14394
|
+
case "le":
|
|
14395
|
+
return x <= n;
|
|
14396
|
+
}
|
|
14397
|
+
}
|
|
14398
|
+
function boundHolds(lv, p) {
|
|
14399
|
+
if (p.b.op !== "lit" || typeof p.b.value !== "number") return false;
|
|
14400
|
+
const n = p.b.value;
|
|
14401
|
+
if (isLengthSelf(p.a)) {
|
|
14402
|
+
return typeof lv === "string" && cmpHolds(lv.length, p.op, n);
|
|
14403
|
+
}
|
|
14404
|
+
if (isSelfVar(p.a)) {
|
|
14405
|
+
return typeof lv === "number" && cmpHolds(lv, p.op, n);
|
|
14406
|
+
}
|
|
14407
|
+
return false;
|
|
14408
|
+
}
|
|
14409
|
+
function isSelfVar(t) {
|
|
14410
|
+
return t.op === "var" && t.id === SELF;
|
|
14411
|
+
}
|
|
14412
|
+
function isLengthSelf(t) {
|
|
14413
|
+
return t.op === "app" && t.fn === "length" && t.args.length === 1 && isSelfVar(t.args[0]);
|
|
14414
|
+
}
|
|
14415
|
+
|
|
14416
|
+
// src/algebra/contract-face.ts
|
|
14417
|
+
var facesByFn = /* @__PURE__ */ new WeakMap();
|
|
14418
|
+
function attachContractFaces(fnObj, faces) {
|
|
14419
|
+
facesByFn.set(fnObj, faces);
|
|
14420
|
+
}
|
|
14421
|
+
function contractFacesOf(fnObj) {
|
|
14422
|
+
if (!fnObj || typeof fnObj !== "object" && typeof fnObj !== "function") {
|
|
14423
|
+
return void 0;
|
|
14424
|
+
}
|
|
14425
|
+
return facesByFn.get(fnObj);
|
|
14426
|
+
}
|
|
14427
|
+
var contractFaceResolverSlot = createScopedSlot(
|
|
14428
|
+
() => null
|
|
14429
|
+
);
|
|
14430
|
+
registerCollectorScopeParticipant(
|
|
14431
|
+
(body) => contractFaceResolverSlot.runScoped(body)
|
|
14432
|
+
);
|
|
14433
|
+
function setContractFaceResolver(resolver) {
|
|
14434
|
+
const prev = contractFaceResolverSlot.get();
|
|
14435
|
+
contractFaceResolverSlot.set(resolver);
|
|
14436
|
+
return prev;
|
|
14437
|
+
}
|
|
14438
|
+
function resolveContractFacesByName(fnName) {
|
|
14439
|
+
const resolver = contractFaceResolverSlot.get();
|
|
14440
|
+
return resolver ? resolver(fnName) : void 0;
|
|
14441
|
+
}
|
|
14442
|
+
function argLacksInformation(a) {
|
|
14443
|
+
if (!a || typeof a !== "object" || !("shape" in a)) return false;
|
|
14444
|
+
const k = a.shape?.k;
|
|
14445
|
+
if (k === "any") return true;
|
|
14446
|
+
if (k === "unknown") return a.term?.op !== "lit";
|
|
14447
|
+
return false;
|
|
14448
|
+
}
|
|
14449
|
+
function adoptCallArgsToFaces(args, faces) {
|
|
14450
|
+
const n = Math.min(args.length, faces.paramFaces.length);
|
|
14451
|
+
let changed = false;
|
|
14452
|
+
const out = args.slice();
|
|
14453
|
+
for (let i = 0; i < n; i++) {
|
|
14454
|
+
const face = faces.paramFaces[i];
|
|
14455
|
+
if (!face || !argLacksInformation(args[i])) continue;
|
|
14456
|
+
out[i] = face;
|
|
14457
|
+
changed = true;
|
|
14458
|
+
}
|
|
14459
|
+
return changed ? out : args;
|
|
14460
|
+
}
|
|
14461
|
+
function litMeetsReturnConstraint(r, c) {
|
|
14462
|
+
if (!c) return false;
|
|
14463
|
+
const lv = litValue(r);
|
|
14464
|
+
if (!lv.ok) return false;
|
|
14465
|
+
const v2 = lv.value;
|
|
14466
|
+
if (typeof v2 !== "number" && typeof v2 !== "string" && typeof v2 !== "boolean" && v2 !== null && v2 !== void 0) {
|
|
14467
|
+
return false;
|
|
14468
|
+
}
|
|
14469
|
+
return literalMeetsConstraint(v2, c);
|
|
14470
|
+
}
|
|
14471
|
+
function presentCallResultFace(r, faces) {
|
|
14472
|
+
const face = faces.returns;
|
|
14473
|
+
if (!face || !r || typeof r !== "object" || !r.shape) return r;
|
|
14474
|
+
if (r.shape.k === "never") return r;
|
|
14475
|
+
if (r.conf === "opaque") return r;
|
|
14476
|
+
if (litMeetsReturnConstraint(r, faces.returnsConstraint)) return r;
|
|
14477
|
+
if (leqAbs(r, face).ok) return r;
|
|
14478
|
+
return face;
|
|
14479
|
+
}
|
|
14480
|
+
function contractFacesFromEffectiveInterface(eff, paramNames) {
|
|
14481
|
+
if (eff.source !== "handwritten") return void 0;
|
|
14482
|
+
const conflictParams = eff.conflict?.params ?? [];
|
|
14483
|
+
const paramFaces = [];
|
|
14484
|
+
let hasFace = false;
|
|
14485
|
+
for (const e of eff.params) {
|
|
14486
|
+
const idx = paramNames.indexOf(e.param);
|
|
14487
|
+
if (idx < 0 || conflictParams.includes(e.param)) continue;
|
|
14488
|
+
paramFaces[idx] = constraintToEntryAbs(e.constraint, e.param);
|
|
14489
|
+
hasFace = true;
|
|
14490
|
+
}
|
|
14491
|
+
let returns;
|
|
14492
|
+
let returnsConstraint;
|
|
14493
|
+
if (eff.returns && !eff.conflict?.returns) {
|
|
14494
|
+
returns = constraintToEntryAbs(eff.returns.constraint, "return");
|
|
14495
|
+
returnsConstraint = eff.returns.constraint;
|
|
14496
|
+
hasFace = true;
|
|
14497
|
+
}
|
|
14498
|
+
return hasFace ? {
|
|
14499
|
+
paramFaces,
|
|
14500
|
+
...returns !== void 0 ? { returns } : {},
|
|
14501
|
+
...returnsConstraint !== void 0 ? { returnsConstraint } : {}
|
|
14502
|
+
} : void 0;
|
|
14503
|
+
}
|
|
14504
|
+
|
|
13506
14505
|
// src/algebra/exec/calls.ts
|
|
13507
14506
|
var PURE_CALL_MEMO_MAX = 256;
|
|
13508
14507
|
var pureCallMemo = /* @__PURE__ */ new WeakMap();
|
|
@@ -13589,16 +14588,16 @@ var NEVER_EXEC_HOST_FN_NAMES = [
|
|
|
13589
14588
|
"requestAnimationFrame",
|
|
13590
14589
|
"requestIdleCallback"
|
|
13591
14590
|
];
|
|
13592
|
-
function neverExecHostName(
|
|
13593
|
-
if (typeof
|
|
14591
|
+
function neverExecHostName(fn2) {
|
|
14592
|
+
if (typeof fn2 !== "function") return null;
|
|
13594
14593
|
const g = globalThis;
|
|
13595
14594
|
for (const n of NEVER_EXEC_HOST_FN_NAMES) {
|
|
13596
|
-
if (
|
|
14595
|
+
if (fn2 === g[n]) return n;
|
|
13597
14596
|
}
|
|
13598
14597
|
return null;
|
|
13599
14598
|
}
|
|
13600
|
-
function blockHostSideEffect(
|
|
13601
|
-
const hostName = neverExecHostName(
|
|
14599
|
+
function blockHostSideEffect(fn2) {
|
|
14600
|
+
const hostName = neverExecHostName(fn2);
|
|
13602
14601
|
if (hostName === null) return null;
|
|
13603
14602
|
noteHostEffectBlocked(hostName);
|
|
13604
14603
|
return abs({ k: "unknown" }, void 0, void 0, "opaque");
|
|
@@ -13620,8 +14619,8 @@ function getEvalCallCollector() {
|
|
|
13620
14619
|
return evalCallCollectorSlot.get();
|
|
13621
14620
|
}
|
|
13622
14621
|
var hostGlobalFnIds;
|
|
13623
|
-
function isHostGlobalFn(
|
|
13624
|
-
if (typeof
|
|
14622
|
+
function isHostGlobalFn(fn2) {
|
|
14623
|
+
if (typeof fn2 !== "function") return false;
|
|
13625
14624
|
if (!hostGlobalFnIds) {
|
|
13626
14625
|
hostGlobalFnIds = /* @__PURE__ */ new Set();
|
|
13627
14626
|
const g = globalThis;
|
|
@@ -13630,9 +14629,9 @@ function isHostGlobalFn(fn) {
|
|
|
13630
14629
|
if (typeof v2 === "function") hostGlobalFnIds.add(v2);
|
|
13631
14630
|
}
|
|
13632
14631
|
}
|
|
13633
|
-
return hostGlobalFnIds.has(
|
|
14632
|
+
return hostGlobalFnIds.has(fn2);
|
|
13634
14633
|
}
|
|
13635
|
-
function callHostGlobalLiteralOnly(name,
|
|
14634
|
+
function callHostGlobalLiteralOnly(name, fn2, args) {
|
|
13636
14635
|
const jsArgs = [];
|
|
13637
14636
|
for (const a of args) {
|
|
13638
14637
|
if (a && typeof a === "object" && "shape" in a) {
|
|
@@ -13653,7 +14652,7 @@ function callHostGlobalLiteralOnly(name, fn, args) {
|
|
|
13653
14652
|
}
|
|
13654
14653
|
}
|
|
13655
14654
|
try {
|
|
13656
|
-
return asAbsVal(
|
|
14655
|
+
return asAbsVal(fn2(...jsArgs));
|
|
13657
14656
|
} catch (e) {
|
|
13658
14657
|
throw new NudoThrow(throwPayloadOf(e));
|
|
13659
14658
|
}
|
|
@@ -13726,12 +14725,12 @@ function getEvalCallBudgetState() {
|
|
|
13726
14725
|
function evalTruncatedAbs() {
|
|
13727
14726
|
return abs({ k: "unknown" }, void 0, void 0, "opaque");
|
|
13728
14727
|
}
|
|
13729
|
-
function evalCallBudgetKey(name,
|
|
13730
|
-
const id =
|
|
14728
|
+
function evalCallBudgetKey(name, fn2, args) {
|
|
14729
|
+
const id = fn2 && typeof fn2 === "object" ? evalStableId(fn2) : "prim";
|
|
13731
14730
|
return callBudgetKey(name, id, args);
|
|
13732
14731
|
}
|
|
13733
|
-
function evalEnterCall(name,
|
|
13734
|
-
const key = evalCallBudgetKey(name,
|
|
14732
|
+
function evalEnterCall(name, fn2, args) {
|
|
14733
|
+
const key = evalCallBudgetKey(name, fn2, args);
|
|
13735
14734
|
if (evalActiveCallKeys.includes(key) || evalCallDepth >= evalCallDepthLimit || evalTotalCalls >= evalTotalCallsLimit) {
|
|
13736
14735
|
noteAbsTruncation(name);
|
|
13737
14736
|
return { ok: false };
|
|
@@ -13745,13 +14744,19 @@ function evalExitCall() {
|
|
|
13745
14744
|
if (evalCallDepth > 0) evalCallDepth--;
|
|
13746
14745
|
if (evalActiveCallKeys.length > 0) evalActiveCallKeys.pop();
|
|
13747
14746
|
}
|
|
13748
|
-
function $callNamed(name,
|
|
13749
|
-
const
|
|
13750
|
-
const fnObj =
|
|
13751
|
-
|
|
14747
|
+
function $callNamed(name, fn2, args, loc, argLocs) {
|
|
14748
|
+
const faces = resolveContractFacesByName(name) ?? contractFacesOf(fn2);
|
|
14749
|
+
const fnObj = fn2 && (typeof fn2 === "object" || typeof fn2 === "function") ? fn2 : void 0;
|
|
14750
|
+
if (faces && fnObj) attachContractFaces(fnObj, faces);
|
|
14751
|
+
const execArgs = faces ? adoptCallArgsToFaces(args, faces) : args;
|
|
14752
|
+
const pureName = pureFnNameOf(fn2);
|
|
14753
|
+
const pk = pureName && fnObj ? callBudgetKey("pure", "", execArgs) : void 0;
|
|
13752
14754
|
if (fnObj && pk !== void 0) {
|
|
13753
14755
|
const hit = pureCallMemo.get(fnObj)?.get(pk);
|
|
13754
|
-
if (hit !== void 0)
|
|
14756
|
+
if (hit !== void 0) {
|
|
14757
|
+
const routed = routeApplyThrows(hit.abs, hit.throws);
|
|
14758
|
+
return faces ? presentCallResultFace(routed, faces) : routed;
|
|
14759
|
+
}
|
|
13755
14760
|
}
|
|
13756
14761
|
let result = unknown;
|
|
13757
14762
|
let threw = false;
|
|
@@ -13767,42 +14772,42 @@ function $callNamed(name, fn, args, loc, argLocs) {
|
|
|
13767
14772
|
);
|
|
13768
14773
|
if (loc) pushCallLoc({ line: loc[0], column: loc[1] });
|
|
13769
14774
|
try {
|
|
13770
|
-
if (typeof
|
|
14775
|
+
if (typeof fn2 === "function") {
|
|
13771
14776
|
let g;
|
|
13772
|
-
if (GLOBAL_FNS.has(name) &&
|
|
14777
|
+
if (GLOBAL_FNS.has(name) && fn2 === globalThis[name]) {
|
|
13773
14778
|
g = evalGlobalFn(name, args);
|
|
13774
14779
|
} else {
|
|
13775
|
-
const ctorName = hostBuiltinCtorName(
|
|
14780
|
+
const ctorName = hostBuiltinCtorName(fn2);
|
|
13776
14781
|
if (ctorName !== void 0) {
|
|
13777
14782
|
g = evalGlobalFn(ctorName, args);
|
|
13778
14783
|
}
|
|
13779
14784
|
}
|
|
13780
|
-
const blockedHost = g === void 0 ? blockHostSideEffect(
|
|
14785
|
+
const blockedHost = g === void 0 ? blockHostSideEffect(fn2) : null;
|
|
13781
14786
|
if (g !== void 0) {
|
|
13782
14787
|
result = g;
|
|
13783
14788
|
} else if (blockedHost !== null) {
|
|
13784
14789
|
result = blockedHost;
|
|
13785
|
-
} else if (isHostGlobalFn(
|
|
13786
|
-
result = callHostGlobalLiteralOnly(name,
|
|
14790
|
+
} else if (isHostGlobalFn(fn2)) {
|
|
14791
|
+
result = callHostGlobalLiteralOnly(name, fn2, args);
|
|
13787
14792
|
} else {
|
|
13788
|
-
const entered = evalEnterCall(name,
|
|
14793
|
+
const entered = evalEnterCall(name, fn2, execArgs);
|
|
13789
14794
|
if (!entered.ok) {
|
|
13790
14795
|
result = evalTruncatedAbs();
|
|
13791
14796
|
} else {
|
|
13792
14797
|
try {
|
|
13793
|
-
result = callAtFunctionBoundary(() =>
|
|
14798
|
+
result = callAtFunctionBoundary(() => fn2(...execArgs));
|
|
13794
14799
|
} finally {
|
|
13795
14800
|
evalExitCall();
|
|
13796
14801
|
}
|
|
13797
14802
|
}
|
|
13798
14803
|
}
|
|
13799
|
-
} else if (
|
|
13800
|
-
const entered = evalEnterCall(name,
|
|
14804
|
+
} else if (fn2 && typeof fn2 === "object" && "shape" in fn2) {
|
|
14805
|
+
const entered = evalEnterCall(name, fn2, execArgs);
|
|
13801
14806
|
if (!entered.ok) {
|
|
13802
14807
|
result = evalTruncatedAbs();
|
|
13803
14808
|
} else {
|
|
13804
14809
|
try {
|
|
13805
|
-
result = $call(
|
|
14810
|
+
result = $call(fn2, execArgs);
|
|
13806
14811
|
} finally {
|
|
13807
14812
|
evalExitCall();
|
|
13808
14813
|
}
|
|
@@ -13836,7 +14841,7 @@ function $callNamed(name, fn, args, loc, argLocs) {
|
|
|
13836
14841
|
}
|
|
13837
14842
|
}
|
|
13838
14843
|
}
|
|
13839
|
-
return result;
|
|
14844
|
+
return faces ? presentCallResultFace(result, faces) : result;
|
|
13840
14845
|
}
|
|
13841
14846
|
|
|
13842
14847
|
// src/algebra/methods.ts
|
|
@@ -14906,8 +15911,8 @@ function $new(cls, args) {
|
|
|
14906
15911
|
popCtorFrame();
|
|
14907
15912
|
}
|
|
14908
15913
|
}
|
|
14909
|
-
const
|
|
14910
|
-
return abs({ k: "brand", name: clsName, shape }, void 0, void 0, "path");
|
|
15914
|
+
const shape2 = objOf({});
|
|
15915
|
+
return abs({ k: "brand", name: clsName, shape: shape2 }, void 0, void 0, "path");
|
|
14911
15916
|
}
|
|
14912
15917
|
const spec = specOf(cls);
|
|
14913
15918
|
if (!spec) {
|
|
@@ -15183,12 +16188,12 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15183
16188
|
return ["_rest"];
|
|
15184
16189
|
};
|
|
15185
16190
|
if (typeof thisVal === "function") {
|
|
15186
|
-
const
|
|
16191
|
+
const fn2 = thisVal;
|
|
15187
16192
|
if (method === "call") {
|
|
15188
|
-
return callAtFunctionBoundary(() =>
|
|
16193
|
+
return callAtFunctionBoundary(() => fn2.apply(args[0], args.slice(1)));
|
|
15189
16194
|
}
|
|
15190
16195
|
if (method === "apply") {
|
|
15191
|
-
return callAtFunctionBoundary(() =>
|
|
16196
|
+
return callAtFunctionBoundary(() => fn2.apply(args[0], expandApplyArgs(args[1])));
|
|
15192
16197
|
}
|
|
15193
16198
|
const boundThis = args[0];
|
|
15194
16199
|
const bound = args.slice(1);
|
|
@@ -15196,7 +16201,7 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15196
16201
|
return absFunction(
|
|
15197
16202
|
boundFnParams(thisVal, bound.length),
|
|
15198
16203
|
{
|
|
15199
|
-
apply: (callArgs) => callAtFunctionBoundary(() =>
|
|
16204
|
+
apply: (callArgs) => callAtFunctionBoundary(() => fn2.apply(boundThis, [...bound, ...callArgs]))
|
|
15200
16205
|
},
|
|
15201
16206
|
hostFacet !== void 0 ? { ctor: hostFacet } : void 0
|
|
15202
16207
|
);
|
|
@@ -15450,9 +16455,9 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15450
16455
|
noteUnknownMemberMissing(thisVal, method, "method", loc);
|
|
15451
16456
|
return unknown;
|
|
15452
16457
|
}
|
|
15453
|
-
function refineFnReturnType(
|
|
15454
|
-
if (!
|
|
15455
|
-
const s =
|
|
16458
|
+
function refineFnReturnType(fn2, result) {
|
|
16459
|
+
if (!fn2 || typeof fn2 !== "object" || !("shape" in fn2)) return;
|
|
16460
|
+
const s = fn2.shape;
|
|
15456
16461
|
if (s.k !== "fn") return;
|
|
15457
16462
|
if (s.returnType === void 0) {
|
|
15458
16463
|
s.returnType = result;
|
|
@@ -15472,8 +16477,8 @@ function memberLikelyHasMethod(m, method) {
|
|
|
15472
16477
|
return false;
|
|
15473
16478
|
}
|
|
15474
16479
|
function invokeArrMethod(arr, method, args) {
|
|
15475
|
-
const
|
|
15476
|
-
const holes =
|
|
16480
|
+
const shape2 = arr.shape;
|
|
16481
|
+
const holes = shape2.k === "tuple" ? arr.shape.holes ?? [] : [];
|
|
15477
16482
|
const isHole = (i) => holes.includes(i);
|
|
15478
16483
|
const unknownIdx = () => abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
15479
16484
|
const callbackTruth = (r) => {
|
|
@@ -15484,7 +16489,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15484
16489
|
if (typeof v2 === "number" && (v2 === 0 || Number.isNaN(v2))) return false;
|
|
15485
16490
|
return true;
|
|
15486
16491
|
};
|
|
15487
|
-
const callFn = (
|
|
16492
|
+
const callFn = (fn2, ...fnArgs) => {
|
|
15488
16493
|
const sumIdx = fnArgs.findIndex(
|
|
15489
16494
|
(a) => a && typeof a === "object" && "shape" in a && a.shape.k === "sum"
|
|
15490
16495
|
);
|
|
@@ -15493,24 +16498,24 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15493
16498
|
let acc;
|
|
15494
16499
|
for (const m of members) {
|
|
15495
16500
|
const next = fnArgs.map((a, i) => i === sumIdx ? m : a);
|
|
15496
|
-
const r = callFn(
|
|
16501
|
+
const r = callFn(fn2, ...next);
|
|
15497
16502
|
acc = acc === void 0 ? r : joinAbs(acc, r);
|
|
15498
16503
|
}
|
|
15499
16504
|
return acc ?? unknown;
|
|
15500
16505
|
}
|
|
15501
|
-
if (typeof
|
|
15502
|
-
const r = callAtFunctionBoundary(() =>
|
|
16506
|
+
if (typeof fn2 === "function") {
|
|
16507
|
+
const r = callAtFunctionBoundary(() => fn2(...fnArgs));
|
|
15503
16508
|
if (r && typeof r === "object" && "shape" in r) return r;
|
|
15504
16509
|
return unknown;
|
|
15505
16510
|
}
|
|
15506
|
-
const absFn = asAbs(
|
|
16511
|
+
const absFn = asAbs(fn2);
|
|
15507
16512
|
if (absFn) {
|
|
15508
16513
|
return applyCallbackAbs(absFn, fnArgs, emptyEnv(), pTrue, defaultLeakBudget);
|
|
15509
16514
|
}
|
|
15510
16515
|
return unknown;
|
|
15511
16516
|
};
|
|
15512
|
-
const isRelationOnly = (
|
|
15513
|
-
const a = asAbs(
|
|
16517
|
+
const isRelationOnly = (fn2) => {
|
|
16518
|
+
const a = asAbs(fn2);
|
|
15514
16519
|
if (!a) return false;
|
|
15515
16520
|
const impl = getFnImpl(a);
|
|
15516
16521
|
if (impl?.body || impl?.apply) return false;
|
|
@@ -15518,8 +16523,8 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15518
16523
|
};
|
|
15519
16524
|
if (method === "map") {
|
|
15520
16525
|
validateCallableArg(args[0], "map callback may not be callable");
|
|
15521
|
-
if (
|
|
15522
|
-
const mapped =
|
|
16526
|
+
if (shape2.k === "tuple") {
|
|
16527
|
+
const mapped = shape2.elements.map(
|
|
15523
16528
|
(el2, i) => isHole(i) ? el2 : callFn(args[0], el2, $lit(i), arr)
|
|
15524
16529
|
);
|
|
15525
16530
|
return abs(
|
|
@@ -15529,70 +16534,70 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15529
16534
|
"path"
|
|
15530
16535
|
);
|
|
15531
16536
|
}
|
|
15532
|
-
const out = callFn(args[0],
|
|
15533
|
-
const el = mapElementFallback(asAbs(args[0]),
|
|
16537
|
+
const out = callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
16538
|
+
const el = mapElementFallback(asAbs(args[0]), shape2.element, out);
|
|
15534
16539
|
const conf = el === out ? confJoin(arr.conf, out.conf) : "partial";
|
|
15535
16540
|
return abs({ k: "arr", element: el }, void 0, void 0, conf);
|
|
15536
16541
|
}
|
|
15537
16542
|
if (method === "reduce") {
|
|
15538
16543
|
validateCallableArg(args[0], "reduce callback may not be callable");
|
|
15539
|
-
const
|
|
16544
|
+
const fn2 = args[0];
|
|
15540
16545
|
const noInitial = args.length < 2;
|
|
15541
16546
|
let acc = args[1] ?? unknown;
|
|
15542
|
-
if (noInitial &&
|
|
16547
|
+
if (noInitial && shape2.k === "arr") {
|
|
15543
16548
|
recordMayThrow({
|
|
15544
16549
|
kind: "TypeError",
|
|
15545
16550
|
cause: "reduce of possibly-empty array with no initial value"
|
|
15546
16551
|
});
|
|
15547
16552
|
}
|
|
15548
|
-
if (isRelationOnly(
|
|
15549
|
-
const d = instantiateReturn(
|
|
16553
|
+
if (isRelationOnly(fn2) && shape2.k === "arr") {
|
|
16554
|
+
const d = instantiateReturn(fn2, [acc, shape2.element]);
|
|
15550
16555
|
return joinAbs(acc, d);
|
|
15551
16556
|
}
|
|
15552
|
-
if (
|
|
16557
|
+
if (shape2.k === "tuple") {
|
|
15553
16558
|
if (noInitial) {
|
|
15554
|
-
const firstIdx =
|
|
16559
|
+
const firstIdx = shape2.elements.findIndex((_, i) => !isHole(i));
|
|
15555
16560
|
if (firstIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
15556
|
-
let acc2 =
|
|
15557
|
-
for (let i = firstIdx + 1; i <
|
|
16561
|
+
let acc2 = shape2.elements[firstIdx];
|
|
16562
|
+
for (let i = firstIdx + 1; i < shape2.elements.length; i++) {
|
|
15558
16563
|
if (isHole(i)) continue;
|
|
15559
|
-
acc2 = callFn(
|
|
16564
|
+
acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
|
|
15560
16565
|
}
|
|
15561
16566
|
return acc2;
|
|
15562
16567
|
}
|
|
15563
|
-
for (let i = 0; i <
|
|
16568
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
15564
16569
|
if (isHole(i)) continue;
|
|
15565
|
-
acc = callFn(
|
|
16570
|
+
acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
|
|
15566
16571
|
}
|
|
15567
16572
|
return acc;
|
|
15568
16573
|
}
|
|
15569
|
-
return callFn(
|
|
16574
|
+
return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
|
|
15570
16575
|
}
|
|
15571
16576
|
if (method === "reduceRight") {
|
|
15572
16577
|
validateCallableArg(args[0], "reduceRight callback may not be callable");
|
|
15573
|
-
const
|
|
16578
|
+
const fn2 = args[0];
|
|
15574
16579
|
const noInitial = args.length < 2;
|
|
15575
16580
|
let acc = args[1] ?? unknown;
|
|
15576
|
-
if (
|
|
16581
|
+
if (shape2.k === "tuple") {
|
|
15577
16582
|
if (noInitial) {
|
|
15578
16583
|
let lastIdx = -1;
|
|
15579
|
-
for (let i =
|
|
16584
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
15580
16585
|
if (!isHole(i)) {
|
|
15581
16586
|
lastIdx = i;
|
|
15582
16587
|
break;
|
|
15583
16588
|
}
|
|
15584
16589
|
}
|
|
15585
16590
|
if (lastIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
15586
|
-
let acc2 =
|
|
16591
|
+
let acc2 = shape2.elements[lastIdx];
|
|
15587
16592
|
for (let i = lastIdx - 1; i >= 0; i--) {
|
|
15588
16593
|
if (isHole(i)) continue;
|
|
15589
|
-
acc2 = callFn(
|
|
16594
|
+
acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
|
|
15590
16595
|
}
|
|
15591
16596
|
return acc2;
|
|
15592
16597
|
}
|
|
15593
|
-
for (let i =
|
|
16598
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
15594
16599
|
if (isHole(i)) continue;
|
|
15595
|
-
acc = callFn(
|
|
16600
|
+
acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
|
|
15596
16601
|
}
|
|
15597
16602
|
return acc;
|
|
15598
16603
|
}
|
|
@@ -15602,14 +16607,14 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15602
16607
|
cause: "reduceRight of possibly-empty array with no initial value"
|
|
15603
16608
|
});
|
|
15604
16609
|
}
|
|
15605
|
-
return callFn(
|
|
16610
|
+
return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
|
|
15606
16611
|
}
|
|
15607
16612
|
if (method === "filter") {
|
|
15608
16613
|
validateCallableArg(args[0], "filter callback may not be callable");
|
|
15609
|
-
if (
|
|
16614
|
+
if (shape2.k === "tuple") {
|
|
15610
16615
|
const kept = [];
|
|
15611
16616
|
let anyUncertain = false;
|
|
15612
|
-
|
|
16617
|
+
shape2.elements.forEach((el2, i) => {
|
|
15613
16618
|
if (isHole(i)) return;
|
|
15614
16619
|
const p = callFn(args[0], el2, $lit(i), arr);
|
|
15615
16620
|
const t = callbackTruth(p);
|
|
@@ -15641,33 +16646,33 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15641
16646
|
}
|
|
15642
16647
|
if (method === "flatMap") {
|
|
15643
16648
|
validateCallableArg(args[0], "flatMap callback may not be callable");
|
|
15644
|
-
if (
|
|
15645
|
-
const mapped =
|
|
16649
|
+
if (shape2.k === "tuple") {
|
|
16650
|
+
const mapped = shape2.elements.map(
|
|
15646
16651
|
(el, i) => isHole(i) ? abs({ k: "tuple", elements: [] }, void 0, void 0, "exact") : callFn(args[0], el, $lit(i), arr)
|
|
15647
16652
|
);
|
|
15648
16653
|
return projectFlatMapResult(arr.conf, mapped);
|
|
15649
16654
|
}
|
|
15650
|
-
const out = callFn(args[0],
|
|
16655
|
+
const out = callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
15651
16656
|
return projectFlatMapResult(arr.conf, [out]);
|
|
15652
16657
|
}
|
|
15653
16658
|
if (method === "forEach") {
|
|
15654
16659
|
validateCallableArg(args[0], "forEach callback may not be callable");
|
|
15655
|
-
if (
|
|
15656
|
-
|
|
16660
|
+
if (shape2.k === "tuple") {
|
|
16661
|
+
shape2.elements.forEach((el, i) => {
|
|
15657
16662
|
if (!isHole(i)) callFn(args[0], el, $lit(i), arr);
|
|
15658
16663
|
});
|
|
15659
16664
|
} else {
|
|
15660
|
-
callFn(args[0],
|
|
16665
|
+
callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
15661
16666
|
}
|
|
15662
16667
|
return undefAbs();
|
|
15663
16668
|
}
|
|
15664
16669
|
if (method === "some" || method === "every") {
|
|
15665
16670
|
validateCallableArg(args[0], `${method} callback may not be callable`);
|
|
15666
16671
|
let undecided = false;
|
|
15667
|
-
if (
|
|
15668
|
-
for (let i = 0; i <
|
|
16672
|
+
if (shape2.k === "tuple") {
|
|
16673
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
15669
16674
|
if (isHole(i)) continue;
|
|
15670
|
-
const t = callbackTruth(callFn(args[0],
|
|
16675
|
+
const t = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
15671
16676
|
if (t === void 0) {
|
|
15672
16677
|
undecided = true;
|
|
15673
16678
|
continue;
|
|
@@ -15676,7 +16681,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15676
16681
|
if (method === "every" && !t) return boolLit(false);
|
|
15677
16682
|
}
|
|
15678
16683
|
} else {
|
|
15679
|
-
const t = callbackTruth(callFn(args[0],
|
|
16684
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15680
16685
|
if (t === void 0) return bool();
|
|
15681
16686
|
if (method === "some" && t) return boolLit(true);
|
|
15682
16687
|
if (method === "every" && !t) return boolLit(false);
|
|
@@ -15687,21 +16692,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15687
16692
|
}
|
|
15688
16693
|
if (method === "find") {
|
|
15689
16694
|
validateCallableArg(args[0], "find callback may not be callable");
|
|
15690
|
-
if (
|
|
16695
|
+
if (shape2.k === "tuple") {
|
|
15691
16696
|
let undecided = false;
|
|
15692
|
-
for (let i = 0; i <
|
|
15693
|
-
const el2 =
|
|
16697
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
16698
|
+
const el2 = shape2.elements[i];
|
|
15694
16699
|
const t2 = callbackTruth(callFn(args[0], el2, $lit(i), arr));
|
|
15695
16700
|
if (t2 === true) return el2;
|
|
15696
16701
|
if (t2 === void 0) undecided = true;
|
|
15697
16702
|
}
|
|
15698
16703
|
if (undecided) {
|
|
15699
|
-
const joined =
|
|
16704
|
+
const joined = shape2.elements.reduce((a, b) => joinAbs(a, b));
|
|
15700
16705
|
return joinAbs(joined, undefAbs());
|
|
15701
16706
|
}
|
|
15702
16707
|
return undefAbs();
|
|
15703
16708
|
}
|
|
15704
|
-
const el =
|
|
16709
|
+
const el = shape2.element;
|
|
15705
16710
|
const t = callbackTruth(callFn(args[0], el, unknownIdx(), arr));
|
|
15706
16711
|
if (t === true) return el;
|
|
15707
16712
|
if (t === false) return undefAbs();
|
|
@@ -15709,17 +16714,17 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15709
16714
|
}
|
|
15710
16715
|
if (method === "findIndex") {
|
|
15711
16716
|
validateCallableArg(args[0], "findIndex callback may not be callable");
|
|
15712
|
-
if (
|
|
16717
|
+
if (shape2.k === "tuple") {
|
|
15713
16718
|
let undecided = false;
|
|
15714
|
-
for (let i = 0; i <
|
|
15715
|
-
const t2 = callbackTruth(callFn(args[0],
|
|
16719
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
16720
|
+
const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
15716
16721
|
if (t2 === true) return $lit(i);
|
|
15717
16722
|
if (t2 === void 0) undecided = true;
|
|
15718
16723
|
}
|
|
15719
16724
|
if (undecided) return joinAbs(unknownIdx(), $lit(-1));
|
|
15720
16725
|
return $lit(-1);
|
|
15721
16726
|
}
|
|
15722
|
-
const t = callbackTruth(callFn(args[0],
|
|
16727
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15723
16728
|
if (t === true) return unknownIdx();
|
|
15724
16729
|
if (t === false) return $lit(-1);
|
|
15725
16730
|
return joinAbs(unknownIdx(), $lit(-1));
|
|
@@ -15727,28 +16732,28 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15727
16732
|
if (method === "findLast" || method === "findLastIndex") {
|
|
15728
16733
|
validateCallableArg(args[0], `${method} callback may not be callable`);
|
|
15729
16734
|
const wantIndex = method === "findLastIndex";
|
|
15730
|
-
if (
|
|
16735
|
+
if (shape2.k === "tuple") {
|
|
15731
16736
|
let undecided = false;
|
|
15732
|
-
for (let i =
|
|
15733
|
-
const t2 = callbackTruth(callFn(args[0],
|
|
15734
|
-
if (t2 === true) return wantIndex ? $lit(i) :
|
|
16737
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
16738
|
+
const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
16739
|
+
if (t2 === true) return wantIndex ? $lit(i) : shape2.elements[i];
|
|
15735
16740
|
if (t2 === void 0) undecided = true;
|
|
15736
16741
|
}
|
|
15737
16742
|
if (undecided) {
|
|
15738
|
-
const joined =
|
|
16743
|
+
const joined = shape2.elements.length ? shape2.elements.reduce((a, b) => joinAbs(a, b)) : unknown;
|
|
15739
16744
|
return wantIndex ? joinAbs(unknownIdx(), $lit(-1)) : joinAbs(joined, undefAbs());
|
|
15740
16745
|
}
|
|
15741
16746
|
return wantIndex ? $lit(-1) : undefAbs();
|
|
15742
16747
|
}
|
|
15743
|
-
const t = callbackTruth(callFn(args[0],
|
|
16748
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15744
16749
|
if (wantIndex) {
|
|
15745
16750
|
if (t === true) return unknownIdx();
|
|
15746
16751
|
if (t === false) return $lit(-1);
|
|
15747
16752
|
return joinAbs(unknownIdx(), $lit(-1));
|
|
15748
16753
|
}
|
|
15749
|
-
if (t === true) return
|
|
16754
|
+
if (t === true) return shape2.element;
|
|
15750
16755
|
if (t === false) return undefAbs();
|
|
15751
|
-
return joinAbs(
|
|
16756
|
+
return joinAbs(shape2.element, undefAbs());
|
|
15752
16757
|
}
|
|
15753
16758
|
if (method === "join") {
|
|
15754
16759
|
const folded = arrayJoinWithSep(arr, args[0]);
|
|
@@ -15760,11 +16765,11 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15760
16765
|
return arrayJoinToString(arr);
|
|
15761
16766
|
}
|
|
15762
16767
|
if (method === "keys") {
|
|
15763
|
-
if (
|
|
16768
|
+
if (shape2.k === "tuple") {
|
|
15764
16769
|
return abs(
|
|
15765
16770
|
{
|
|
15766
16771
|
k: "tuple",
|
|
15767
|
-
elements:
|
|
16772
|
+
elements: shape2.elements.map((_, i) => numLit(i))
|
|
15768
16773
|
},
|
|
15769
16774
|
void 0,
|
|
15770
16775
|
void 0,
|
|
@@ -15774,12 +16779,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15774
16779
|
return abs({ k: "arr", element: unknownIdx() }, void 0, void 0, "partial");
|
|
15775
16780
|
}
|
|
15776
16781
|
if (method === "values") {
|
|
15777
|
-
if (
|
|
15778
|
-
const holes2 =
|
|
16782
|
+
if (shape2.k === "tuple") {
|
|
16783
|
+
const holes2 = shape2.holes ?? [];
|
|
15779
16784
|
return abs(
|
|
15780
16785
|
{
|
|
15781
16786
|
k: "tuple",
|
|
15782
|
-
elements:
|
|
16787
|
+
elements: shape2.elements.map((el, i) => holes2.includes(i) ? undefAbs() : el)
|
|
15783
16788
|
},
|
|
15784
16789
|
void 0,
|
|
15785
16790
|
void 0,
|
|
@@ -15789,12 +16794,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15789
16794
|
return arr;
|
|
15790
16795
|
}
|
|
15791
16796
|
if (method === "entries") {
|
|
15792
|
-
if (
|
|
15793
|
-
const holes2 =
|
|
16797
|
+
if (shape2.k === "tuple") {
|
|
16798
|
+
const holes2 = shape2.holes ?? [];
|
|
15794
16799
|
return abs(
|
|
15795
16800
|
{
|
|
15796
16801
|
k: "tuple",
|
|
15797
|
-
elements:
|
|
16802
|
+
elements: shape2.elements.map(
|
|
15798
16803
|
(el, i) => abs(
|
|
15799
16804
|
{ k: "tuple", elements: [numLit(i), holes2.includes(i) ? undefAbs() : el] },
|
|
15800
16805
|
void 0,
|
|
@@ -15812,7 +16817,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15812
16817
|
{
|
|
15813
16818
|
k: "arr",
|
|
15814
16819
|
element: abs(
|
|
15815
|
-
{ k: "tuple", elements: [unknownIdx(),
|
|
16820
|
+
{ k: "tuple", elements: [unknownIdx(), shape2.element] },
|
|
15816
16821
|
void 0,
|
|
15817
16822
|
void 0,
|
|
15818
16823
|
"partial"
|
|
@@ -15824,16 +16829,16 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15824
16829
|
);
|
|
15825
16830
|
}
|
|
15826
16831
|
if (method === "fill" && args.length >= 1) {
|
|
15827
|
-
return fillTuple(
|
|
16832
|
+
return fillTuple(shape2, args, arr);
|
|
15828
16833
|
}
|
|
15829
16834
|
if (method === "sort" || method === "toSorted") {
|
|
15830
16835
|
validateCallableArg(args[0], `${method} comparator may not be callable`, {
|
|
15831
16836
|
undefinedOk: true
|
|
15832
16837
|
});
|
|
15833
|
-
if (
|
|
15834
|
-
return abs({ k: "arr", element:
|
|
16838
|
+
if (shape2.k === "arr") {
|
|
16839
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15835
16840
|
}
|
|
15836
|
-
const slots =
|
|
16841
|
+
const slots = shape2.elements.map((el2, i) => isHole(i) ? undefAbs() : el2);
|
|
15837
16842
|
const isUndefLit = (el2) => el2.term?.op === "lit" && el2.term.value === void 0;
|
|
15838
16843
|
const isDefaultCmp = args[0] === void 0 || !!asAbs(args[0])?.term && asAbs(args[0]).term.op === "lit" && asAbs(args[0]).term.value === void 0;
|
|
15839
16844
|
if (isDefaultCmp) {
|
|
@@ -15862,17 +16867,17 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15862
16867
|
}
|
|
15863
16868
|
}
|
|
15864
16869
|
}
|
|
15865
|
-
const el =
|
|
16870
|
+
const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15866
16871
|
return abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"));
|
|
15867
16872
|
}
|
|
15868
16873
|
if (method === "reverse") {
|
|
15869
|
-
if (
|
|
15870
|
-
const len =
|
|
15871
|
-
const holesR =
|
|
16874
|
+
if (shape2.k === "tuple") {
|
|
16875
|
+
const len = shape2.elements.length;
|
|
16876
|
+
const holesR = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
|
|
15872
16877
|
return abs(
|
|
15873
16878
|
{
|
|
15874
16879
|
k: "tuple",
|
|
15875
|
-
elements: [...
|
|
16880
|
+
elements: [...shape2.elements].reverse(),
|
|
15876
16881
|
holes: holesR && holesR.length > 0 ? holesR : void 0
|
|
15877
16882
|
},
|
|
15878
16883
|
void 0,
|
|
@@ -15880,21 +16885,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15880
16885
|
confJoin(arr.conf, "path")
|
|
15881
16886
|
);
|
|
15882
16887
|
}
|
|
15883
|
-
return abs({ k: "arr", element:
|
|
16888
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15884
16889
|
}
|
|
15885
16890
|
if (method === "toReversed") {
|
|
15886
|
-
if (
|
|
16891
|
+
if (shape2.k === "tuple") {
|
|
15887
16892
|
return abs(
|
|
15888
16893
|
{
|
|
15889
16894
|
k: "tuple",
|
|
15890
|
-
elements: [...
|
|
16895
|
+
elements: [...shape2.elements].reverse().map((el, i) => (shape2.holes ?? []).includes(shape2.elements.length - 1 - i) ? undefAbs() : el)
|
|
15891
16896
|
},
|
|
15892
16897
|
void 0,
|
|
15893
16898
|
void 0,
|
|
15894
16899
|
confJoin(arr.conf, "path")
|
|
15895
16900
|
);
|
|
15896
16901
|
}
|
|
15897
|
-
return abs({ k: "arr", element:
|
|
16902
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15898
16903
|
}
|
|
15899
16904
|
if (method === "flat") {
|
|
15900
16905
|
validateIndexArg(args[0], "flat depth may not be convertible to a number");
|
|
@@ -15922,10 +16927,10 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15922
16927
|
}
|
|
15923
16928
|
return { els: out, degraded };
|
|
15924
16929
|
};
|
|
15925
|
-
if (
|
|
15926
|
-
const es =
|
|
16930
|
+
if (shape2.k === "arr") {
|
|
16931
|
+
const es = shape2.element.shape;
|
|
15927
16932
|
const innerEls = es.k === "tuple" ? es.elements.length ? es.elements.reduce((x, y) => joinAbs(x, y)) : unknown : es.k === "arr" ? es.element : void 0;
|
|
15928
|
-
const el = innerEls !== void 0 ? joinAbs(
|
|
16933
|
+
const el = innerEls !== void 0 ? joinAbs(shape2.element, innerEls) : shape2.element;
|
|
15929
16934
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15930
16935
|
}
|
|
15931
16936
|
if (depthRaw === null) {
|
|
@@ -15933,8 +16938,8 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15933
16938
|
kind: "TypeError",
|
|
15934
16939
|
cause: "flat depth may not be convertible to a number"
|
|
15935
16940
|
});
|
|
15936
|
-
const shallow = rec(
|
|
15937
|
-
const deep = rec(
|
|
16941
|
+
const shallow = rec(shape2.elements, holeSet, 0);
|
|
16942
|
+
const deep = rec(shape2.elements, holeSet, Number.MAX_SAFE_INTEGER);
|
|
15938
16943
|
if (shallow !== null && deep !== null) {
|
|
15939
16944
|
const el = [...shallow.els, ...deep.els].reduce((x, y) => joinAbs(x, y));
|
|
15940
16945
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
@@ -15942,9 +16947,9 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15942
16947
|
return unknown;
|
|
15943
16948
|
}
|
|
15944
16949
|
const depth = depthRaw === void 0 ? 1 : Math.max(depthRaw, 0);
|
|
15945
|
-
const r = rec(
|
|
16950
|
+
const r = rec(shape2.elements, holeSet, depth);
|
|
15946
16951
|
if (r === null) {
|
|
15947
|
-
const shallow = rec(
|
|
16952
|
+
const shallow = rec(shape2.elements, holeSet, 0);
|
|
15948
16953
|
const el = shallow && shallow.els.length ? shallow.els.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15949
16954
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15950
16955
|
}
|
|
@@ -15963,22 +16968,22 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15963
16968
|
validateIndexArg(args[0], "toSpliced start may not be convertible to a number");
|
|
15964
16969
|
validateIndexArg(args[1], "toSpliced skipCount may not be convertible to a number");
|
|
15965
16970
|
const items = args.slice(2);
|
|
15966
|
-
if (
|
|
16971
|
+
if (shape2.k === "tuple") {
|
|
15967
16972
|
const st = toIOI(args[0]);
|
|
15968
16973
|
const dc = args[1] === void 0 ? void 0 : toIOI(args[1]);
|
|
15969
16974
|
if (st === null || dc === null) {
|
|
15970
|
-
const parts2 = [...
|
|
16975
|
+
const parts2 = [...shape2.elements.filter((_, i) => !isHole(i)), ...items];
|
|
15971
16976
|
const el = parts2.length ? parts2.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15972
16977
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15973
16978
|
}
|
|
15974
|
-
const len =
|
|
16979
|
+
const len = shape2.elements.length;
|
|
15975
16980
|
const a = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
|
|
15976
16981
|
const skip = dc === void 0 ? len - a : Math.max(0, Math.min(dc, len - a));
|
|
15977
16982
|
const solid = (el, i) => isHole(i) ? undefAbs() : el;
|
|
15978
16983
|
const els = [
|
|
15979
|
-
...
|
|
16984
|
+
...shape2.elements.slice(0, a).map(solid),
|
|
15980
16985
|
...items,
|
|
15981
|
-
...
|
|
16986
|
+
...shape2.elements.slice(a + skip).map((el, i) => solid(el, a + skip + i))
|
|
15982
16987
|
];
|
|
15983
16988
|
return abs(
|
|
15984
16989
|
{ k: "tuple", elements: els },
|
|
@@ -15987,7 +16992,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15987
16992
|
confJoin(arr.conf, "path")
|
|
15988
16993
|
);
|
|
15989
16994
|
}
|
|
15990
|
-
const parts = [
|
|
16995
|
+
const parts = [shape2.element, ...items];
|
|
15991
16996
|
return abs(
|
|
15992
16997
|
{ k: "arr", element: parts.reduce((x, y) => joinAbs(x, y)) },
|
|
15993
16998
|
void 0,
|
|
@@ -15998,21 +17003,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15998
17003
|
if (method === "with") {
|
|
15999
17004
|
validateIndexArg(args[0], "with index may not be convertible to a number");
|
|
16000
17005
|
const v2 = args[1] ?? undefAbs();
|
|
16001
|
-
if (
|
|
17006
|
+
if (shape2.k === "tuple") {
|
|
16002
17007
|
const iv = toIOI(args[0]) ?? 0;
|
|
16003
17008
|
if (iv === null) {
|
|
16004
17009
|
recordMayThrow({ kind: "RangeError", cause: "with index may be out of range" });
|
|
16005
17010
|
return abs(
|
|
16006
|
-
{ k: "tuple", elements:
|
|
17011
|
+
{ k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
|
|
16007
17012
|
void 0,
|
|
16008
17013
|
void 0,
|
|
16009
17014
|
"partial"
|
|
16010
17015
|
);
|
|
16011
17016
|
}
|
|
16012
|
-
const len =
|
|
17017
|
+
const len = shape2.elements.length;
|
|
16013
17018
|
const idx = iv < 0 ? len + iv : iv;
|
|
16014
17019
|
if (idx < 0 || idx >= len) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
16015
|
-
const els =
|
|
17020
|
+
const els = shape2.elements.map(
|
|
16016
17021
|
(el, i) => i === idx ? v2 : isHole(i) ? undefAbs() : el
|
|
16017
17022
|
);
|
|
16018
17023
|
return abs(
|
|
@@ -16023,15 +17028,15 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16023
17028
|
);
|
|
16024
17029
|
}
|
|
16025
17030
|
return abs(
|
|
16026
|
-
{ k: "arr", element: joinAbs(
|
|
17031
|
+
{ k: "arr", element: joinAbs(shape2.element, v2) },
|
|
16027
17032
|
void 0,
|
|
16028
17033
|
void 0,
|
|
16029
17034
|
"partial"
|
|
16030
17035
|
);
|
|
16031
17036
|
}
|
|
16032
17037
|
if (method === "concat") {
|
|
16033
|
-
if (
|
|
16034
|
-
const out = [...
|
|
17038
|
+
if (shape2.k === "tuple") {
|
|
17039
|
+
const out = [...shape2.elements];
|
|
16035
17040
|
const holesC = new Set(holes);
|
|
16036
17041
|
let degraded = false;
|
|
16037
17042
|
for (const a of args) {
|
|
@@ -16064,7 +17069,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16064
17069
|
confJoin(arr.conf, "path")
|
|
16065
17070
|
);
|
|
16066
17071
|
}
|
|
16067
|
-
const parts = [
|
|
17072
|
+
const parts = [shape2.element, ...args.map((a) => {
|
|
16068
17073
|
const aa = asAbs(a) ?? unknown;
|
|
16069
17074
|
return aa.shape.k === "arr" || aa.shape.k === "tuple" ? aa.shape.k === "arr" ? aa.shape.element : aa.shape.elements.length ? aa.shape.elements.reduce((x, y) => joinAbs(x, y)) : unknown : aa;
|
|
16070
17075
|
})];
|
|
@@ -16078,24 +17083,24 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16078
17083
|
if (method === "slice") {
|
|
16079
17084
|
validateIndexArg(args[0], "slice start may not be convertible to a number");
|
|
16080
17085
|
validateIndexArg(args[1], "slice end may not be convertible to a number");
|
|
16081
|
-
if (
|
|
17086
|
+
if (shape2.k === "tuple") {
|
|
16082
17087
|
const st = toIOI(args[0]);
|
|
16083
17088
|
const en = toIOI(args[1]);
|
|
16084
17089
|
if (st === null || en === null) {
|
|
16085
|
-
const el =
|
|
17090
|
+
const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
16086
17091
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
16087
17092
|
}
|
|
16088
|
-
const len =
|
|
17093
|
+
const len = shape2.elements.length;
|
|
16089
17094
|
const s = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
|
|
16090
17095
|
const e = en === void 0 ? len : en < 0 ? Math.max(len + en, 0) : Math.min(en, len);
|
|
16091
17096
|
if (e <= s) {
|
|
16092
17097
|
return abs({ k: "tuple", elements: [] }, void 0, void 0, confJoin(arr.conf, "exact"));
|
|
16093
17098
|
}
|
|
16094
|
-
const holesS = (
|
|
17099
|
+
const holesS = (shape2.holes ?? []).filter((h) => h >= s && h < e).map((h) => h - s);
|
|
16095
17100
|
return abs(
|
|
16096
17101
|
{
|
|
16097
17102
|
k: "tuple",
|
|
16098
|
-
elements:
|
|
17103
|
+
elements: shape2.elements.slice(s, e),
|
|
16099
17104
|
holes: holesS.length > 0 ? holesS : void 0
|
|
16100
17105
|
},
|
|
16101
17106
|
void 0,
|
|
@@ -16103,12 +17108,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16103
17108
|
confJoin(arr.conf, "path")
|
|
16104
17109
|
);
|
|
16105
17110
|
}
|
|
16106
|
-
return abs({ k: "arr", element:
|
|
17111
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
16107
17112
|
}
|
|
16108
17113
|
if (method === "indexOf" || method === "lastIndexOf") {
|
|
16109
17114
|
validateIndexArg(args[1], `${method} fromIndex may not be convertible to a number`);
|
|
16110
|
-
if (
|
|
16111
|
-
const els =
|
|
17115
|
+
if (shape2.k === "tuple") {
|
|
17116
|
+
const els = shape2.elements;
|
|
16112
17117
|
const search = args[0];
|
|
16113
17118
|
const searchLit = search !== void 0 && search.term?.op === "lit" ? litValue(search) : void 0;
|
|
16114
17119
|
const hasLitSearch = search !== void 0 && search.term?.op === "lit";
|
|
@@ -16153,22 +17158,22 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16153
17158
|
return abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
16154
17159
|
}
|
|
16155
17160
|
if (method === "pop") {
|
|
16156
|
-
if (
|
|
16157
|
-
return
|
|
17161
|
+
if (shape2.k === "tuple") {
|
|
17162
|
+
return shape2.elements.length > 0 ? shape2.elements[shape2.elements.length - 1] ?? unknown : undefAbs();
|
|
16158
17163
|
}
|
|
16159
|
-
if (
|
|
17164
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16160
17165
|
}
|
|
16161
17166
|
if (method === "shift") {
|
|
16162
|
-
if (
|
|
16163
|
-
return
|
|
17167
|
+
if (shape2.k === "tuple" && shape2.elements.length > 0) {
|
|
17168
|
+
return shape2.elements[0] ?? unknown;
|
|
16164
17169
|
}
|
|
16165
|
-
if (
|
|
17170
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16166
17171
|
}
|
|
16167
17172
|
if (method === "at") {
|
|
16168
17173
|
validateIndexArg(args[0], "at index may not be convertible to a number");
|
|
16169
17174
|
const iv = toIntegerOrInfinityLit(args[0]);
|
|
16170
|
-
if (
|
|
16171
|
-
const els =
|
|
17175
|
+
if (shape2.k === "tuple") {
|
|
17176
|
+
const els = shape2.elements;
|
|
16172
17177
|
if (iv === void 0) {
|
|
16173
17178
|
if (els.length === 0) return undefAbs();
|
|
16174
17179
|
return joinAbs(els.reduce((a, b) => joinAbs(a, b)), undefAbs());
|
|
@@ -16177,7 +17182,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16177
17182
|
if (idx >= 0 && idx < els.length) return els[idx] ?? unknown;
|
|
16178
17183
|
return undefAbs();
|
|
16179
17184
|
}
|
|
16180
|
-
if (
|
|
17185
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16181
17186
|
}
|
|
16182
17187
|
return void 0;
|
|
16183
17188
|
}
|
|
@@ -16391,11 +17396,11 @@ function $setKey(o, key, value) {
|
|
|
16391
17396
|
confJoin("path", value.conf)
|
|
16392
17397
|
);
|
|
16393
17398
|
}
|
|
16394
|
-
const
|
|
16395
|
-
const prevIndex =
|
|
17399
|
+
const shape2 = o.shape;
|
|
17400
|
+
const prevIndex = shape2.index?.value;
|
|
16396
17401
|
const indexVal = prevIndex ? joinAbs(prevIndex, val) : val;
|
|
16397
|
-
const next = objOf({ ...
|
|
16398
|
-
index: { key:
|
|
17402
|
+
const next = objOf({ ...shape2.slots }, {
|
|
17403
|
+
index: { key: shape2.index?.key ?? unknown, value: indexVal },
|
|
16399
17404
|
open: true
|
|
16400
17405
|
});
|
|
16401
17406
|
next.conf = confJoin(o.conf, value.conf);
|
|
@@ -17403,12 +18408,12 @@ ${js}`;
|
|
|
17403
18408
|
}
|
|
17404
18409
|
const cjsMerge = hasCjsExports ? `(() => { const me = $get(module, "exports"); if (me !== __nudoCjsOrig && me && typeof me === "object" && "shape" in me) { return { default: me }; } const out = {}; if (__nudoCjsOrig && __nudoCjsOrig.shape && __nudoCjsOrig.shape.k === "obj") { for (const k of Object.keys(__nudoCjsOrig.shape.slots)) out[k] = __nudoCjsOrig.shape.slots[k].value; } return out; })()` : "{}";
|
|
17405
18410
|
const ret = `return { ...__nudoExports, ...${cjsMerge}, ${names.join(", ")} };`;
|
|
17406
|
-
const
|
|
18411
|
+
const fn2 = new Function(...argNames, `${js}
|
|
17407
18412
|
${ret}`);
|
|
17408
18413
|
setEvalBindingSink(bindings);
|
|
17409
18414
|
beginClassEpoch();
|
|
17410
18415
|
try {
|
|
17411
|
-
const result =
|
|
18416
|
+
const result = fn2(...args);
|
|
17412
18417
|
runBindings.set(result, bindings);
|
|
17413
18418
|
return result;
|
|
17414
18419
|
} finally {
|
|
@@ -17500,14 +18505,14 @@ function callTranspiledExportFull(exports, name, args, opts) {
|
|
|
17500
18505
|
});
|
|
17501
18506
|
}
|
|
17502
18507
|
function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
17503
|
-
const
|
|
17504
|
-
if (typeof
|
|
18508
|
+
const fn2 = Object.hasOwn(exports, name) ? exports[name] : void 0;
|
|
18509
|
+
if (typeof fn2 === "function") {
|
|
17505
18510
|
const callArgs = args.map(
|
|
17506
18511
|
(a) => a && typeof a === "object" && "shape" in a ? $copy(a) : asAbsVal(a)
|
|
17507
18512
|
);
|
|
17508
18513
|
return runWithLoopExits(() => {
|
|
17509
18514
|
try {
|
|
17510
|
-
const invoke = () => withNewTargetReset(() =>
|
|
18515
|
+
const invoke = () => withNewTargetReset(() => fn2(...callArgs));
|
|
17511
18516
|
const r = opts?.phi ? withExecPhi(opts.phi, invoke) : invoke();
|
|
17512
18517
|
drainPromiseMicros();
|
|
17513
18518
|
if (!isAbsVal(r)) return joinControlExits(unknown);
|
|
@@ -17536,11 +18541,11 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
|
17536
18541
|
}
|
|
17537
18542
|
});
|
|
17538
18543
|
}
|
|
17539
|
-
if (isAbsVal(
|
|
17540
|
-
if (
|
|
18544
|
+
if (isAbsVal(fn2)) {
|
|
18545
|
+
if (fn2.shape.k === "fn") {
|
|
17541
18546
|
return runWithLoopExits(() => {
|
|
17542
18547
|
try {
|
|
17543
|
-
const r = $call(
|
|
18548
|
+
const r = $call(fn2, args);
|
|
17544
18549
|
drainPromiseMicros();
|
|
17545
18550
|
return joinControlExits(r);
|
|
17546
18551
|
} catch (e) {
|
|
@@ -17560,7 +18565,7 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
|
17560
18565
|
});
|
|
17561
18566
|
}
|
|
17562
18567
|
drainPromiseMicros();
|
|
17563
|
-
return { result:
|
|
18568
|
+
return { result: fn2, throws: never };
|
|
17564
18569
|
}
|
|
17565
18570
|
drainPromiseMicros();
|
|
17566
18571
|
return { result: unknown, throws: never };
|
|
@@ -17744,26 +18749,31 @@ function joinThrowsSince2(mark) {
|
|
|
17744
18749
|
if (items.length === 1) return items[0];
|
|
17745
18750
|
return items.reduce((a, b) => joinAbs(a, b));
|
|
17746
18751
|
}
|
|
17747
|
-
function $call(
|
|
17748
|
-
return withNewTargetReset(() => $callInner(
|
|
18752
|
+
function $call(fn2, args, thisVal) {
|
|
18753
|
+
return withNewTargetReset(() => $callInner(fn2, args, thisVal));
|
|
17749
18754
|
}
|
|
17750
|
-
function $callInner(
|
|
17751
|
-
if (
|
|
17752
|
-
const results =
|
|
17753
|
-
if (results.every((
|
|
18755
|
+
function $callInner(fn2, args, thisVal) {
|
|
18756
|
+
if (fn2?.shape?.k === "sum") {
|
|
18757
|
+
const results = fn2.shape.members.map((m) => $call(m, args, thisVal));
|
|
18758
|
+
if (results.every((r2) => r2.shape.k === "unknown")) return unknown;
|
|
17754
18759
|
return results.reduce((a, b) => joinAbs(a, b));
|
|
17755
18760
|
}
|
|
17756
|
-
const
|
|
17757
|
-
const
|
|
18761
|
+
const faces = contractFacesOf(fn2);
|
|
18762
|
+
const r = $callDispatch(fn2, faces ? adoptCallArgsToFaces(args, faces) : args, thisVal);
|
|
18763
|
+
return faces ? presentCallResultFace(r, faces) : r;
|
|
18764
|
+
}
|
|
18765
|
+
function $callDispatch(fn2, args, thisVal) {
|
|
18766
|
+
const pureName = pureFnNameOf(fn2);
|
|
18767
|
+
const fnObj = fn2 && typeof fn2 === "object" ? fn2 : void 0;
|
|
17758
18768
|
const pk = pureName && fnObj ? pureMemoKey(args) : void 0;
|
|
17759
18769
|
if (fnObj && pk !== void 0) {
|
|
17760
18770
|
const hit = pureMemo.get(fnObj)?.get(pk);
|
|
17761
18771
|
if (hit !== void 0) return routeApplyThrows(hit.abs, hit.throws);
|
|
17762
18772
|
}
|
|
17763
|
-
const impl = getFnImpl(
|
|
18773
|
+
const impl = getFnImpl(fn2);
|
|
17764
18774
|
if (!impl?.body && !impl?.apply) {
|
|
17765
|
-
if (impl?.relation || isRelFn(
|
|
17766
|
-
const calleeAbs =
|
|
18775
|
+
if (impl?.relation || isRelFn(fn2)) return instantiateReturn(fn2, args);
|
|
18776
|
+
const calleeAbs = fn2 && typeof fn2 === "object" ? fn2 : void 0;
|
|
17767
18777
|
const calleeK = calleeAbs?.shape?.k;
|
|
17768
18778
|
if (calleeK === "prim" || calleeAbs !== void 0 && isNullishLitAbs(calleeAbs)) {
|
|
17769
18779
|
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -17777,8 +18787,8 @@ function $callInner(fn, args, thisVal) {
|
|
|
17777
18787
|
return unknown;
|
|
17778
18788
|
}
|
|
17779
18789
|
if (impl?.apply) {
|
|
17780
|
-
const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(
|
|
17781
|
-
const label =
|
|
18790
|
+
const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(fn2), args);
|
|
18791
|
+
const label = fn2.shape.name ?? "anonymous";
|
|
17782
18792
|
if (!enterCall(key, label)) return truncatedAbs();
|
|
17783
18793
|
try {
|
|
17784
18794
|
try {
|
|
@@ -17804,8 +18814,8 @@ function $callInner(fn, args, thisVal) {
|
|
|
17804
18814
|
}
|
|
17805
18815
|
const compiled = compiledBodyOf(impl);
|
|
17806
18816
|
if (compiled) {
|
|
17807
|
-
const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(
|
|
17808
|
-
const label =
|
|
18817
|
+
const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(fn2), args);
|
|
18818
|
+
const label = fn2.shape.name ?? "anonymous";
|
|
17809
18819
|
if (!enterCall(key, label)) return truncatedAbs();
|
|
17810
18820
|
try {
|
|
17811
18821
|
const throwMark = throwExitsMark();
|
|
@@ -18182,9 +19192,9 @@ function evalObjectMethod(name, args) {
|
|
|
18182
19192
|
const key = keyR?.ok ? keyR.value : void 0;
|
|
18183
19193
|
if (typeof key !== "string") return boolPrim();
|
|
18184
19194
|
if (a0.shape.k === "obj") {
|
|
18185
|
-
const
|
|
18186
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
18187
|
-
if (!
|
|
19195
|
+
const shape2 = a0.shape;
|
|
19196
|
+
if (Object.prototype.hasOwnProperty.call(shape2.slots, key)) return boolLit(true);
|
|
19197
|
+
if (!shape2.open && a0.conf === "exact") return boolLit(false);
|
|
18188
19198
|
return boolPrim();
|
|
18189
19199
|
}
|
|
18190
19200
|
return boolPrim();
|
|
@@ -21403,7 +22413,42 @@ export {
|
|
|
21403
22413
|
$removeUndefined,
|
|
21404
22414
|
$removeMemberNullish,
|
|
21405
22415
|
$narrowTypeOf,
|
|
22416
|
+
$narrowMemberEq,
|
|
21406
22417
|
$nullishTest,
|
|
22418
|
+
SELF,
|
|
22419
|
+
getTerm,
|
|
22420
|
+
lenTerm,
|
|
22421
|
+
isNudoConstraint,
|
|
22422
|
+
isIntFlag,
|
|
22423
|
+
number,
|
|
22424
|
+
string,
|
|
22425
|
+
boolean,
|
|
22426
|
+
any,
|
|
22427
|
+
array,
|
|
22428
|
+
shape,
|
|
22429
|
+
litC,
|
|
22430
|
+
union,
|
|
22431
|
+
nullable,
|
|
22432
|
+
lazy,
|
|
22433
|
+
derefConstraint,
|
|
22434
|
+
constraintAdmitsNullish,
|
|
22435
|
+
fn,
|
|
22436
|
+
andC,
|
|
22437
|
+
partial,
|
|
22438
|
+
pick,
|
|
22439
|
+
omit,
|
|
22440
|
+
CONSTRAINT_BUILDERS,
|
|
22441
|
+
CONSTRAINT_BUILDER_NAMES,
|
|
22442
|
+
CONSTRAINT_EXPR_RE,
|
|
22443
|
+
instantiateConstraint,
|
|
22444
|
+
instantiateOnTerm,
|
|
22445
|
+
constraintToEntryAbs,
|
|
22446
|
+
fnConstraintToEntryReqs,
|
|
22447
|
+
throwConstraintToKinds,
|
|
22448
|
+
literalMeetsConstraint,
|
|
22449
|
+
attachContractFaces,
|
|
22450
|
+
setContractFaceResolver,
|
|
22451
|
+
contractFacesFromEffectiveInterface,
|
|
21407
22452
|
clearPureCallMemo,
|
|
21408
22453
|
setEvalAssignCollector,
|
|
21409
22454
|
$assignRecord,
|