@nudojs/core 1.7.9 → 1.8.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-YQIRU637.js → chunk-P6O5BXOA.js} +1389 -426
- package/dist/{chunk-5SAMWKI6.js → chunk-WT5J6QTZ.js} +80 -716
- package/dist/exec.d.ts +11 -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
|
}
|
|
@@ -3361,7 +3361,12 @@ function isKnownNonBigintNumeric(a) {
|
|
|
3361
3361
|
if (r.ok && r.value === void 0) return true;
|
|
3362
3362
|
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
3363
3363
|
}
|
|
3364
|
+
function isNullishLitOperand(a) {
|
|
3365
|
+
const r = litValue(a);
|
|
3366
|
+
return r.ok && (r.value === null || r.value === void 0);
|
|
3367
|
+
}
|
|
3364
3368
|
function isMaybeBigintOperand(a) {
|
|
3369
|
+
if (isNullishLitOperand(a)) return false;
|
|
3365
3370
|
const k = a.shape.k;
|
|
3366
3371
|
if (k === "sum") {
|
|
3367
3372
|
const members = a.shape.members;
|
|
@@ -4406,8 +4411,8 @@ function str2(conf = "path") {
|
|
|
4406
4411
|
function boolPrim(conf = "partial") {
|
|
4407
4412
|
return abs({ k: "prim", type: "boolean" }, void 0, void 0, conf);
|
|
4408
4413
|
}
|
|
4409
|
-
function peelBrand(
|
|
4410
|
-
let s =
|
|
4414
|
+
function peelBrand(shape2) {
|
|
4415
|
+
let s = shape2;
|
|
4411
4416
|
while (s.k === "brand") s = s.shape.shape;
|
|
4412
4417
|
return s;
|
|
4413
4418
|
}
|
|
@@ -5787,8 +5792,8 @@ function matchAsOverride(stmt, opts) {
|
|
|
5787
5792
|
}
|
|
5788
5793
|
return null;
|
|
5789
5794
|
}
|
|
5790
|
-
function fnBodyHasThis(
|
|
5791
|
-
const body =
|
|
5795
|
+
function fnBodyHasThis(fn2) {
|
|
5796
|
+
const body = fn2.body;
|
|
5792
5797
|
if (!body) return false;
|
|
5793
5798
|
const seen = /* @__PURE__ */ new Set();
|
|
5794
5799
|
const walk = (n) => {
|
|
@@ -5812,8 +5817,8 @@ function fnBodyHasThis(fn) {
|
|
|
5812
5817
|
};
|
|
5813
5818
|
return walk(body);
|
|
5814
5819
|
}
|
|
5815
|
-
function fnBodyHasOwnArguments(
|
|
5816
|
-
const body =
|
|
5820
|
+
function fnBodyHasOwnArguments(fn2) {
|
|
5821
|
+
const body = fn2.body;
|
|
5817
5822
|
if (!body) return false;
|
|
5818
5823
|
const seen = /* @__PURE__ */ new Set();
|
|
5819
5824
|
const walk = (n) => {
|
|
@@ -6338,16 +6343,16 @@ function isExpression(n) {
|
|
|
6338
6343
|
|
|
6339
6344
|
// src/algebra/exec/transpile/transpile-dispatch.ts
|
|
6340
6345
|
var dispatch = {};
|
|
6341
|
-
function bindTranspileExpression(
|
|
6342
|
-
dispatch.expr =
|
|
6346
|
+
function bindTranspileExpression(fn2) {
|
|
6347
|
+
dispatch.expr = fn2;
|
|
6343
6348
|
}
|
|
6344
|
-
function bindTranspileShortCircuit(
|
|
6345
|
-
dispatch.shortCircuit =
|
|
6349
|
+
function bindTranspileShortCircuit(fn2) {
|
|
6350
|
+
dispatch.shortCircuit = fn2;
|
|
6346
6351
|
}
|
|
6347
6352
|
function emitTranspileExpression(expr, opts = {}) {
|
|
6348
|
-
const
|
|
6349
|
-
if (!
|
|
6350
|
-
return
|
|
6353
|
+
const fn2 = dispatch.expr;
|
|
6354
|
+
if (!fn2) throw new Error("transpileExpression not bound (expr.ts not loaded)");
|
|
6355
|
+
return fn2(expr, opts);
|
|
6351
6356
|
}
|
|
6352
6357
|
|
|
6353
6358
|
// src/algebra/exec/transpile/member-path.ts
|
|
@@ -6542,7 +6547,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
6542
6547
|
}
|
|
6543
6548
|
if (node.type === "UpdateExpression" && node.argument) {
|
|
6544
6549
|
const arg = node.argument;
|
|
6545
|
-
const
|
|
6550
|
+
const fn2 = node.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
6546
6551
|
if (arg.type === "MemberExpression") {
|
|
6547
6552
|
const path = memberPathOf(
|
|
6548
6553
|
arg,
|
|
@@ -6550,7 +6555,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
|
|
|
6550
6555
|
);
|
|
6551
6556
|
if (path) {
|
|
6552
6557
|
const readSrc = readPathSrc(path);
|
|
6553
|
-
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${
|
|
6558
|
+
lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn2}(${readSrc})`)};`);
|
|
6554
6559
|
}
|
|
6555
6560
|
}
|
|
6556
6561
|
}
|
|
@@ -6971,15 +6976,43 @@ function mergeGrain(a, b) {
|
|
|
6971
6976
|
if (a !== b) return "nullish";
|
|
6972
6977
|
return a;
|
|
6973
6978
|
}
|
|
6979
|
+
var memberGuardTarget = (n) => {
|
|
6980
|
+
const t = n;
|
|
6981
|
+
const m = t?.type === "ChainExpression" ? t.expression : t;
|
|
6982
|
+
if (m?.type !== "MemberExpression" && m?.type !== "OptionalMemberExpression") return void 0;
|
|
6983
|
+
if (m.computed) return void 0;
|
|
6984
|
+
if (m.object?.type !== "Identifier" || !m.object.name) return void 0;
|
|
6985
|
+
const p = m.property;
|
|
6986
|
+
const key = p?.type === "Identifier" ? p.name : p?.type === "StringLiteral" && typeof p.value === "string" ? p.value : void 0;
|
|
6987
|
+
if (key === void 0) return void 0;
|
|
6988
|
+
return { name: m.object.name, key };
|
|
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
|
+
};
|
|
6974
6997
|
function nullishGuardOf(test) {
|
|
6975
6998
|
const t = test;
|
|
6976
6999
|
if (t?.type === "LogicalExpression") return compositeNullishGuardOf(t);
|
|
6977
7000
|
if (t?.type === "UnaryExpression" && t.operator === "!" && t.argument?.type === "Identifier" && t.argument.name) {
|
|
6978
7001
|
return { name: t.argument.name, arm: "alt", grain: "nullish" };
|
|
6979
7002
|
}
|
|
7003
|
+
if (t?.type === "UnaryExpression" && t.operator === "!") {
|
|
7004
|
+
const m = memberGuardTarget(t.argument);
|
|
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" };
|
|
7008
|
+
}
|
|
6980
7009
|
if (t?.type === "Identifier" && t.name) {
|
|
6981
7010
|
return { name: t.name, arm: "cons", grain: "nullish" };
|
|
6982
7011
|
}
|
|
7012
|
+
const bare = memberGuardTarget(t);
|
|
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" };
|
|
6983
7016
|
if (t?.type !== "BinaryExpression") return void 0;
|
|
6984
7017
|
const op = t.operator;
|
|
6985
7018
|
if (op !== "===" && op !== "!==" && op !== "==" && op !== "!=") return void 0;
|
|
@@ -7011,20 +7044,64 @@ function nullishGuardOf(test) {
|
|
|
7011
7044
|
const grain = litGrain(l);
|
|
7012
7045
|
if (grain !== void 0) return { name: r.name, arm: truthyArm, grain };
|
|
7013
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
|
+
}
|
|
7014
7061
|
return void 0;
|
|
7015
7062
|
}
|
|
7016
7063
|
function compositeNullishGuardOf(test) {
|
|
7017
7064
|
const t = test;
|
|
7018
7065
|
if (t?.type !== "LogicalExpression" || t.operator !== "||" && t.operator !== "&&") return void 0;
|
|
7066
|
+
const wantArm = t.operator === "||" ? "alt" : "cons";
|
|
7019
7067
|
const l = nullishGuardOf(t.left);
|
|
7020
7068
|
const r = nullishGuardOf(t.right);
|
|
7021
|
-
|
|
7022
|
-
const
|
|
7023
|
-
if (
|
|
7024
|
-
|
|
7025
|
-
|
|
7026
|
-
|
|
7027
|
-
|
|
7069
|
+
const lg = l && l.arm === wantArm ? l : void 0;
|
|
7070
|
+
const rg = r && r.arm === wantArm ? r : void 0;
|
|
7071
|
+
if (lg && rg) {
|
|
7072
|
+
if (lg.name !== rg.name) return void 0;
|
|
7073
|
+
const g1 = lg.grain === "null" || lg.grain === "undefined" ? lg.grain : null;
|
|
7074
|
+
const g2 = rg.grain === "null" || rg.grain === "undefined" ? rg.grain : null;
|
|
7075
|
+
const grain = g1 === null || g2 === null ? "nullish" : mergeGrain(g1, g2);
|
|
7076
|
+
const memberKey = lg.memberKey ?? rg.memberKey;
|
|
7077
|
+
return { name: lg.name, arm: wantArm, grain, ...memberKey !== void 0 ? { memberKey } : {} };
|
|
7078
|
+
}
|
|
7079
|
+
return lg ?? rg;
|
|
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] : [];
|
|
7028
7105
|
}
|
|
7029
7106
|
function typeGuardOf(test) {
|
|
7030
7107
|
const t = test;
|
|
@@ -7039,16 +7116,23 @@ function typeGuardOf(test) {
|
|
|
7039
7116
|
if (litSide.value === "undefined" || !TYPEOF_NAMES2.has(litSide.value)) return void 0;
|
|
7040
7117
|
return { name, typeOf: litSide.value, arm: op === "===" || op === "==" ? "cons" : "alt" };
|
|
7041
7118
|
}
|
|
7042
|
-
function
|
|
7043
|
-
if (
|
|
7044
|
-
|
|
7045
|
-
|
|
7119
|
+
function nullishRemoveCallOf(guard) {
|
|
7120
|
+
if (guard.memberKey !== void 0) {
|
|
7121
|
+
return `$removeMemberNullish($removeNullish(${guard.name}), ${JSON.stringify(guard.memberKey)})`;
|
|
7122
|
+
}
|
|
7123
|
+
if (guard.grain === "undefined") return `$removeUndefined(${guard.name})`;
|
|
7124
|
+
if (guard.grain === "null") return `$removeNull(${guard.name})`;
|
|
7125
|
+
return `$removeNullish(${guard.name})`;
|
|
7046
7126
|
}
|
|
7047
|
-
function
|
|
7048
|
-
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;
|
|
7049
7131
|
const names = forkBindingNames instanceof Set ? forkBindingNames : new Set(forkBindingNames);
|
|
7050
|
-
if (names.has(
|
|
7051
|
-
|
|
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})`;
|
|
7052
7136
|
}
|
|
7053
7137
|
function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
|
|
7054
7138
|
if (!guard) return thunk;
|
|
@@ -7151,15 +7235,26 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
|
|
|
7151
7235
|
};
|
|
7152
7236
|
const testRecvs = collectArrMutatorReceivers(stmt.test);
|
|
7153
7237
|
const testRebinds = testRecvs.size ? emitArrMutatorRebinds(stmt.test, scopedOpts, pad) : [];
|
|
7154
|
-
const
|
|
7238
|
+
const earlyGuards = nullishGuardsOf(stmt.test);
|
|
7239
|
+
const earlyTGuard = typeGuardOf(stmt.test);
|
|
7240
|
+
const consNarrowed = narrowTypeArmThunk(
|
|
7241
|
+
narrowNullishArmThunks(
|
|
7242
|
+
transpileBlockAsThunk(stmt.consequent, depth, scopedOpts),
|
|
7243
|
+
earlyGuards,
|
|
7244
|
+
"cons",
|
|
7245
|
+
recvSet
|
|
7246
|
+
),
|
|
7247
|
+
earlyTGuard,
|
|
7248
|
+
"cons",
|
|
7249
|
+
recvSet
|
|
7250
|
+
);
|
|
7251
|
+
const cons = wrapArm(consNarrowed, "fk1_");
|
|
7155
7252
|
const altBody = transpileFnBodyStmts(rest, depth + 1, { ...scopedOpts, inLoop: opts.inLoop });
|
|
7156
7253
|
const altThunk = `() => {
|
|
7157
7254
|
${altBody}
|
|
7158
7255
|
${pad}}`;
|
|
7159
|
-
const earlyGuard = nullishGuardOf(stmt.test);
|
|
7160
|
-
const earlyTGuard = typeGuardOf(stmt.test);
|
|
7161
7256
|
const altNarrowed = narrowTypeArmThunk(
|
|
7162
|
-
|
|
7257
|
+
narrowNullishArmThunks(altThunk, earlyGuards, "alt", recvSet),
|
|
7163
7258
|
earlyTGuard,
|
|
7164
7259
|
"alt",
|
|
7165
7260
|
recvSet
|
|
@@ -7489,16 +7584,16 @@ ${pad}export default ${name};`;
|
|
|
7489
7584
|
...opts,
|
|
7490
7585
|
conditionalFlow: (opts.conditionalFlow ?? 0) + 1
|
|
7491
7586
|
}) : null;
|
|
7492
|
-
const
|
|
7587
|
+
const guards = nullishGuardsOf(stmt.test);
|
|
7493
7588
|
const tguard = typeGuardOf(stmt.test);
|
|
7494
7589
|
const consNarrowed = narrowTypeArmThunk(
|
|
7495
|
-
|
|
7590
|
+
narrowNullishArmThunks(consRaw, guards, "cons", recvSet),
|
|
7496
7591
|
tguard,
|
|
7497
7592
|
"cons",
|
|
7498
7593
|
recvSet
|
|
7499
7594
|
);
|
|
7500
7595
|
const altNarrowed = altRaw === null ? null : narrowTypeArmThunk(
|
|
7501
|
-
|
|
7596
|
+
narrowNullishArmThunks(altRaw, guards, "alt", recvSet),
|
|
7502
7597
|
tguard,
|
|
7503
7598
|
"alt",
|
|
7504
7599
|
recvSet
|
|
@@ -7946,13 +8041,24 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
7946
8041
|
collectAssignedIds(stmt.test, assigned);
|
|
7947
8042
|
const bodyLocalDecls = /* @__PURE__ */ new Set();
|
|
7948
8043
|
collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
|
|
8044
|
+
const bodyWrites = /* @__PURE__ */ new Set();
|
|
8045
|
+
collectAssignedIds(stmt.body, bodyWrites);
|
|
8046
|
+
collectArrMutatorReceivers(stmt.body, bodyWrites);
|
|
8047
|
+
const loopGuards = nullishGuardsOf(stmt.test).filter(
|
|
8048
|
+
(g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
|
|
8049
|
+
);
|
|
8050
|
+
const bodyNarrowed = loopGuards.length === 0 ? body : [
|
|
8051
|
+
`${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
|
|
8052
|
+
body,
|
|
8053
|
+
`${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
|
|
8054
|
+
].join("\n");
|
|
7949
8055
|
const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
|
|
7950
8056
|
const loopOpts = opts.loopLabel ? `label: ${JSON.stringify(opts.loopLabel)}` : "";
|
|
7951
8057
|
if (names.length === 0) {
|
|
7952
8058
|
return [
|
|
7953
8059
|
`${pad}// while \u2192 $whileSeq (bounded, max=${max})`,
|
|
7954
8060
|
`${pad}$whileSeq(() => ${test}, () => {`,
|
|
7955
|
-
|
|
8061
|
+
bodyNarrowed,
|
|
7956
8062
|
`${pad}}, ${max}${loopOpts ? `, { ${loopOpts} }` : ""});`
|
|
7957
8063
|
].join("\n");
|
|
7958
8064
|
}
|
|
@@ -7961,7 +8067,7 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
7961
8067
|
return [
|
|
7962
8068
|
`${pad}// while \u2192 $whileSeq (instrumented bindings: ${names.join(", ")})`,
|
|
7963
8069
|
`${pad}$whileSeq(() => ${test}, () => {`,
|
|
7964
|
-
|
|
8070
|
+
bodyNarrowed,
|
|
7965
8071
|
`${pad}}, ${max}, { pack: () => ${packSrc}, unpack: ${unpackSrc}${loopOpts ? `, ${loopOpts}` : ""} });`
|
|
7966
8072
|
].join("\n");
|
|
7967
8073
|
}
|
|
@@ -7980,6 +8086,17 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
7980
8086
|
collectArrMutatorReceivers(stmt.body, assigned);
|
|
7981
8087
|
const bodyLocalDecls = /* @__PURE__ */ new Set();
|
|
7982
8088
|
collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
|
|
8089
|
+
const bodyWrites = /* @__PURE__ */ new Set();
|
|
8090
|
+
collectAssignedIds(stmt.body, bodyWrites);
|
|
8091
|
+
collectArrMutatorReceivers(stmt.body, bodyWrites);
|
|
8092
|
+
const loopGuards = nullishGuardsOf(stmt.test).filter(
|
|
8093
|
+
(g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
|
|
8094
|
+
);
|
|
8095
|
+
const innerBody = loopGuards.length === 0 ? bodyStmts : [
|
|
8096
|
+
`${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
|
|
8097
|
+
bodyStmts,
|
|
8098
|
+
`${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
|
|
8099
|
+
].join("\n");
|
|
7983
8100
|
const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
|
|
7984
8101
|
const packSrc = names.length === 0 ? null : `$obj({ ${names.map((n) => `${JSON.stringify(n)}: $copy(${n})`).join(", ")} })`;
|
|
7985
8102
|
const unpackSrc = names.length === 0 ? null : `(__lp) => { ${names.map((n) => `${n} = $get(__lp, ${JSON.stringify(n)});`).join(" ")} }`;
|
|
@@ -7990,7 +8107,7 @@ ${indent(depth + 1)}]${dflt})`;
|
|
|
7990
8107
|
`{`,
|
|
7991
8108
|
bodyStmts,
|
|
7992
8109
|
`${indent(depth + 1)}$whileSeq(() => ${test}, () => {`,
|
|
7993
|
-
|
|
8110
|
+
innerBody,
|
|
7994
8111
|
`${indent(depth + 1)}}, ${max}${optsSrc});`,
|
|
7995
8112
|
`${pad}}`
|
|
7996
8113
|
].join("\n");
|
|
@@ -8396,13 +8513,15 @@ function transpileShortCircuitExpr(opts, parts) {
|
|
|
8396
8513
|
const forkTest2 = parts.testSrc ?? parts.alwaysSrc;
|
|
8397
8514
|
let consExpr = parts.consSrc === "__test" ? parts.alwaysSrc : parts.consSrc;
|
|
8398
8515
|
let altExpr = parts.altSrc === "__test" ? parts.alwaysSrc : parts.altSrc;
|
|
8399
|
-
|
|
8400
|
-
|
|
8401
|
-
|
|
8402
|
-
|
|
8403
|
-
|
|
8404
|
-
}
|
|
8405
|
-
}
|
|
8516
|
+
const applyGuards = (src, arm) => {
|
|
8517
|
+
const gs = (parts.narrowGuards ?? []).filter((g) => g.arm === arm);
|
|
8518
|
+
if (gs.length === 0) return src;
|
|
8519
|
+
const params = gs.map((g) => g.name).join(", ");
|
|
8520
|
+
const args = gs.map((g) => nullishRemoveCallOf(g)).join(", ");
|
|
8521
|
+
return `((${params}) => (${src}))(${args})`;
|
|
8522
|
+
};
|
|
8523
|
+
consExpr = applyGuards(consExpr, "cons");
|
|
8524
|
+
altExpr = applyGuards(altExpr, "alt");
|
|
8406
8525
|
if (parts.typeGuard) {
|
|
8407
8526
|
const g = parts.typeGuard;
|
|
8408
8527
|
const apply = (src, arm) => `((${g.name}) => (${src}))($narrowTypeOf(${g.name}, ${JSON.stringify(g.typeOf)}, ${arm === g.arm}))`;
|
|
@@ -8414,9 +8533,9 @@ function transpileShortCircuitExpr(opts, parts) {
|
|
|
8414
8533
|
const consLines = parts.consSrc === "__test" ? [`return __test;`] : consRebinds.length === 0 ? [`return (${parts.consSrc});`] : [`const __v = (${parts.consSrc});`, ...consRebinds, `return __v;`];
|
|
8415
8534
|
const altLines = parts.altSrc === "__test" ? [`return __test;`] : altRebinds.length === 0 ? [`return (${parts.altSrc});`] : [`const __v = (${parts.altSrc});`, ...altRebinds, `return __v;`];
|
|
8416
8535
|
const forkTest = parts.testSrc ?? "__test";
|
|
8417
|
-
const
|
|
8418
|
-
const consFinal =
|
|
8419
|
-
const altFinal =
|
|
8536
|
+
const guards = parts.narrowGuards;
|
|
8537
|
+
const consFinal = narrowNullishArmThunks(forkArmThunk(consLines, "fk1_", names), guards, "cons", names);
|
|
8538
|
+
const altFinal = narrowNullishArmThunks(forkArmThunk(altLines, "fk2_", names), guards, "alt", names);
|
|
8420
8539
|
return [
|
|
8421
8540
|
`(() => {`,
|
|
8422
8541
|
` const __test = (${parts.alwaysSrc});`,
|
|
@@ -8638,7 +8757,7 @@ ${inner}
|
|
|
8638
8757
|
testSrc: `$nullishTest(${l})`
|
|
8639
8758
|
});
|
|
8640
8759
|
}
|
|
8641
|
-
const
|
|
8760
|
+
const leftGuards = nullishGuardsOf(expr.left);
|
|
8642
8761
|
const andTypeGuard = typeGuardOf(expr.left);
|
|
8643
8762
|
return op === "&&" ? transpileShortCircuitExpr(opts, {
|
|
8644
8763
|
alwaysNodes: [lNode],
|
|
@@ -8647,7 +8766,7 @@ ${inner}
|
|
|
8647
8766
|
consNodes: [rNode],
|
|
8648
8767
|
altSrc: "__test",
|
|
8649
8768
|
altNodes: [],
|
|
8650
|
-
|
|
8769
|
+
narrowGuards: leftGuards.filter((g) => g.arm === "cons"),
|
|
8651
8770
|
typeGuard: andTypeGuard
|
|
8652
8771
|
}) : transpileShortCircuitExpr(opts, {
|
|
8653
8772
|
alwaysNodes: [lNode],
|
|
@@ -8656,7 +8775,7 @@ ${inner}
|
|
|
8656
8775
|
consNodes: [],
|
|
8657
8776
|
altSrc: r,
|
|
8658
8777
|
altNodes: [rNode],
|
|
8659
|
-
|
|
8778
|
+
narrowGuards: leftGuards.filter((g) => g.arm === "alt"),
|
|
8660
8779
|
typeGuard: andTypeGuard
|
|
8661
8780
|
});
|
|
8662
8781
|
}
|
|
@@ -8675,8 +8794,9 @@ ${inner}
|
|
|
8675
8794
|
altSrc: a,
|
|
8676
8795
|
altNodes: [altNode],
|
|
8677
8796
|
// 三元的 nullish/typeof 守卫臂收窄(issue #97:`p === null ? -1 : p.major`;
|
|
8678
|
-
// Bug 23:`typeof v === "string" ? v + "!" : 0
|
|
8679
|
-
|
|
8797
|
+
// Bug 23:`typeof v === "string" ? v + "!" : 0`;#118 v3/#120:多名复合
|
|
8798
|
+
// `obj == null || node.p == null ? … : node.p.name` 一臂多事实)
|
|
8799
|
+
narrowGuards: nullishGuardsOf(expr.test),
|
|
8680
8800
|
typeGuard: typeGuardOf(expr.test)
|
|
8681
8801
|
});
|
|
8682
8802
|
}
|
|
@@ -8692,8 +8812,8 @@ ${inner}
|
|
|
8692
8812
|
const r2 = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
|
|
8693
8813
|
return `$instanceofNonIdent(${l2}, ${r2})`;
|
|
8694
8814
|
}
|
|
8695
|
-
const
|
|
8696
|
-
if (!
|
|
8815
|
+
const fn2 = BIN_OPS[expr.operator];
|
|
8816
|
+
if (!fn2) {
|
|
8697
8817
|
throw new NudoUnsupportedError(
|
|
8698
8818
|
`binary:${expr.operator}`,
|
|
8699
8819
|
expr.loc ? { line: expr.loc.start.line, column: expr.loc.start.column } : void 0
|
|
@@ -8701,7 +8821,7 @@ ${inner}
|
|
|
8701
8821
|
}
|
|
8702
8822
|
const l = isExpression(expr.left) ? transpileExpression(expr.left, opts) : "$lit(void 0)";
|
|
8703
8823
|
const r = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
|
|
8704
|
-
return `${
|
|
8824
|
+
return `${fn2}(${l}, ${r})`;
|
|
8705
8825
|
}
|
|
8706
8826
|
case "UnaryExpression": {
|
|
8707
8827
|
if (expr.operator === "delete") {
|
|
@@ -8737,20 +8857,20 @@ ${inner}
|
|
|
8737
8857
|
}
|
|
8738
8858
|
case "UpdateExpression": {
|
|
8739
8859
|
const arg = expr.argument;
|
|
8740
|
-
const
|
|
8860
|
+
const fn2 = expr.operator === "++" ? "$updateAdd" : "$updateSub";
|
|
8741
8861
|
if (arg.type === "Identifier") {
|
|
8742
8862
|
if (isConstAssignTarget(arg.name, opts)) {
|
|
8743
8863
|
return `$throwConstAssign()`;
|
|
8744
8864
|
}
|
|
8745
|
-
if (expr.prefix) return `${arg.name} = ${
|
|
8746
|
-
return `((__old) => (${arg.name} = ${
|
|
8865
|
+
if (expr.prefix) return `${arg.name} = ${fn2}(${arg.name})`;
|
|
8866
|
+
return `((__old) => (${arg.name} = ${fn2}(__old), __old))($toNumeric(${arg.name}))`;
|
|
8747
8867
|
}
|
|
8748
8868
|
if (arg.type === "MemberExpression") {
|
|
8749
8869
|
const m = arg;
|
|
8750
8870
|
const path = memberPathOf(m, opts);
|
|
8751
8871
|
if (path) {
|
|
8752
8872
|
const readSrc = readPathSrc(path);
|
|
8753
|
-
if (expr.prefix) return `${
|
|
8873
|
+
if (expr.prefix) return `${fn2}(${readSrc})`;
|
|
8754
8874
|
return `$toNumeric(${readSrc})`;
|
|
8755
8875
|
}
|
|
8756
8876
|
}
|
|
@@ -8930,23 +9050,23 @@ ${mBodyInner}
|
|
|
8930
9050
|
continue;
|
|
8931
9051
|
}
|
|
8932
9052
|
if (prop.value.type === "FunctionExpression" && !prop.value.async) {
|
|
8933
|
-
const
|
|
8934
|
-
if (!
|
|
8935
|
-
const displayNames = paramDisplayNames(
|
|
8936
|
-
const bindNames = methodBindNames(
|
|
8937
|
-
const mHasArgs = fnBodyHasOwnArguments({ body:
|
|
9053
|
+
const fn2 = prop.value;
|
|
9054
|
+
if (!fn2.generator) {
|
|
9055
|
+
const displayNames = paramDisplayNames(fn2.params);
|
|
9056
|
+
const bindNames = methodBindNames(fn2.params);
|
|
9057
|
+
const mHasArgs = fnBodyHasOwnArguments({ body: fn2.body });
|
|
8938
9058
|
const methodOpts = {
|
|
8939
9059
|
...opts,
|
|
8940
9060
|
inLoop: 0,
|
|
8941
9061
|
thisParam: "__this",
|
|
8942
9062
|
argsBinding: mHasArgs ? "__nudoArgs" : void 0
|
|
8943
9063
|
};
|
|
8944
|
-
let mBodyInner = emitFnBlockBody(
|
|
8945
|
-
varParams: paramNamesOfFn(
|
|
9064
|
+
let mBodyInner = emitFnBlockBody(fn2.body, 1, methodOpts, {
|
|
9065
|
+
varParams: paramNamesOfFn(fn2.params)
|
|
8946
9066
|
});
|
|
8947
9067
|
let mParams = ["__this", ...bindNames];
|
|
8948
9068
|
if (mHasArgs) {
|
|
8949
|
-
const bound = emitParamBindingFromArgs(
|
|
9069
|
+
const bound = emitParamBindingFromArgs(fn2.params, " ", methodOpts, "__nudoArgs");
|
|
8950
9070
|
mBodyInner = [
|
|
8951
9071
|
` let __nudoArgs = $arguments(__margs);`,
|
|
8952
9072
|
...bound.prologue,
|
|
@@ -9288,14 +9408,14 @@ ${mBodyInner}
|
|
|
9288
9408
|
}
|
|
9289
9409
|
case "ArrowFunctionExpression":
|
|
9290
9410
|
case "FunctionExpression": {
|
|
9291
|
-
const
|
|
9411
|
+
const fn2 = expr;
|
|
9292
9412
|
const isArrow = expr.type === "ArrowFunctionExpression";
|
|
9293
|
-
const nfeName = !isArrow &&
|
|
9413
|
+
const nfeName = !isArrow && fn2.id?.name ? fn2.id.name : null;
|
|
9294
9414
|
const fnValSrc = (() => {
|
|
9295
|
-
const fnCtor = isArrow || !!
|
|
9296
|
-
const hasThis = !isArrow && fnBodyHasThis(
|
|
9297
|
-
const hasArgs = !isArrow && fnBodyHasOwnArguments(
|
|
9298
|
-
const { sig, rest, prologue } = emitParamBinding(
|
|
9415
|
+
const fnCtor = isArrow || !!fn2.async || !!fn2.generator ? false : true;
|
|
9416
|
+
const hasThis = !isArrow && fnBodyHasThis(fn2);
|
|
9417
|
+
const hasArgs = !isArrow && fnBodyHasOwnArguments(fn2);
|
|
9418
|
+
const { sig, rest, prologue } = emitParamBinding(fn2.params, indent(1), opts);
|
|
9299
9419
|
const fnBodyOpts = {
|
|
9300
9420
|
...opts,
|
|
9301
9421
|
inLoop: 0,
|
|
@@ -9307,12 +9427,12 @@ ${mBodyInner}
|
|
|
9307
9427
|
const restRaw = rest && !useArgsSlot ? `__rest_raw` : rest;
|
|
9308
9428
|
const restPrologue = rest && !useArgsSlot && restRaw ? [` const ${rest} = $arr(${restRaw});`] : [];
|
|
9309
9429
|
const paramParts = restRaw ? [...sig, `...${restRaw}`] : sig;
|
|
9310
|
-
const nameList = `[${paramDisplayNames(
|
|
9430
|
+
const nameList = `[${paramDisplayNames(fn2.params).map((p) => JSON.stringify(p)).join(", ")}]`;
|
|
9311
9431
|
const thisPrologue = hasThis ? [`let __this = $rawThis(this);`] : [];
|
|
9312
9432
|
let argsSlotPrologue = [];
|
|
9313
9433
|
let argsParamParts = paramParts;
|
|
9314
9434
|
if (useArgsSlot) {
|
|
9315
|
-
const bound = emitParamBindingFromArgs(
|
|
9435
|
+
const bound = emitParamBindingFromArgs(fn2.params, " ", fnBodyOpts, "__nudoArgs");
|
|
9316
9436
|
argsSlotPrologue = [` let __nudoArgs = $arguments(__allArgs);`, ...bound.prologue];
|
|
9317
9437
|
argsParamParts = ["...__allArgs"];
|
|
9318
9438
|
} else if (hasArgs && hasThis) {
|
|
@@ -9329,27 +9449,27 @@ ${mBodyInner}
|
|
|
9329
9449
|
...thisPrologue,
|
|
9330
9450
|
...argsSlotPrologue
|
|
9331
9451
|
];
|
|
9332
|
-
if (
|
|
9452
|
+
if (fn2.body.type === "BlockStatement") {
|
|
9333
9453
|
const raw = withImplicitReturn(
|
|
9334
|
-
|
|
9335
|
-
[...allPrologue, transpileFnBodyStmts(
|
|
9454
|
+
fn2.body,
|
|
9455
|
+
[...allPrologue, transpileFnBodyStmts(fn2.body.body, 1, fnBodyOpts, {
|
|
9336
9456
|
// Bug 21:函数体 var 提升边界——参数模式名已绑定,不得提升
|
|
9337
|
-
skip: paramNamesOfFn(
|
|
9457
|
+
skip: paramNamesOfFn(fn2.params)
|
|
9338
9458
|
})].join("\n"),
|
|
9339
9459
|
1
|
|
9340
9460
|
);
|
|
9341
|
-
const inner =
|
|
9461
|
+
const inner = fn2.generator ? `return $gen(() => {
|
|
9342
9462
|
${raw}
|
|
9343
9463
|
});` : raw;
|
|
9344
9464
|
if (hasThis) {
|
|
9345
|
-
const wrap =
|
|
9465
|
+
const wrap = fn2.async && !fn2.generator ? `function (${argsParamParts.join(", ")}) { return $async(() => {
|
|
9346
9466
|
${inner}
|
|
9347
9467
|
}); }` : `function (${argsParamParts.join(", ")}) {
|
|
9348
9468
|
${inner}
|
|
9349
9469
|
}`;
|
|
9350
9470
|
return `$fnVal(${nameList}, ${wrap}, { ctor: ${fnCtor}${hasArgs ? ", padArgs: false" : ""} })`;
|
|
9351
9471
|
}
|
|
9352
|
-
if (
|
|
9472
|
+
if (fn2.async && !fn2.generator) {
|
|
9353
9473
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => {
|
|
9354
9474
|
${inner}
|
|
9355
9475
|
}), { ctor: ${fnCtor} })`;
|
|
@@ -9358,13 +9478,13 @@ ${inner}
|
|
|
9358
9478
|
${inner}
|
|
9359
9479
|
}, { ctor: ${fnCtor} })`;
|
|
9360
9480
|
}
|
|
9361
|
-
const bodySrc = transpileExpression(
|
|
9481
|
+
const bodySrc = transpileExpression(fn2.body, fnBodyOpts);
|
|
9362
9482
|
if (allPrologue.length > 0 || hasThis) {
|
|
9363
|
-
const rebinds2 = emitArrMutatorRebinds(
|
|
9483
|
+
const rebinds2 = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
|
|
9364
9484
|
const inner = [
|
|
9365
9485
|
...allPrologue,
|
|
9366
9486
|
...rebinds2.map((l) => ` ${l}`),
|
|
9367
|
-
` return ${
|
|
9487
|
+
` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
|
|
9368
9488
|
].join("\n");
|
|
9369
9489
|
if (hasThis) {
|
|
9370
9490
|
const wrap = `function (${argsParamParts.join(", ")}) {
|
|
@@ -9376,17 +9496,17 @@ ${inner}
|
|
|
9376
9496
|
${inner}
|
|
9377
9497
|
}, { ctor: ${fnCtor} })`;
|
|
9378
9498
|
}
|
|
9379
|
-
const rebinds = emitArrMutatorRebinds(
|
|
9499
|
+
const rebinds = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
|
|
9380
9500
|
if (rebinds.length > 0) {
|
|
9381
9501
|
const inner = [
|
|
9382
9502
|
...rebinds.map((l) => ` ${l}`),
|
|
9383
|
-
` return ${
|
|
9503
|
+
` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
|
|
9384
9504
|
].join("\n");
|
|
9385
9505
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => {
|
|
9386
9506
|
${inner}
|
|
9387
9507
|
}, { ctor: ${fnCtor} })`;
|
|
9388
9508
|
}
|
|
9389
|
-
if (
|
|
9509
|
+
if (fn2.async) {
|
|
9390
9510
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => ${bodySrc}), { ctor: ${fnCtor} })`;
|
|
9391
9511
|
}
|
|
9392
9512
|
return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => ${bodySrc}, { ctor: ${fnCtor} })`;
|
|
@@ -9420,7 +9540,7 @@ function transpileSource(source, opts = {}) {
|
|
|
9420
9540
|
return transpileFile(file, { ...opts, source: opts.source ?? source });
|
|
9421
9541
|
}
|
|
9422
9542
|
function runtimeImportOf(runtime) {
|
|
9423
|
-
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, $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)};`;
|
|
9543
|
+
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)};`;
|
|
9424
9544
|
}
|
|
9425
9545
|
function transpileFile(file, opts = {}) {
|
|
9426
9546
|
const runtime = opts.runtimeImport ?? "@nudojs/core/exec";
|
|
@@ -9441,7 +9561,7 @@ function transpileFile(file, opts = {}) {
|
|
|
9441
9561
|
};
|
|
9442
9562
|
const lines = [
|
|
9443
9563
|
`// nudo evaluator transpile \u2014 values are Abs; operators are overloaded calls`,
|
|
9444
|
-
`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, $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)};`,
|
|
9564
|
+
`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)};`,
|
|
9445
9565
|
``
|
|
9446
9566
|
];
|
|
9447
9567
|
if (varHoistLine) lines.push(varHoistLine);
|
|
@@ -9537,6 +9657,7 @@ __export(runtime_exports, {
|
|
|
9537
9657
|
$pushLoopExit: () => $pushLoopExit,
|
|
9538
9658
|
$rawThis: () => $rawThis,
|
|
9539
9659
|
$regex: () => $regex,
|
|
9660
|
+
$removeMemberNullish: () => $removeMemberNullish,
|
|
9540
9661
|
$removeNull: () => $removeNull,
|
|
9541
9662
|
$removeNullish: () => $removeNullish,
|
|
9542
9663
|
$removeUndefined: () => $removeUndefined,
|
|
@@ -9700,9 +9821,9 @@ var BOOLEAN_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
|
|
|
9700
9821
|
var SYMBOL_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
|
|
9701
9822
|
var BIGINT_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "toLocaleString", "valueOf"]);
|
|
9702
9823
|
function notePrimMemberMissing(recv, name, kind, loc) {
|
|
9703
|
-
const
|
|
9704
|
-
if (!
|
|
9705
|
-
const t =
|
|
9824
|
+
const shape2 = recv?.shape;
|
|
9825
|
+
if (!shape2 || shape2.k !== "prim") return false;
|
|
9826
|
+
const t = shape2.type;
|
|
9706
9827
|
if (OBJECT_PROTO_NAMES.has(name)) return false;
|
|
9707
9828
|
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;
|
|
9708
9829
|
if (!protoMethods) return false;
|
|
@@ -9824,9 +9945,9 @@ function runWithEvalMissingSlot(enabled, body) {
|
|
|
9824
9945
|
}
|
|
9825
9946
|
function noteObjSlotMissing(recv, name, loc) {
|
|
9826
9947
|
if (!isEvalMissingSlotEnabled()) return false;
|
|
9827
|
-
const
|
|
9828
|
-
if (!
|
|
9829
|
-
const obj2 =
|
|
9948
|
+
const shape2 = recv?.shape;
|
|
9949
|
+
if (!shape2 || shape2.k !== "obj") return false;
|
|
9950
|
+
const obj2 = shape2;
|
|
9830
9951
|
if (obj2.open) return false;
|
|
9831
9952
|
if (obj2.slots && Object.prototype.hasOwnProperty.call(obj2.slots, name)) return false;
|
|
9832
9953
|
const conf = recv?.conf;
|
|
@@ -10718,23 +10839,23 @@ function clampWindow(len, target, start, end) {
|
|
|
10718
10839
|
if (count <= 0) return null;
|
|
10719
10840
|
return { t, s, e: s + count };
|
|
10720
10841
|
}
|
|
10721
|
-
function copyWithinTuple(
|
|
10842
|
+
function copyWithinTuple(shape2, vals) {
|
|
10722
10843
|
validateIndexArg(vals[0], "copyWithin target may not be convertible to a number");
|
|
10723
10844
|
validateIndexArg(vals[1], "copyWithin start may not be convertible to a number");
|
|
10724
10845
|
validateIndexArg(vals[2], "copyWithin end may not be convertible to a number");
|
|
10725
10846
|
const t = toIOI(vals[0]);
|
|
10726
10847
|
const s = toIOI(vals[1]);
|
|
10727
10848
|
const e = toIOI(vals[2]);
|
|
10728
|
-
if (
|
|
10849
|
+
if (shape2.k === "tuple") {
|
|
10729
10850
|
if (t === null || s === null || e === null) {
|
|
10730
|
-
const joined =
|
|
10851
|
+
const joined = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
10731
10852
|
return abs({ k: "arr", element: joined }, void 0, void 0, "partial");
|
|
10732
10853
|
}
|
|
10733
|
-
const len =
|
|
10854
|
+
const len = shape2.elements.length;
|
|
10734
10855
|
const win = clampWindow(len, t ?? 0, s ?? 0, e ?? len);
|
|
10735
|
-
const origHoles =
|
|
10856
|
+
const origHoles = shape2.holes ?? [];
|
|
10736
10857
|
if (win) {
|
|
10737
|
-
const els = [...
|
|
10858
|
+
const els = [...shape2.elements];
|
|
10738
10859
|
const holesSet = new Set(origHoles);
|
|
10739
10860
|
const backwards = win.s < win.t && win.s + (win.e - win.s) > win.t;
|
|
10740
10861
|
const count = win.e - win.s;
|
|
@@ -10762,7 +10883,7 @@ function copyWithinTuple(shape, vals) {
|
|
|
10762
10883
|
return abs(
|
|
10763
10884
|
{
|
|
10764
10885
|
k: "tuple",
|
|
10765
|
-
elements: [...
|
|
10886
|
+
elements: [...shape2.elements],
|
|
10766
10887
|
holes: origHoles.length > 0 ? [...origHoles] : void 0
|
|
10767
10888
|
},
|
|
10768
10889
|
void 0,
|
|
@@ -10770,19 +10891,19 @@ function copyWithinTuple(shape, vals) {
|
|
|
10770
10891
|
"path"
|
|
10771
10892
|
);
|
|
10772
10893
|
}
|
|
10773
|
-
return abs({ k: "arr", element:
|
|
10894
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
10774
10895
|
}
|
|
10775
|
-
function fillTuple(
|
|
10896
|
+
function fillTuple(shape2, vals, arr) {
|
|
10776
10897
|
validateIndexArg(vals[1], "fill start may not be convertible to a number");
|
|
10777
10898
|
validateIndexArg(vals[2], "fill end may not be convertible to a number");
|
|
10778
10899
|
const v2 = vals[0] ?? unknown;
|
|
10779
10900
|
const s = toIOI(vals[1]);
|
|
10780
10901
|
const e = toIOI(vals[2]);
|
|
10781
|
-
if (
|
|
10782
|
-
const len =
|
|
10902
|
+
if (shape2.k === "tuple") {
|
|
10903
|
+
const len = shape2.elements.length;
|
|
10783
10904
|
if (s === null || e === null) {
|
|
10784
10905
|
return abs(
|
|
10785
|
-
{ k: "tuple", elements:
|
|
10906
|
+
{ k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
|
|
10786
10907
|
void 0,
|
|
10787
10908
|
void 0,
|
|
10788
10909
|
"partial"
|
|
@@ -10790,16 +10911,16 @@ function fillTuple(shape, vals, arr) {
|
|
|
10790
10911
|
}
|
|
10791
10912
|
const start = Math.max(Math.min((s ?? 0) < 0 ? len + (s ?? 0) : s ?? 0, len), 0);
|
|
10792
10913
|
const end = Math.max(Math.min((e ?? len) < 0 ? len + (e ?? len) : e ?? len, len), 0);
|
|
10793
|
-
const holes = (
|
|
10914
|
+
const holes = (shape2.holes ?? []).filter((h) => h < start || h >= end);
|
|
10794
10915
|
if (end <= start) {
|
|
10795
10916
|
return abs(
|
|
10796
|
-
{ k: "tuple", elements: [...
|
|
10917
|
+
{ k: "tuple", elements: [...shape2.elements], holes: holes.length > 0 ? holes : void 0 },
|
|
10797
10918
|
void 0,
|
|
10798
10919
|
void 0,
|
|
10799
10920
|
"path"
|
|
10800
10921
|
);
|
|
10801
10922
|
}
|
|
10802
|
-
const els =
|
|
10923
|
+
const els = shape2.elements.map((el, i) => i >= start && i < end ? v2 : el);
|
|
10803
10924
|
return abs(
|
|
10804
10925
|
{ k: "tuple", elements: els, holes: holes.length > 0 ? holes : void 0 },
|
|
10805
10926
|
void 0,
|
|
@@ -10809,7 +10930,7 @@ function fillTuple(shape, vals, arr) {
|
|
|
10809
10930
|
}
|
|
10810
10931
|
const coversAll = (s === void 0 || s === 0) && e === void 0;
|
|
10811
10932
|
return abs(
|
|
10812
|
-
{ k: "arr", element: coversAll ? v2 : joinAbs(
|
|
10933
|
+
{ k: "arr", element: coversAll ? v2 : joinAbs(shape2.element, v2) },
|
|
10813
10934
|
void 0,
|
|
10814
10935
|
void 0,
|
|
10815
10936
|
confJoin(arr.conf, coversAll ? arr.conf : "path")
|
|
@@ -10848,6 +10969,8 @@ function $copy(a) {
|
|
|
10848
10969
|
open: s.open
|
|
10849
10970
|
});
|
|
10850
10971
|
next.conf = a.conf;
|
|
10972
|
+
next.term = a.term;
|
|
10973
|
+
next.pred = a.pred;
|
|
10851
10974
|
migrateAccessors(a, next);
|
|
10852
10975
|
migrateInvariants(a, next);
|
|
10853
10976
|
migrateNullProto(a, next);
|
|
@@ -10872,8 +10995,8 @@ function $copy(a) {
|
|
|
10872
10995
|
return a;
|
|
10873
10996
|
}
|
|
10874
10997
|
function $arrMutContainer(arr, method, args) {
|
|
10875
|
-
const
|
|
10876
|
-
if (
|
|
10998
|
+
const shape2 = arr.shape;
|
|
10999
|
+
if (shape2.k !== "tuple" && shape2.k !== "arr") return arr;
|
|
10877
11000
|
const st = extStateOf(arr);
|
|
10878
11001
|
if (st === "frozen") throwStrictWrite();
|
|
10879
11002
|
if ((st === "sealed" || st === "nonext") && (method === "push" || method === "unshift" || method === "splice")) {
|
|
@@ -10883,9 +11006,9 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10883
11006
|
const asArrEl = (els) => els.length > 0 ? els.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
10884
11007
|
const writeBack = (next) => writeInPlace(arr, next);
|
|
10885
11008
|
if (method === "push" || method === "unshift") {
|
|
10886
|
-
if (
|
|
10887
|
-
const els = method === "push" ? [...
|
|
10888
|
-
const holes =
|
|
11009
|
+
if (shape2.k === "tuple") {
|
|
11010
|
+
const els = method === "push" ? [...shape2.elements, ...vals] : [...vals, ...shape2.elements];
|
|
11011
|
+
const holes = shape2.holes ? shape2.holes.map((h) => method === "push" ? h : h + vals.length) : void 0;
|
|
10889
11012
|
const conf = vals.reduce(
|
|
10890
11013
|
(acc, v2) => confJoin(acc, v2.conf),
|
|
10891
11014
|
arr.conf
|
|
@@ -10894,19 +11017,19 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10894
11017
|
abs({ k: "tuple", elements: els, holes }, void 0, void 0, conf)
|
|
10895
11018
|
);
|
|
10896
11019
|
}
|
|
10897
|
-
const el = vals.reduce((acc, v2) => joinAbs(acc, v2),
|
|
11020
|
+
const el = vals.reduce((acc, v2) => joinAbs(acc, v2), shape2.element);
|
|
10898
11021
|
return writeBack(
|
|
10899
11022
|
abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"))
|
|
10900
11023
|
);
|
|
10901
11024
|
}
|
|
10902
11025
|
if (method === "pop") {
|
|
10903
|
-
if (
|
|
10904
|
-
if (
|
|
10905
|
-
const newLen =
|
|
10906
|
-
const holes =
|
|
11026
|
+
if (shape2.k === "tuple") {
|
|
11027
|
+
if (shape2.elements.length === 0) return arr;
|
|
11028
|
+
const newLen = shape2.elements.length - 1;
|
|
11029
|
+
const holes = shape2.holes ? shape2.holes.filter((h) => h < newLen) : void 0;
|
|
10907
11030
|
return writeBack(
|
|
10908
11031
|
abs(
|
|
10909
|
-
{ k: "tuple", elements:
|
|
11032
|
+
{ k: "tuple", elements: shape2.elements.slice(0, -1), holes: holes && holes.length > 0 ? holes : void 0 },
|
|
10910
11033
|
void 0,
|
|
10911
11034
|
void 0,
|
|
10912
11035
|
arr.conf
|
|
@@ -10916,12 +11039,12 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10916
11039
|
return arr;
|
|
10917
11040
|
}
|
|
10918
11041
|
if (method === "shift") {
|
|
10919
|
-
if (
|
|
10920
|
-
if (
|
|
10921
|
-
const holes =
|
|
11042
|
+
if (shape2.k === "tuple") {
|
|
11043
|
+
if (shape2.elements.length === 0) return arr;
|
|
11044
|
+
const holes = shape2.holes ? shape2.holes.map((h) => h - 1).filter((h) => h >= 0) : void 0;
|
|
10922
11045
|
return writeBack(
|
|
10923
11046
|
abs(
|
|
10924
|
-
{ k: "tuple", elements:
|
|
11047
|
+
{ k: "tuple", elements: shape2.elements.slice(1), holes: holes && holes.length > 0 ? holes : void 0 },
|
|
10925
11048
|
void 0,
|
|
10926
11049
|
void 0,
|
|
10927
11050
|
arr.conf
|
|
@@ -10933,10 +11056,10 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10933
11056
|
if (method === "splice") {
|
|
10934
11057
|
validateIndexArg(vals[0], "splice start may not be convertible to a number");
|
|
10935
11058
|
validateIndexArg(vals[1], "splice deleteCount may not be convertible to a number");
|
|
10936
|
-
if (
|
|
11059
|
+
if (shape2.k === "tuple") {
|
|
10937
11060
|
return writeBack(
|
|
10938
11061
|
abs(
|
|
10939
|
-
{ k: "arr", element: asArrEl(
|
|
11062
|
+
{ k: "arr", element: asArrEl(shape2.elements) },
|
|
10940
11063
|
void 0,
|
|
10941
11064
|
void 0,
|
|
10942
11065
|
confJoin(arr.conf, "path")
|
|
@@ -10946,12 +11069,12 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10946
11069
|
return arr;
|
|
10947
11070
|
}
|
|
10948
11071
|
if (method === "reverse") {
|
|
10949
|
-
if (
|
|
10950
|
-
const len =
|
|
10951
|
-
const holes =
|
|
11072
|
+
if (shape2.k === "tuple") {
|
|
11073
|
+
const len = shape2.elements.length;
|
|
11074
|
+
const holes = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
|
|
10952
11075
|
return writeBack(
|
|
10953
11076
|
abs(
|
|
10954
|
-
{ k: "tuple", elements: [...
|
|
11077
|
+
{ k: "tuple", elements: [...shape2.elements].reverse(), holes },
|
|
10955
11078
|
void 0,
|
|
10956
11079
|
void 0,
|
|
10957
11080
|
arr.conf
|
|
@@ -10961,19 +11084,19 @@ function $arrMutContainer(arr, method, args) {
|
|
|
10961
11084
|
return arr;
|
|
10962
11085
|
}
|
|
10963
11086
|
if (method === "copyWithin") {
|
|
10964
|
-
return writeBack(copyWithinTuple(
|
|
11087
|
+
return writeBack(copyWithinTuple(shape2, vals));
|
|
10965
11088
|
}
|
|
10966
11089
|
if (method === "fill") {
|
|
10967
|
-
return writeBack(fillTuple(
|
|
11090
|
+
return writeBack(fillTuple(shape2, vals, arr));
|
|
10968
11091
|
}
|
|
10969
11092
|
if (method === "sort") {
|
|
10970
11093
|
validateCallableArg(vals[0], "sort comparator may not be callable", {
|
|
10971
11094
|
undefinedOk: true
|
|
10972
11095
|
});
|
|
10973
|
-
if (
|
|
11096
|
+
if (shape2.k === "tuple") {
|
|
10974
11097
|
return writeBack(
|
|
10975
11098
|
abs(
|
|
10976
|
-
{ k: "arr", element: asArrEl(
|
|
11099
|
+
{ k: "arr", element: asArrEl(shape2.elements) },
|
|
10977
11100
|
void 0,
|
|
10978
11101
|
void 0,
|
|
10979
11102
|
confJoin(arr.conf, "path")
|
|
@@ -11240,9 +11363,9 @@ function $spread(a, b) {
|
|
|
11240
11363
|
if (acc && bb.shape.k === "obj") {
|
|
11241
11364
|
let changed = false;
|
|
11242
11365
|
const slots = { ...bb.shape.slots };
|
|
11243
|
-
for (const [k,
|
|
11244
|
-
if (
|
|
11245
|
-
setSlot(slots, k, { value:
|
|
11366
|
+
for (const [k, fn2] of acc) {
|
|
11367
|
+
if (fn2.get) {
|
|
11368
|
+
setSlot(slots, k, { value: fn2.get(bb) });
|
|
11246
11369
|
changed = true;
|
|
11247
11370
|
}
|
|
11248
11371
|
}
|
|
@@ -11300,8 +11423,8 @@ function $objRest(o, keys) {
|
|
|
11300
11423
|
}
|
|
11301
11424
|
if (!isObj(o)) {
|
|
11302
11425
|
if (o.shape.k === "any") {
|
|
11303
|
-
const
|
|
11304
|
-
return { shape:
|
|
11426
|
+
const shape3 = { k: "obj", slots: {}, open: true };
|
|
11427
|
+
return { shape: shape3, conf: "partial" };
|
|
11305
11428
|
}
|
|
11306
11429
|
return unknown;
|
|
11307
11430
|
}
|
|
@@ -11313,9 +11436,9 @@ function $objRest(o, keys) {
|
|
|
11313
11436
|
setSlot(slots, k, s);
|
|
11314
11437
|
}
|
|
11315
11438
|
if (o.shape.open) openRest = true;
|
|
11316
|
-
const
|
|
11317
|
-
if (openRest)
|
|
11318
|
-
return { shape, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
|
|
11439
|
+
const shape2 = { k: "obj", slots };
|
|
11440
|
+
if (openRest) shape2.open = true;
|
|
11441
|
+
return { shape: shape2, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
|
|
11319
11442
|
}
|
|
11320
11443
|
function $arrRest(a, start) {
|
|
11321
11444
|
const mi = matchIterElements(a);
|
|
@@ -11521,30 +11644,30 @@ function elemsOf(a) {
|
|
|
11521
11644
|
return [unknown];
|
|
11522
11645
|
}
|
|
11523
11646
|
function $forInKeys(o) {
|
|
11524
|
-
const
|
|
11525
|
-
if (
|
|
11526
|
-
const members =
|
|
11647
|
+
const shape2 = o.shape;
|
|
11648
|
+
if (shape2.k === "sum") {
|
|
11649
|
+
const members = shape2.members.map((m) => $forInKeys(m));
|
|
11527
11650
|
return members.length ? members.reduce((a, b) => joinAbs(a, b)) : unknown;
|
|
11528
11651
|
}
|
|
11529
11652
|
const isArrayIndexKey = (k) => {
|
|
11530
11653
|
const n = Number(k);
|
|
11531
11654
|
return k !== "" && String(n) === k && Number.isInteger(n) && n >= 0 && n < 4294967295;
|
|
11532
11655
|
};
|
|
11533
|
-
if (
|
|
11534
|
-
const keys = enumOwnKeys(o,
|
|
11656
|
+
if (shape2.k === "obj") {
|
|
11657
|
+
const keys = enumOwnKeys(o, shape2.slots);
|
|
11535
11658
|
const intKeys = keys.filter(isArrayIndexKey).sort((a, b) => Number(a) - Number(b));
|
|
11536
11659
|
const strKeys = keys.filter((k) => !isArrayIndexKey(k));
|
|
11537
11660
|
return $arr([...intKeys, ...strKeys].map((k) => $lit(k)));
|
|
11538
11661
|
}
|
|
11539
|
-
if (
|
|
11662
|
+
if (shape2.k === "tuple") {
|
|
11540
11663
|
const idxs = [];
|
|
11541
|
-
for (let i = 0; i <
|
|
11542
|
-
if (
|
|
11664
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
11665
|
+
if (shape2.holes?.includes(i)) continue;
|
|
11543
11666
|
idxs.push(i);
|
|
11544
11667
|
}
|
|
11545
11668
|
return $arr(idxs.map((i) => $lit(String(i))));
|
|
11546
11669
|
}
|
|
11547
|
-
if (
|
|
11670
|
+
if (shape2.k === "arr") {
|
|
11548
11671
|
return abs({ k: "arr", element: $lit("0") }, void 0, void 0, "partial");
|
|
11549
11672
|
}
|
|
11550
11673
|
const svR = litValue(o);
|
|
@@ -11553,11 +11676,11 @@ function $forInKeys(o) {
|
|
|
11553
11676
|
return $arr(Array.from({ length: sv.length }, (_, i) => $lit(String(i))));
|
|
11554
11677
|
}
|
|
11555
11678
|
const isNullishLit2 = o.term?.op === "lit" && (o.term.value === null || o.term.value === void 0);
|
|
11556
|
-
if (!isNullishLit2 && (
|
|
11679
|
+
if (!isNullishLit2 && (shape2.k === "any" || shape2.k === "unknown" || shape2.k === "prim" && shape2.type === "string")) {
|
|
11557
11680
|
return abs({ k: "arr", element: str() }, void 0, void 0, "partial");
|
|
11558
11681
|
}
|
|
11559
|
-
if (
|
|
11560
|
-
const inner =
|
|
11682
|
+
if (shape2.k === "brand") {
|
|
11683
|
+
const inner = shape2.shape;
|
|
11561
11684
|
if (inner.shape.k === "obj") {
|
|
11562
11685
|
const keys = enumOwnKeys(inner, inner.shape.slots);
|
|
11563
11686
|
return $arr(keys.map((k) => $lit(k)));
|
|
@@ -11583,9 +11706,9 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
|
|
|
11583
11706
|
if (!exitJoin || !pack || !unpack) return;
|
|
11584
11707
|
unpack(joinAbs(exitJoin, pack()));
|
|
11585
11708
|
};
|
|
11586
|
-
const
|
|
11709
|
+
const shape2 = iterable.shape;
|
|
11587
11710
|
const forAwait = opts?.forAwait === true;
|
|
11588
|
-
const asyncOnly = forAwait &&
|
|
11711
|
+
const asyncOnly = forAwait && shape2.k === "obj" && !shape2.slots["@@iterator"] && !!shape2.slots["@@asyncIterator"];
|
|
11589
11712
|
if (forAwait) {
|
|
11590
11713
|
const kind = asyncIterabilityKind(iterable);
|
|
11591
11714
|
if (kind === "definite") throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -11600,7 +11723,7 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
|
|
|
11600
11723
|
const items = asyncOnly ? [unknown] : forAwait ? elemsOf(iterable).map(awaitElem) : $elems(iterable);
|
|
11601
11724
|
const svR = litValue(iterable);
|
|
11602
11725
|
const sv = svR.ok ? svR.value : void 0;
|
|
11603
|
-
const knownLen =
|
|
11726
|
+
const knownLen = shape2.k === "tuple" ? shape2.elements.length : typeof sv === "string" ? [...sv].length : collectionExactLen(iterable) ?? sideIterLen(iterable);
|
|
11604
11727
|
const unbounded = knownLen === void 0;
|
|
11605
11728
|
if (unbounded) snapExit();
|
|
11606
11729
|
const concreteCap = Math.max(maxIters, MAX_CONCRETE_LOOP_ITERS);
|
|
@@ -12019,9 +12142,9 @@ function $set(o, key, value) {
|
|
|
12019
12142
|
}
|
|
12020
12143
|
return o;
|
|
12021
12144
|
}
|
|
12022
|
-
const
|
|
12145
|
+
const shape2 = o.shape;
|
|
12023
12146
|
const st = extStateOf(o);
|
|
12024
|
-
const hasKey = Object.prototype.hasOwnProperty.call(
|
|
12147
|
+
const hasKey = Object.prototype.hasOwnProperty.call(shape2.slots, key);
|
|
12025
12148
|
if (st === "frozen") throwStrictWrite();
|
|
12026
12149
|
if ((st === "sealed" || st === "nonext") && !hasKey) throwStrictWrite();
|
|
12027
12150
|
if (getPropFlags(o)?.get(key)?.writable === false) throwStrictWrite();
|
|
@@ -12033,7 +12156,7 @@ function $set(o, key, value) {
|
|
|
12033
12156
|
if (key === "__proto__" && !isNullProtoObj(o)) {
|
|
12034
12157
|
return $setProto(o, value);
|
|
12035
12158
|
}
|
|
12036
|
-
setSlot(
|
|
12159
|
+
setSlot(shape2.slots, key, { value: asAbsVal(value) });
|
|
12037
12160
|
o.conf = confJoin(o.conf, value.conf);
|
|
12038
12161
|
clearStaleTermPred(o);
|
|
12039
12162
|
return o;
|
|
@@ -12193,7 +12316,7 @@ function instanceOf(left, rightClassName, env) {
|
|
|
12193
12316
|
term: { op: "lit", value: v2 },
|
|
12194
12317
|
conf: "exact"
|
|
12195
12318
|
});
|
|
12196
|
-
const
|
|
12319
|
+
const partial2 = () => ({ shape: { k: "prim", type: "boolean" }, conf: "partial" });
|
|
12197
12320
|
switch (left.shape.k) {
|
|
12198
12321
|
case "brand": {
|
|
12199
12322
|
if (rightClassName === "Object") return t(true);
|
|
@@ -12203,28 +12326,28 @@ function instanceOf(left, rightClassName, env) {
|
|
|
12203
12326
|
case "tuple":
|
|
12204
12327
|
if (rightClassName === "Array" || rightClassName === "Object") return t(true);
|
|
12205
12328
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12206
|
-
return
|
|
12329
|
+
return partial2();
|
|
12207
12330
|
// 可能是 Array 子类
|
|
12208
12331
|
case "obj":
|
|
12209
12332
|
if (rightClassName === "Object") return t(true);
|
|
12210
12333
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12211
|
-
return
|
|
12334
|
+
return partial2();
|
|
12212
12335
|
case "fn":
|
|
12213
12336
|
if (rightClassName === "Function" || rightClassName === "Object") return t(true);
|
|
12214
12337
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12215
|
-
return
|
|
12338
|
+
return partial2();
|
|
12216
12339
|
case "eff":
|
|
12217
12340
|
if (left.shape.eff === "promise") {
|
|
12218
12341
|
if (rightClassName === "Promise" || rightClassName === "Object") return t(true);
|
|
12219
12342
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12220
|
-
return
|
|
12343
|
+
return partial2();
|
|
12221
12344
|
}
|
|
12222
12345
|
if (left.shape.eff === "generator") {
|
|
12223
12346
|
if (rightClassName === "Generator" || rightClassName === "Object") return t(true);
|
|
12224
12347
|
if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
|
|
12225
|
-
return
|
|
12348
|
+
return partial2();
|
|
12226
12349
|
}
|
|
12227
|
-
return
|
|
12350
|
+
return partial2();
|
|
12228
12351
|
case "prim":
|
|
12229
12352
|
return t(false);
|
|
12230
12353
|
// 原始值无装箱
|
|
@@ -12583,13 +12706,13 @@ function setGenJoinOverride(v2) {
|
|
|
12583
12706
|
function bumpGenPathSensitive() {
|
|
12584
12707
|
genPathSensitive++;
|
|
12585
12708
|
}
|
|
12586
|
-
function withIsolatedYields(
|
|
12709
|
+
function withIsolatedYields(fn2) {
|
|
12587
12710
|
const top = yieldStack[yieldStack.length - 1];
|
|
12588
|
-
if (!top) return { v:
|
|
12711
|
+
if (!top) return { v: fn2(), ys: null };
|
|
12589
12712
|
const armYs = [];
|
|
12590
12713
|
yieldStack[yieldStack.length - 1] = armYs;
|
|
12591
12714
|
try {
|
|
12592
|
-
return { v:
|
|
12715
|
+
return { v: fn2(), ys: armYs };
|
|
12593
12716
|
} finally {
|
|
12594
12717
|
yieldStack[yieldStack.length - 1] = top;
|
|
12595
12718
|
}
|
|
@@ -13012,10 +13135,10 @@ function $switch(disc, cases, dflt) {
|
|
|
13012
13135
|
beginCollectionFork();
|
|
13013
13136
|
const armOverlays2 = [];
|
|
13014
13137
|
const armYsList = [];
|
|
13015
|
-
const runArm = (
|
|
13138
|
+
const runArm = (fn2) => {
|
|
13016
13139
|
pushCollectionArm();
|
|
13017
13140
|
try {
|
|
13018
|
-
const r = withIsolatedYields(() => runForkArm(
|
|
13141
|
+
const r = withIsolatedYields(() => runForkArm(fn2, exits));
|
|
13019
13142
|
armYsList.push(r.ys);
|
|
13020
13143
|
return r.v;
|
|
13021
13144
|
} finally {
|
|
@@ -13282,6 +13405,28 @@ function $removeUndefined(a) {
|
|
|
13282
13405
|
}
|
|
13283
13406
|
return a;
|
|
13284
13407
|
}
|
|
13408
|
+
function $removeMemberNullish(a, key) {
|
|
13409
|
+
if (!a || typeof a !== "object" || !("shape" in a)) return a;
|
|
13410
|
+
if (a.shape.k !== "obj") return a;
|
|
13411
|
+
const slots = a.shape.slots;
|
|
13412
|
+
if (!Object.prototype.hasOwnProperty.call(slots, key)) return a;
|
|
13413
|
+
const slot = slots[key];
|
|
13414
|
+
let value = slot.value;
|
|
13415
|
+
let changed = false;
|
|
13416
|
+
if (!definitelyNotNullishShape(value.shape) && value.shape.k === "sum") {
|
|
13417
|
+
const members = value.shape.members;
|
|
13418
|
+
const kept = members.filter((m) => !isNullishLitAbs(m));
|
|
13419
|
+
if (kept.length > 0 && kept.length < members.length) {
|
|
13420
|
+
value = kept.length === 1 ? kept[0] : { ...value, shape: { k: "sum", members: kept } };
|
|
13421
|
+
changed = true;
|
|
13422
|
+
}
|
|
13423
|
+
}
|
|
13424
|
+
if (slot.optional) changed = true;
|
|
13425
|
+
if (!changed) return a;
|
|
13426
|
+
const next = { ...slot, value };
|
|
13427
|
+
delete next.optional;
|
|
13428
|
+
return { ...a, shape: { ...a.shape, slots: { ...slots, [key]: next } } };
|
|
13429
|
+
}
|
|
13285
13430
|
function typeofOfMember(m) {
|
|
13286
13431
|
const t = m.term;
|
|
13287
13432
|
if (t?.op === "lit") {
|
|
@@ -13439,6 +13584,773 @@ var BoundedLruMap = class {
|
|
|
13439
13584
|
}
|
|
13440
13585
|
};
|
|
13441
13586
|
|
|
13587
|
+
// src/algebra/constraint.ts
|
|
13588
|
+
var SELF = "__nudo_self__";
|
|
13589
|
+
function selfTerm() {
|
|
13590
|
+
return v(SELF);
|
|
13591
|
+
}
|
|
13592
|
+
function getTerm(obj2, key) {
|
|
13593
|
+
return app("get", [obj2, lit(key)]);
|
|
13594
|
+
}
|
|
13595
|
+
function lenTerm(t) {
|
|
13596
|
+
return app("length", [t]);
|
|
13597
|
+
}
|
|
13598
|
+
function isConstraint(x) {
|
|
13599
|
+
return !!x && typeof x === "object" && x.__nudoConstraint === true;
|
|
13600
|
+
}
|
|
13601
|
+
function isNudoConstraint(x) {
|
|
13602
|
+
return isConstraint(x);
|
|
13603
|
+
}
|
|
13604
|
+
var intFlaggedBuilders = /* @__PURE__ */ new WeakSet();
|
|
13605
|
+
function isIntFlag(c) {
|
|
13606
|
+
return c.int === true || intFlaggedBuilders.has(c);
|
|
13607
|
+
}
|
|
13608
|
+
function makeBuilder(prim, preds, extra) {
|
|
13609
|
+
const fields = extra?.fields;
|
|
13610
|
+
const element = extra?.element;
|
|
13611
|
+
const isInt = extra?.int;
|
|
13612
|
+
const optional = extra?.optional;
|
|
13613
|
+
const members = extra?.members;
|
|
13614
|
+
const fnSlot = extra?.fn;
|
|
13615
|
+
const lazySlot = extra?.lazy;
|
|
13616
|
+
const base = {
|
|
13617
|
+
__nudoConstraint: true,
|
|
13618
|
+
...prim ? { prim } : {},
|
|
13619
|
+
preds: [...preds],
|
|
13620
|
+
...fields ? { fields } : {},
|
|
13621
|
+
...element ? { element } : {},
|
|
13622
|
+
...optional ? { isOptional: true } : {},
|
|
13623
|
+
...members ? { members } : {},
|
|
13624
|
+
...fnSlot ? { fn: fnSlot } : {},
|
|
13625
|
+
...lazySlot ? { lazy: lazySlot } : {}
|
|
13626
|
+
};
|
|
13627
|
+
const add2 = (p) => makeBuilder(prim, [...preds, p], extra);
|
|
13628
|
+
const builder = Object.assign(
|
|
13629
|
+
/* @__PURE__ */ Object.create(null),
|
|
13630
|
+
base,
|
|
13631
|
+
{
|
|
13632
|
+
gt: (n) => add2(gt(selfTerm(), lit(n))),
|
|
13633
|
+
ge: (n) => add2(ge(selfTerm(), lit(n))),
|
|
13634
|
+
lt: (n) => add2(lt(selfTerm(), lit(n))),
|
|
13635
|
+
le: (n) => add2(le(selfTerm(), lit(n))),
|
|
13636
|
+
int: () => makeBuilder(prim ?? "number", preds, { ...extra, int: true }),
|
|
13637
|
+
min: (n) => add2(ge(lenTerm(selfTerm()), lit(n))),
|
|
13638
|
+
max: (n) => add2(le(lenTerm(selfTerm()), lit(n))),
|
|
13639
|
+
length: (n) => add2(and(ge(lenTerm(selfTerm()), lit(n)), le(lenTerm(selfTerm()), lit(n)))),
|
|
13640
|
+
shift: (n) => {
|
|
13641
|
+
if (!Number.isFinite(n))
|
|
13642
|
+
throw new Error("nudo shift(): offset must be a finite number");
|
|
13643
|
+
if (fields || element || members || fnSlot || lazySlot)
|
|
13644
|
+
throw new Error("nudo shift(): only numeric scalar constraint chains are allowed (shape/array/union/fn are not supported)");
|
|
13645
|
+
if (prim !== void 0 && prim !== "number")
|
|
13646
|
+
throw new Error(`nudo shift(): only numeric chains are allowed (prim=${prim})`);
|
|
13647
|
+
return makeBuilder(prim, shiftBoundPreds(preds, n), extra);
|
|
13648
|
+
},
|
|
13649
|
+
optional: () => makeBuilder(prim, preds, { ...extra, optional: true })
|
|
13650
|
+
}
|
|
13651
|
+
);
|
|
13652
|
+
if (isInt) intFlaggedBuilders.add(builder);
|
|
13653
|
+
return builder;
|
|
13654
|
+
}
|
|
13655
|
+
function shiftBoundPreds(preds, n) {
|
|
13656
|
+
return preds.map((p) => {
|
|
13657
|
+
if (p.op !== "gt" && p.op !== "ge" && p.op !== "lt" && p.op !== "le")
|
|
13658
|
+
throw new Error(`nudo shift(): predicate ${p.op} is not supported (only gt/ge/lt/le constant bounds)`);
|
|
13659
|
+
const { a, b } = p;
|
|
13660
|
+
if (b.op !== "lit" || typeof b.value !== "number")
|
|
13661
|
+
throw new Error("nudo shift(): the right-hand side of a constant bound must be a numeric literal");
|
|
13662
|
+
if (termHasApp(a, "length") || termHasApp(b, "length"))
|
|
13663
|
+
throw new Error("nudo shift(): length(...) bounds are not supported");
|
|
13664
|
+
return { op: p.op, a, b: lit(b.value + n) };
|
|
13665
|
+
});
|
|
13666
|
+
}
|
|
13667
|
+
function termHasApp(t, fn2) {
|
|
13668
|
+
if (t.op !== "app") return false;
|
|
13669
|
+
if (t.fn === fn2) return true;
|
|
13670
|
+
return t.args.some((x) => termHasApp(x, fn2));
|
|
13671
|
+
}
|
|
13672
|
+
function number() {
|
|
13673
|
+
return makeBuilder("number", []);
|
|
13674
|
+
}
|
|
13675
|
+
function string() {
|
|
13676
|
+
return makeBuilder("string", []);
|
|
13677
|
+
}
|
|
13678
|
+
function boolean() {
|
|
13679
|
+
return makeBuilder("boolean", []);
|
|
13680
|
+
}
|
|
13681
|
+
function any() {
|
|
13682
|
+
return makeBuilder(void 0, []);
|
|
13683
|
+
}
|
|
13684
|
+
function array(item) {
|
|
13685
|
+
return makeBuilder(void 0, [], {
|
|
13686
|
+
element: asNestedConstraint(item, "array(item)")
|
|
13687
|
+
});
|
|
13688
|
+
}
|
|
13689
|
+
function shape(fields) {
|
|
13690
|
+
const mapped = {};
|
|
13691
|
+
for (const [k, v2] of Object.entries(fields)) {
|
|
13692
|
+
const constraint = asNestedConstraint(v2, `shape \u5B57\u6BB5 '${k}'`);
|
|
13693
|
+
mapped[k] = {
|
|
13694
|
+
constraint,
|
|
13695
|
+
...constraint.isOptional ? { optional: true } : {}
|
|
13696
|
+
};
|
|
13697
|
+
}
|
|
13698
|
+
return makeBuilder(void 0, [], { fields: mapped });
|
|
13699
|
+
}
|
|
13700
|
+
function toPlainConstraint(c) {
|
|
13701
|
+
if (!isConstraint(c))
|
|
13702
|
+
throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
|
|
13703
|
+
return {
|
|
13704
|
+
__nudoConstraint: true,
|
|
13705
|
+
...c.prim ? { prim: c.prim } : {},
|
|
13706
|
+
preds: [...c.preds],
|
|
13707
|
+
...c.fields ? { fields: c.fields } : {},
|
|
13708
|
+
...c.element ? { element: c.element } : {},
|
|
13709
|
+
// isIntFlag 统一读取:builder(int 是方法)查 WeakSet,纯数据看 === true
|
|
13710
|
+
...isIntFlag(c) ? { int: true } : {},
|
|
13711
|
+
...c.isOptional ? { isOptional: true } : {},
|
|
13712
|
+
...c.members ? { members: c.members } : {},
|
|
13713
|
+
...c.fn ? { fn: c.fn } : {},
|
|
13714
|
+
...c.lazy ? { lazy: c.lazy } : {}
|
|
13715
|
+
};
|
|
13716
|
+
}
|
|
13717
|
+
function litC(v2) {
|
|
13718
|
+
const prim = typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : typeof v2 === "boolean" ? "boolean" : void 0;
|
|
13719
|
+
return makeBuilder(prim, [eq(selfTerm(), lit(v2))]);
|
|
13720
|
+
}
|
|
13721
|
+
function asNestedConstraint(x, ctx2) {
|
|
13722
|
+
if (isConstraint(x)) return toPlainConstraint(x);
|
|
13723
|
+
if (x === null || x === void 0 || typeof x === "number" || typeof x === "string" || typeof x === "boolean") {
|
|
13724
|
+
return toPlainConstraint(litC(x));
|
|
13725
|
+
}
|
|
13726
|
+
throw new Error(
|
|
13727
|
+
`nudo: ${ctx2} expects a constraint value (number()/string()/\u2026) or a concrete literal; received a non-constraint`
|
|
13728
|
+
);
|
|
13729
|
+
}
|
|
13730
|
+
function union(...cs) {
|
|
13731
|
+
if (cs.length === 0)
|
|
13732
|
+
throw new Error("nudo union(): at least one member constraint is required");
|
|
13733
|
+
return makeBuilder(void 0, [], {
|
|
13734
|
+
members: cs.map((c) => asNestedConstraint(c, "union member"))
|
|
13735
|
+
});
|
|
13736
|
+
}
|
|
13737
|
+
function nullable(c) {
|
|
13738
|
+
return makeBuilder(void 0, [], {
|
|
13739
|
+
members: [
|
|
13740
|
+
asNestedConstraint(c, "nullable()"),
|
|
13741
|
+
toPlainConstraint(litC(null)),
|
|
13742
|
+
toPlainConstraint(litC(void 0))
|
|
13743
|
+
]
|
|
13744
|
+
});
|
|
13745
|
+
}
|
|
13746
|
+
function lazy(thunk) {
|
|
13747
|
+
if (typeof thunk !== "function")
|
|
13748
|
+
throw new Error("nudo lazy(): expects a thunk function () => constraint");
|
|
13749
|
+
return makeBuilder(void 0, [], { lazy: thunk });
|
|
13750
|
+
}
|
|
13751
|
+
var LAZY_TEMPLATE_DEPTH = 3;
|
|
13752
|
+
var lazyDerefMemo = /* @__PURE__ */ new WeakMap();
|
|
13753
|
+
function derefConstraint(c) {
|
|
13754
|
+
const thunk = c.lazy;
|
|
13755
|
+
if (!thunk) return c;
|
|
13756
|
+
const memoized = lazyDerefMemo.get(thunk);
|
|
13757
|
+
if (memoized) return memoized;
|
|
13758
|
+
const out = thunk();
|
|
13759
|
+
if (!isConstraint(out))
|
|
13760
|
+
throw new Error(
|
|
13761
|
+
"nudo lazy(): the thunk must return a constraint (number()/string()/shape()/\u2026)"
|
|
13762
|
+
);
|
|
13763
|
+
const normalized = toPlainConstraint(out);
|
|
13764
|
+
lazyDerefMemo.set(thunk, normalized);
|
|
13765
|
+
return normalized;
|
|
13766
|
+
}
|
|
13767
|
+
function constraintAdmitsNullish(c, seen) {
|
|
13768
|
+
if (c.lazy) {
|
|
13769
|
+
const s = seen ?? /* @__PURE__ */ new Set();
|
|
13770
|
+
if (s.has(c.lazy)) return false;
|
|
13771
|
+
s.add(c.lazy);
|
|
13772
|
+
return constraintAdmitsNullish(derefConstraint(c), s);
|
|
13773
|
+
}
|
|
13774
|
+
if (c.members)
|
|
13775
|
+
return c.members.some((m) => constraintAdmitsNullish(m, seen));
|
|
13776
|
+
if (!c.prim && c.preds.length === 0 && !c.fields && !c.element && !c.fn) return true;
|
|
13777
|
+
for (const p of c.preds) {
|
|
13778
|
+
for (const flat of p.op === "and" ? p.args : [p]) {
|
|
13779
|
+
if (flat.op !== "eq") continue;
|
|
13780
|
+
for (const side of [flat.a, flat.b]) {
|
|
13781
|
+
if (side.op === "lit" && (side.value === null || side.value === void 0)) return true;
|
|
13782
|
+
}
|
|
13783
|
+
}
|
|
13784
|
+
}
|
|
13785
|
+
return false;
|
|
13786
|
+
}
|
|
13787
|
+
function fn(params, returns, opts) {
|
|
13788
|
+
const normalized = {};
|
|
13789
|
+
for (const [k, v2] of Object.entries(params)) {
|
|
13790
|
+
normalized[k] = asNestedConstraint(v2, `fn param '${k}'`);
|
|
13791
|
+
}
|
|
13792
|
+
return makeBuilder(void 0, [], {
|
|
13793
|
+
fn: {
|
|
13794
|
+
params: normalized,
|
|
13795
|
+
...returns !== void 0 ? { returns: asNestedConstraint(returns, "fn return value") } : {},
|
|
13796
|
+
...opts?.throws !== void 0 ? { throws: asNestedConstraint(opts.throws, "fn throws") } : {}
|
|
13797
|
+
}
|
|
13798
|
+
});
|
|
13799
|
+
}
|
|
13800
|
+
function andC(...cs) {
|
|
13801
|
+
if (cs.length === 0)
|
|
13802
|
+
throw new Error("nudo and(): at least one constraint is required");
|
|
13803
|
+
let prim;
|
|
13804
|
+
let isInt = false;
|
|
13805
|
+
let allOptional = true;
|
|
13806
|
+
const preds = [];
|
|
13807
|
+
for (const c0 of cs) {
|
|
13808
|
+
if (!isConstraint(c0))
|
|
13809
|
+
throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
|
|
13810
|
+
const c = derefConstraint(c0);
|
|
13811
|
+
if (c.fields || c.element || c.members || c.fn)
|
|
13812
|
+
throw new Error("nudo and(): Phase 1 supports scalar constraint conjunction only (shape/array/union/fn are not supported)");
|
|
13813
|
+
if (c.prim) {
|
|
13814
|
+
if (prim !== void 0 && prim !== c.prim)
|
|
13815
|
+
throw new Error(`nudo and(): inconsistent prim (${prim} vs ${c.prim})`);
|
|
13816
|
+
prim = c.prim;
|
|
13817
|
+
}
|
|
13818
|
+
preds.push(...c.preds);
|
|
13819
|
+
if (isIntFlag(c)) isInt = true;
|
|
13820
|
+
if (!c.isOptional) allOptional = false;
|
|
13821
|
+
}
|
|
13822
|
+
return makeBuilder(prim, preds, {
|
|
13823
|
+
...isInt ? { int: true } : {},
|
|
13824
|
+
...allOptional ? { optional: true } : {}
|
|
13825
|
+
});
|
|
13826
|
+
}
|
|
13827
|
+
function partial(c) {
|
|
13828
|
+
if (!isConstraint(c))
|
|
13829
|
+
throw new Error("nudo partial(): only shape(...) constraints are accepted");
|
|
13830
|
+
const d = derefConstraint(c);
|
|
13831
|
+
if (!d.fields)
|
|
13832
|
+
throw new Error("nudo partial(): only shape(...) constraints are accepted");
|
|
13833
|
+
const fields = {};
|
|
13834
|
+
for (const [k, f] of Object.entries(d.fields)) {
|
|
13835
|
+
fields[k] = {
|
|
13836
|
+
constraint: { ...toPlainConstraint(f.constraint), isOptional: true },
|
|
13837
|
+
optional: true
|
|
13838
|
+
};
|
|
13839
|
+
}
|
|
13840
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
13841
|
+
}
|
|
13842
|
+
function pick(c, keys) {
|
|
13843
|
+
if (!isConstraint(c))
|
|
13844
|
+
throw new Error("nudo pick(): only shape(...) constraints are accepted");
|
|
13845
|
+
const d = derefConstraint(c);
|
|
13846
|
+
if (!d.fields)
|
|
13847
|
+
throw new Error("nudo pick(): only shape(...) constraints are accepted");
|
|
13848
|
+
const fields = {};
|
|
13849
|
+
for (const k of keys) {
|
|
13850
|
+
const f = d.fields[k];
|
|
13851
|
+
if (f) fields[k] = f;
|
|
13852
|
+
}
|
|
13853
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
13854
|
+
}
|
|
13855
|
+
function omit(c, keys) {
|
|
13856
|
+
if (!isConstraint(c))
|
|
13857
|
+
throw new Error("nudo omit(): only shape(...) constraints are accepted");
|
|
13858
|
+
const d = derefConstraint(c);
|
|
13859
|
+
if (!d.fields)
|
|
13860
|
+
throw new Error("nudo omit(): only shape(...) constraints are accepted");
|
|
13861
|
+
const drop = new Set(keys);
|
|
13862
|
+
const fields = {};
|
|
13863
|
+
for (const [k, f] of Object.entries(d.fields)) {
|
|
13864
|
+
if (!drop.has(k)) fields[k] = f;
|
|
13865
|
+
}
|
|
13866
|
+
return makeBuilder(d.prim, d.preds, { fields });
|
|
13867
|
+
}
|
|
13868
|
+
var CONSTRAINT_BUILDERS = {
|
|
13869
|
+
number,
|
|
13870
|
+
string,
|
|
13871
|
+
boolean,
|
|
13872
|
+
any,
|
|
13873
|
+
array,
|
|
13874
|
+
shape,
|
|
13875
|
+
lit: litC,
|
|
13876
|
+
union,
|
|
13877
|
+
nullable,
|
|
13878
|
+
lazy,
|
|
13879
|
+
fn,
|
|
13880
|
+
and: andC,
|
|
13881
|
+
partial,
|
|
13882
|
+
pick,
|
|
13883
|
+
omit
|
|
13884
|
+
};
|
|
13885
|
+
var CONSTRAINT_BUILDER_NAMES = Object.keys(
|
|
13886
|
+
CONSTRAINT_BUILDERS
|
|
13887
|
+
);
|
|
13888
|
+
var CONSTRAINT_EXPR_RE = new RegExp(
|
|
13889
|
+
`^(${CONSTRAINT_BUILDER_NAMES.join("|")})\\s*\\(`
|
|
13890
|
+
);
|
|
13891
|
+
function substTerm(t, paramName) {
|
|
13892
|
+
if (t.op === "var" && t.id === SELF) return v(paramName);
|
|
13893
|
+
if (t.op === "app" && t.fn === "get" && t.args.length === 2) {
|
|
13894
|
+
return getTerm(substTerm(t.args[0], paramName), String(
|
|
13895
|
+
t.args[1].op === "lit" ? t.args[1].value : ""
|
|
13896
|
+
));
|
|
13897
|
+
}
|
|
13898
|
+
return t;
|
|
13899
|
+
}
|
|
13900
|
+
function substPred2(p, paramName) {
|
|
13901
|
+
switch (p.op) {
|
|
13902
|
+
case "gt":
|
|
13903
|
+
case "ge":
|
|
13904
|
+
case "lt":
|
|
13905
|
+
case "le":
|
|
13906
|
+
case "eq":
|
|
13907
|
+
case "ne": {
|
|
13908
|
+
return { op: p.op, a: substTerm(p.a, paramName), b: substTerm(p.b, paramName) };
|
|
13909
|
+
}
|
|
13910
|
+
case "typeof": {
|
|
13911
|
+
return { op: "typeof", t: substTerm(p.t, paramName), type: p.type };
|
|
13912
|
+
}
|
|
13913
|
+
case "and":
|
|
13914
|
+
return and(...p.args.map((x) => substPred2(x, paramName)));
|
|
13915
|
+
default:
|
|
13916
|
+
return p;
|
|
13917
|
+
}
|
|
13918
|
+
}
|
|
13919
|
+
function instantiateConstraint(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
|
|
13920
|
+
if (c.lazy) {
|
|
13921
|
+
if (depth <= 0) return pTrue;
|
|
13922
|
+
return instantiateConstraint(derefConstraint(c), paramName, depth - 1);
|
|
13923
|
+
}
|
|
13924
|
+
if (c.fields) {
|
|
13925
|
+
const parts = [];
|
|
13926
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
13927
|
+
if (field.optional || field.constraint.isOptional) continue;
|
|
13928
|
+
const fieldTerm = getTerm(v(paramName), key);
|
|
13929
|
+
parts.push(instantiateOnTerm(field.constraint, fieldTerm, depth));
|
|
13930
|
+
}
|
|
13931
|
+
if (c.prim) parts.push(ptypeof(v(paramName), primToTypeof(c.prim)));
|
|
13932
|
+
if (parts.length === 0) return { op: "true" };
|
|
13933
|
+
return parts.length === 1 ? parts[0] : and(...parts);
|
|
13934
|
+
}
|
|
13935
|
+
if (c.members) {
|
|
13936
|
+
const disj = or(
|
|
13937
|
+
...c.members.map((m) => instantiateOnTerm(m, v(paramName), depth))
|
|
13938
|
+
);
|
|
13939
|
+
const own = c.preds.map((p) => substPred2(p, paramName));
|
|
13940
|
+
return own.length === 0 ? disj : and(...own, disj);
|
|
13941
|
+
}
|
|
13942
|
+
if (c.fn) {
|
|
13943
|
+
const own = c.preds.map((p) => substPred2(p, paramName));
|
|
13944
|
+
return own.length === 0 ? pTrue : and(...own);
|
|
13945
|
+
}
|
|
13946
|
+
const preds = c.preds.map((p) => substPred2(p, paramName));
|
|
13947
|
+
if (c.prim && c.preds.length === 0) {
|
|
13948
|
+
return ptypeof(v(paramName), primToTypeof(c.prim));
|
|
13949
|
+
}
|
|
13950
|
+
return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
|
|
13951
|
+
}
|
|
13952
|
+
function instantiateOnTerm(c, t, depth = LAZY_TEMPLATE_DEPTH) {
|
|
13953
|
+
if (c.lazy) {
|
|
13954
|
+
if (depth <= 0) return pTrue;
|
|
13955
|
+
return instantiateOnTerm(derefConstraint(c), t, depth - 1);
|
|
13956
|
+
}
|
|
13957
|
+
const subst = (p) => {
|
|
13958
|
+
switch (p.op) {
|
|
13959
|
+
case "gt":
|
|
13960
|
+
case "ge":
|
|
13961
|
+
case "lt":
|
|
13962
|
+
case "le":
|
|
13963
|
+
case "eq":
|
|
13964
|
+
case "ne": {
|
|
13965
|
+
const a = p.a.op === "var" && p.a.id === SELF ? t : p.a;
|
|
13966
|
+
const b = p.b.op === "var" && p.b.id === SELF ? t : p.b;
|
|
13967
|
+
return { op: p.op, a, b };
|
|
13968
|
+
}
|
|
13969
|
+
case "typeof": {
|
|
13970
|
+
const tt = p.t.op === "var" && p.t.id === SELF ? t : p.t;
|
|
13971
|
+
return { op: "typeof", t: tt, type: p.type };
|
|
13972
|
+
}
|
|
13973
|
+
case "and":
|
|
13974
|
+
return and(...p.args.map(subst));
|
|
13975
|
+
default:
|
|
13976
|
+
return p;
|
|
13977
|
+
}
|
|
13978
|
+
};
|
|
13979
|
+
if (c.fields) {
|
|
13980
|
+
const parts = [];
|
|
13981
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
13982
|
+
if (field.optional || field.constraint.isOptional) continue;
|
|
13983
|
+
parts.push(instantiateOnTerm(field.constraint, getTerm(t, key), depth));
|
|
13984
|
+
}
|
|
13985
|
+
if (parts.length === 0) return { op: "true" };
|
|
13986
|
+
return parts.length === 1 ? parts[0] : and(...parts);
|
|
13987
|
+
}
|
|
13988
|
+
if (c.members) {
|
|
13989
|
+
const disj = or(...c.members.map((m) => instantiateOnTerm(m, t, depth)));
|
|
13990
|
+
const own = c.preds.map(subst);
|
|
13991
|
+
return own.length === 0 ? disj : and(...own, disj);
|
|
13992
|
+
}
|
|
13993
|
+
if (c.fn) {
|
|
13994
|
+
const own = c.preds.map(subst);
|
|
13995
|
+
return own.length === 0 ? pTrue : and(...own);
|
|
13996
|
+
}
|
|
13997
|
+
const preds = c.preds.map(subst);
|
|
13998
|
+
if (c.prim && c.preds.length === 0) return ptypeof(t, primToTypeof(c.prim));
|
|
13999
|
+
return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
|
|
14000
|
+
}
|
|
14001
|
+
function constraintToEntryAbs(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
|
|
14002
|
+
const t = v(paramName);
|
|
14003
|
+
if (c.fields) {
|
|
14004
|
+
const slots = {};
|
|
14005
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14006
|
+
if (field.constraint.lazy && depth <= 0) continue;
|
|
14007
|
+
const fieldTerm = getTerm(t, key);
|
|
14008
|
+
slots[key] = {
|
|
14009
|
+
value: constraintOnTermAbs(field.constraint, fieldTerm, depth),
|
|
14010
|
+
...field.optional || field.constraint.isOptional ? { optional: true } : {}
|
|
14011
|
+
};
|
|
14012
|
+
}
|
|
14013
|
+
return abs({ k: "obj", slots }, t, void 0, "path");
|
|
14014
|
+
}
|
|
14015
|
+
return constraintOnTermAbs(c, t, depth);
|
|
14016
|
+
}
|
|
14017
|
+
function memberLitValue(m) {
|
|
14018
|
+
const leaves = [];
|
|
14019
|
+
const visit = (p2) => {
|
|
14020
|
+
if (p2.op === "and") {
|
|
14021
|
+
p2.args.forEach(visit);
|
|
14022
|
+
return;
|
|
14023
|
+
}
|
|
14024
|
+
leaves.push(p2);
|
|
14025
|
+
};
|
|
14026
|
+
m.preds.forEach(visit);
|
|
14027
|
+
if (leaves.length !== 1) return { ok: false };
|
|
14028
|
+
const p = leaves[0];
|
|
14029
|
+
if (p.op !== "eq") return { ok: false };
|
|
14030
|
+
if (p.a.op === "var" && p.b.op === "lit") {
|
|
14031
|
+
return { ok: true, v: p.b.value };
|
|
14032
|
+
}
|
|
14033
|
+
if (p.b.op === "var" && p.a.op === "lit") {
|
|
14034
|
+
return { ok: true, v: p.a.value };
|
|
14035
|
+
}
|
|
14036
|
+
return { ok: false };
|
|
14037
|
+
}
|
|
14038
|
+
function samePrimLiteralUnionAbs(members, t) {
|
|
14039
|
+
if (members.length === 0) return void 0;
|
|
14040
|
+
const values = [];
|
|
14041
|
+
let prim;
|
|
14042
|
+
for (const m of members) {
|
|
14043
|
+
const mk = memberLitValue(m);
|
|
14044
|
+
if (!mk.ok) return void 0;
|
|
14045
|
+
const v2 = mk.v;
|
|
14046
|
+
if (v2 === void 0 || v2 === null) return void 0;
|
|
14047
|
+
const mp = m.prim ?? (typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : "boolean");
|
|
14048
|
+
if (prim === void 0) prim = mp;
|
|
14049
|
+
else if (prim !== mp) return void 0;
|
|
14050
|
+
values.push(v2);
|
|
14051
|
+
}
|
|
14052
|
+
if (prim === void 0) return void 0;
|
|
14053
|
+
const uniq = [];
|
|
14054
|
+
for (const v2 of values) {
|
|
14055
|
+
if (!uniq.some((u) => Object.is(u, v2))) uniq.push(v2);
|
|
14056
|
+
}
|
|
14057
|
+
const disj = or(
|
|
14058
|
+
...uniq.map((v2) => eq(t, lit(v2)))
|
|
14059
|
+
);
|
|
14060
|
+
return abs({ k: "prim", type: prim }, t, disj, "path");
|
|
14061
|
+
}
|
|
14062
|
+
function constraintOnTermAbs(c, t, depth) {
|
|
14063
|
+
if (c.lazy) {
|
|
14064
|
+
if (depth <= 0) return abs({ k: "any" }, t, void 0, "path");
|
|
14065
|
+
return constraintOnTermAbs(derefConstraint(c), t, depth - 1);
|
|
14066
|
+
}
|
|
14067
|
+
if (c.fields) {
|
|
14068
|
+
const slots = {};
|
|
14069
|
+
for (const [key, field] of Object.entries(c.fields)) {
|
|
14070
|
+
if (field.constraint.lazy && depth <= 0) continue;
|
|
14071
|
+
slots[key] = {
|
|
14072
|
+
value: constraintOnTermAbs(field.constraint, getTerm(t, key), depth),
|
|
14073
|
+
...field.optional || field.constraint.isOptional ? { optional: true } : {}
|
|
14074
|
+
};
|
|
14075
|
+
}
|
|
14076
|
+
return abs({ k: "obj", slots }, t, void 0, "path");
|
|
14077
|
+
}
|
|
14078
|
+
if (c.members) {
|
|
14079
|
+
const litUnion = samePrimLiteralUnionAbs(c.members, t);
|
|
14080
|
+
if (litUnion) return litUnion;
|
|
14081
|
+
const joined = c.members.map((m) => constraintOnTermAbs(m, t, depth)).reduce((a, b) => joinAbs(a, b));
|
|
14082
|
+
if (joined.shape.k === "prim" && joined.pred === void 0 && c.members.every((m) => m.prim === joined.shape.type)) {
|
|
14083
|
+
const type = joined.shape.type;
|
|
14084
|
+
return abs({ k: "prim", type }, t, ptypeof(t, primToTypeof(type)), "path");
|
|
14085
|
+
}
|
|
14086
|
+
return joined;
|
|
14087
|
+
}
|
|
14088
|
+
if (c.fn) {
|
|
14089
|
+
const paramNames = Object.keys(c.fn.params);
|
|
14090
|
+
const paramTypes = paramNames.map(
|
|
14091
|
+
(p, i) => constraintOnTermAbs(c.fn.params[p], v(`x${i}`), depth)
|
|
14092
|
+
);
|
|
14093
|
+
const returnType = c.fn.returns ? constraintOnTermAbs(c.fn.returns, v("ret"), depth) : unknown;
|
|
14094
|
+
return abs(
|
|
14095
|
+
{ k: "fn", params: paramNames, paramTypes, returnType },
|
|
14096
|
+
t,
|
|
14097
|
+
void 0,
|
|
14098
|
+
"path"
|
|
14099
|
+
);
|
|
14100
|
+
}
|
|
14101
|
+
if (c.element) {
|
|
14102
|
+
const elem = constraintOnTermAbs(c.element, v("x[]"), depth);
|
|
14103
|
+
return abs({ k: "arr", element: elem }, t, void 0, "path");
|
|
14104
|
+
}
|
|
14105
|
+
const pred = instantiateOnTerm(c, t, depth);
|
|
14106
|
+
const predOut = pred.op === "true" ? void 0 : pred;
|
|
14107
|
+
if (c.prim) {
|
|
14108
|
+
return abs({ k: "prim", type: c.prim }, t, predOut, "path");
|
|
14109
|
+
}
|
|
14110
|
+
const allEqNullish = c.preds.length > 0 && c.preds.every(
|
|
14111
|
+
(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))
|
|
14112
|
+
);
|
|
14113
|
+
if (allEqNullish) {
|
|
14114
|
+
let nullish = null;
|
|
14115
|
+
for (const p of c.preds) {
|
|
14116
|
+
if (p.op !== "eq") continue;
|
|
14117
|
+
if (p.b.op === "lit" && (p.b.value === null || p.b.value === void 0)) {
|
|
14118
|
+
nullish = p.b.value;
|
|
14119
|
+
break;
|
|
14120
|
+
}
|
|
14121
|
+
if (p.a.op === "lit" && (p.a.value === null || p.a.value === void 0)) {
|
|
14122
|
+
nullish = p.a.value;
|
|
14123
|
+
break;
|
|
14124
|
+
}
|
|
14125
|
+
}
|
|
14126
|
+
return abs({ k: "unknown" }, lit(nullish), void 0, "path");
|
|
14127
|
+
}
|
|
14128
|
+
if (c.preds.length > 0) {
|
|
14129
|
+
return abs({ k: "prim", type: "number" }, t, predOut, "path");
|
|
14130
|
+
}
|
|
14131
|
+
return abs({ k: "any" }, t, void 0, "path");
|
|
14132
|
+
}
|
|
14133
|
+
function fnConstraintToEntryReqs(c) {
|
|
14134
|
+
if (!c.fn) throw new Error("nudo fnConstraintToEntryReqs(): constraint is not in fn() form");
|
|
14135
|
+
return Object.entries(c.fn.params).map(([param, constraint]) => ({
|
|
14136
|
+
param,
|
|
14137
|
+
constraint
|
|
14138
|
+
}));
|
|
14139
|
+
}
|
|
14140
|
+
function throwConstraintToKinds(c) {
|
|
14141
|
+
if (!c) return void 0;
|
|
14142
|
+
const out = /* @__PURE__ */ new Set();
|
|
14143
|
+
let any2 = false;
|
|
14144
|
+
const seen = /* @__PURE__ */ new Set();
|
|
14145
|
+
const note2 = (s) => {
|
|
14146
|
+
if (s === "*" || s === "any") any2 = true;
|
|
14147
|
+
else if (s) out.add(s);
|
|
14148
|
+
};
|
|
14149
|
+
const walk = (x) => {
|
|
14150
|
+
if (x.lazy) {
|
|
14151
|
+
if (seen.has(x.lazy)) return;
|
|
14152
|
+
seen.add(x.lazy);
|
|
14153
|
+
walk(derefConstraint(x));
|
|
14154
|
+
return;
|
|
14155
|
+
}
|
|
14156
|
+
if (x.members) {
|
|
14157
|
+
for (const m of x.members) walk(m);
|
|
14158
|
+
return;
|
|
14159
|
+
}
|
|
14160
|
+
for (const p of x.preds) {
|
|
14161
|
+
if (p.op !== "eq" && p.op !== "ne") continue;
|
|
14162
|
+
for (const side of [p.a, p.b]) {
|
|
14163
|
+
if (side.op === "lit" && typeof side.value === "string") note2(side.value);
|
|
14164
|
+
}
|
|
14165
|
+
}
|
|
14166
|
+
};
|
|
14167
|
+
walk(c);
|
|
14168
|
+
if (any2) return "*";
|
|
14169
|
+
if (out.size > 0) return [...out];
|
|
14170
|
+
return void 0;
|
|
14171
|
+
}
|
|
14172
|
+
|
|
14173
|
+
// src/algebra/domain-membership.ts
|
|
14174
|
+
function literalMeetsConstraint(lv, c, seen) {
|
|
14175
|
+
if (c.lazy) {
|
|
14176
|
+
const s = seen ?? /* @__PURE__ */ new Set();
|
|
14177
|
+
if (s.has(c.lazy)) return false;
|
|
14178
|
+
s.add(c.lazy);
|
|
14179
|
+
return literalMeetsConstraint(lv, derefConstraint(c), s);
|
|
14180
|
+
}
|
|
14181
|
+
const ext = c;
|
|
14182
|
+
if (c.fields || c.element) return false;
|
|
14183
|
+
if (ext.fn) return false;
|
|
14184
|
+
if (Array.isArray(ext.members) && ext.members.length > 0) {
|
|
14185
|
+
return ext.members.some((m) => literalMeetsConstraint(lv, m, seen));
|
|
14186
|
+
}
|
|
14187
|
+
if (c.prim === void 0) {
|
|
14188
|
+
return c.preds.every((p) => predHolds(lv, p));
|
|
14189
|
+
}
|
|
14190
|
+
if (!primMatches(c.prim, lv)) return false;
|
|
14191
|
+
if (isIntFlag(c) && c.prim === "number" && !(typeof lv === "number" && Number.isInteger(lv))) {
|
|
14192
|
+
return false;
|
|
14193
|
+
}
|
|
14194
|
+
return c.preds.every((p) => predHolds(lv, p));
|
|
14195
|
+
}
|
|
14196
|
+
function primMatches(prim, lv) {
|
|
14197
|
+
switch (prim) {
|
|
14198
|
+
case "number":
|
|
14199
|
+
return typeof lv === "number";
|
|
14200
|
+
case "string":
|
|
14201
|
+
return typeof lv === "string";
|
|
14202
|
+
case "boolean":
|
|
14203
|
+
return typeof lv === "boolean";
|
|
14204
|
+
case "object":
|
|
14205
|
+
return lv === null;
|
|
14206
|
+
case "undefined":
|
|
14207
|
+
return lv === void 0;
|
|
14208
|
+
default:
|
|
14209
|
+
return false;
|
|
14210
|
+
}
|
|
14211
|
+
}
|
|
14212
|
+
function predHolds(lv, p) {
|
|
14213
|
+
switch (p.op) {
|
|
14214
|
+
case "eq": {
|
|
14215
|
+
const litT = isSelfVar(p.a) && p.b.op === "lit" ? p.b : isSelfVar(p.b) && p.a.op === "lit" ? p.a : void 0;
|
|
14216
|
+
if (!litT) return false;
|
|
14217
|
+
return Object.is(lv, litT.value);
|
|
14218
|
+
}
|
|
14219
|
+
case "gt":
|
|
14220
|
+
case "ge":
|
|
14221
|
+
case "lt":
|
|
14222
|
+
case "le":
|
|
14223
|
+
return boundHolds(lv, p);
|
|
14224
|
+
case "typeof":
|
|
14225
|
+
return p.t.op === "var" && p.t.id === SELF && primMatches(p.type, lv);
|
|
14226
|
+
// and 是合取:逐参数按同一规则判定(string().length(n) 的 preds 是
|
|
14227
|
+
// and 包裹的两个长度界,叶子仍是 gt/ge/lt/le,无假阳性风险)
|
|
14228
|
+
case "and":
|
|
14229
|
+
return p.args.every((x) => predHolds(lv, x));
|
|
14230
|
+
// ne / or / not / true / false 等其余形态:保守不满足
|
|
14231
|
+
default:
|
|
14232
|
+
return false;
|
|
14233
|
+
}
|
|
14234
|
+
}
|
|
14235
|
+
function cmpHolds(x, op, n) {
|
|
14236
|
+
switch (op) {
|
|
14237
|
+
case "gt":
|
|
14238
|
+
return x > n;
|
|
14239
|
+
case "ge":
|
|
14240
|
+
return x >= n;
|
|
14241
|
+
case "lt":
|
|
14242
|
+
return x < n;
|
|
14243
|
+
case "le":
|
|
14244
|
+
return x <= n;
|
|
14245
|
+
}
|
|
14246
|
+
}
|
|
14247
|
+
function boundHolds(lv, p) {
|
|
14248
|
+
if (p.b.op !== "lit" || typeof p.b.value !== "number") return false;
|
|
14249
|
+
const n = p.b.value;
|
|
14250
|
+
if (isLengthSelf(p.a)) {
|
|
14251
|
+
return typeof lv === "string" && cmpHolds(lv.length, p.op, n);
|
|
14252
|
+
}
|
|
14253
|
+
if (isSelfVar(p.a)) {
|
|
14254
|
+
return typeof lv === "number" && cmpHolds(lv, p.op, n);
|
|
14255
|
+
}
|
|
14256
|
+
return false;
|
|
14257
|
+
}
|
|
14258
|
+
function isSelfVar(t) {
|
|
14259
|
+
return t.op === "var" && t.id === SELF;
|
|
14260
|
+
}
|
|
14261
|
+
function isLengthSelf(t) {
|
|
14262
|
+
return t.op === "app" && t.fn === "length" && t.args.length === 1 && isSelfVar(t.args[0]);
|
|
14263
|
+
}
|
|
14264
|
+
|
|
14265
|
+
// src/algebra/contract-face.ts
|
|
14266
|
+
var facesByFn = /* @__PURE__ */ new WeakMap();
|
|
14267
|
+
function attachContractFaces(fnObj, faces) {
|
|
14268
|
+
facesByFn.set(fnObj, faces);
|
|
14269
|
+
}
|
|
14270
|
+
function contractFacesOf(fnObj) {
|
|
14271
|
+
if (!fnObj || typeof fnObj !== "object" && typeof fnObj !== "function") {
|
|
14272
|
+
return void 0;
|
|
14273
|
+
}
|
|
14274
|
+
return facesByFn.get(fnObj);
|
|
14275
|
+
}
|
|
14276
|
+
var contractFaceResolverSlot = createScopedSlot(
|
|
14277
|
+
() => null
|
|
14278
|
+
);
|
|
14279
|
+
registerCollectorScopeParticipant(
|
|
14280
|
+
(body) => contractFaceResolverSlot.runScoped(body)
|
|
14281
|
+
);
|
|
14282
|
+
function setContractFaceResolver(resolver) {
|
|
14283
|
+
const prev = contractFaceResolverSlot.get();
|
|
14284
|
+
contractFaceResolverSlot.set(resolver);
|
|
14285
|
+
return prev;
|
|
14286
|
+
}
|
|
14287
|
+
function resolveContractFacesByName(fnName) {
|
|
14288
|
+
const resolver = contractFaceResolverSlot.get();
|
|
14289
|
+
return resolver ? resolver(fnName) : void 0;
|
|
14290
|
+
}
|
|
14291
|
+
function argLacksInformation(a) {
|
|
14292
|
+
if (!a || typeof a !== "object" || !("shape" in a)) return false;
|
|
14293
|
+
const k = a.shape?.k;
|
|
14294
|
+
if (k === "any") return true;
|
|
14295
|
+
if (k === "unknown") return a.term?.op !== "lit";
|
|
14296
|
+
return false;
|
|
14297
|
+
}
|
|
14298
|
+
function adoptCallArgsToFaces(args, faces) {
|
|
14299
|
+
const n = Math.min(args.length, faces.paramFaces.length);
|
|
14300
|
+
let changed = false;
|
|
14301
|
+
const out = args.slice();
|
|
14302
|
+
for (let i = 0; i < n; i++) {
|
|
14303
|
+
const face = faces.paramFaces[i];
|
|
14304
|
+
if (!face || !argLacksInformation(args[i])) continue;
|
|
14305
|
+
out[i] = face;
|
|
14306
|
+
changed = true;
|
|
14307
|
+
}
|
|
14308
|
+
return changed ? out : args;
|
|
14309
|
+
}
|
|
14310
|
+
function litMeetsReturnConstraint(r, c) {
|
|
14311
|
+
if (!c) return false;
|
|
14312
|
+
const lv = litValue(r);
|
|
14313
|
+
if (!lv.ok) return false;
|
|
14314
|
+
const v2 = lv.value;
|
|
14315
|
+
if (typeof v2 !== "number" && typeof v2 !== "string" && typeof v2 !== "boolean" && v2 !== null && v2 !== void 0) {
|
|
14316
|
+
return false;
|
|
14317
|
+
}
|
|
14318
|
+
return literalMeetsConstraint(v2, c);
|
|
14319
|
+
}
|
|
14320
|
+
function presentCallResultFace(r, faces) {
|
|
14321
|
+
const face = faces.returns;
|
|
14322
|
+
if (!face || !r || typeof r !== "object" || !r.shape) return r;
|
|
14323
|
+
if (r.shape.k === "never") return r;
|
|
14324
|
+
if (r.conf === "opaque") return r;
|
|
14325
|
+
if (litMeetsReturnConstraint(r, faces.returnsConstraint)) return r;
|
|
14326
|
+
if (leqAbs(r, face).ok) return r;
|
|
14327
|
+
return face;
|
|
14328
|
+
}
|
|
14329
|
+
function contractFacesFromEffectiveInterface(eff, paramNames) {
|
|
14330
|
+
if (eff.source !== "handwritten") return void 0;
|
|
14331
|
+
const conflictParams = eff.conflict?.params ?? [];
|
|
14332
|
+
const paramFaces = [];
|
|
14333
|
+
let hasFace = false;
|
|
14334
|
+
for (const e of eff.params) {
|
|
14335
|
+
const idx = paramNames.indexOf(e.param);
|
|
14336
|
+
if (idx < 0 || conflictParams.includes(e.param)) continue;
|
|
14337
|
+
paramFaces[idx] = constraintToEntryAbs(e.constraint, e.param);
|
|
14338
|
+
hasFace = true;
|
|
14339
|
+
}
|
|
14340
|
+
let returns;
|
|
14341
|
+
let returnsConstraint;
|
|
14342
|
+
if (eff.returns && !eff.conflict?.returns) {
|
|
14343
|
+
returns = constraintToEntryAbs(eff.returns.constraint, "return");
|
|
14344
|
+
returnsConstraint = eff.returns.constraint;
|
|
14345
|
+
hasFace = true;
|
|
14346
|
+
}
|
|
14347
|
+
return hasFace ? {
|
|
14348
|
+
paramFaces,
|
|
14349
|
+
...returns !== void 0 ? { returns } : {},
|
|
14350
|
+
...returnsConstraint !== void 0 ? { returnsConstraint } : {}
|
|
14351
|
+
} : void 0;
|
|
14352
|
+
}
|
|
14353
|
+
|
|
13442
14354
|
// src/algebra/exec/calls.ts
|
|
13443
14355
|
var PURE_CALL_MEMO_MAX = 256;
|
|
13444
14356
|
var pureCallMemo = /* @__PURE__ */ new WeakMap();
|
|
@@ -13525,16 +14437,16 @@ var NEVER_EXEC_HOST_FN_NAMES = [
|
|
|
13525
14437
|
"requestAnimationFrame",
|
|
13526
14438
|
"requestIdleCallback"
|
|
13527
14439
|
];
|
|
13528
|
-
function neverExecHostName(
|
|
13529
|
-
if (typeof
|
|
14440
|
+
function neverExecHostName(fn2) {
|
|
14441
|
+
if (typeof fn2 !== "function") return null;
|
|
13530
14442
|
const g = globalThis;
|
|
13531
14443
|
for (const n of NEVER_EXEC_HOST_FN_NAMES) {
|
|
13532
|
-
if (
|
|
14444
|
+
if (fn2 === g[n]) return n;
|
|
13533
14445
|
}
|
|
13534
14446
|
return null;
|
|
13535
14447
|
}
|
|
13536
|
-
function blockHostSideEffect(
|
|
13537
|
-
const hostName = neverExecHostName(
|
|
14448
|
+
function blockHostSideEffect(fn2) {
|
|
14449
|
+
const hostName = neverExecHostName(fn2);
|
|
13538
14450
|
if (hostName === null) return null;
|
|
13539
14451
|
noteHostEffectBlocked(hostName);
|
|
13540
14452
|
return abs({ k: "unknown" }, void 0, void 0, "opaque");
|
|
@@ -13556,8 +14468,8 @@ function getEvalCallCollector() {
|
|
|
13556
14468
|
return evalCallCollectorSlot.get();
|
|
13557
14469
|
}
|
|
13558
14470
|
var hostGlobalFnIds;
|
|
13559
|
-
function isHostGlobalFn(
|
|
13560
|
-
if (typeof
|
|
14471
|
+
function isHostGlobalFn(fn2) {
|
|
14472
|
+
if (typeof fn2 !== "function") return false;
|
|
13561
14473
|
if (!hostGlobalFnIds) {
|
|
13562
14474
|
hostGlobalFnIds = /* @__PURE__ */ new Set();
|
|
13563
14475
|
const g = globalThis;
|
|
@@ -13566,9 +14478,9 @@ function isHostGlobalFn(fn) {
|
|
|
13566
14478
|
if (typeof v2 === "function") hostGlobalFnIds.add(v2);
|
|
13567
14479
|
}
|
|
13568
14480
|
}
|
|
13569
|
-
return hostGlobalFnIds.has(
|
|
14481
|
+
return hostGlobalFnIds.has(fn2);
|
|
13570
14482
|
}
|
|
13571
|
-
function callHostGlobalLiteralOnly(name,
|
|
14483
|
+
function callHostGlobalLiteralOnly(name, fn2, args) {
|
|
13572
14484
|
const jsArgs = [];
|
|
13573
14485
|
for (const a of args) {
|
|
13574
14486
|
if (a && typeof a === "object" && "shape" in a) {
|
|
@@ -13589,7 +14501,7 @@ function callHostGlobalLiteralOnly(name, fn, args) {
|
|
|
13589
14501
|
}
|
|
13590
14502
|
}
|
|
13591
14503
|
try {
|
|
13592
|
-
return asAbsVal(
|
|
14504
|
+
return asAbsVal(fn2(...jsArgs));
|
|
13593
14505
|
} catch (e) {
|
|
13594
14506
|
throw new NudoThrow(throwPayloadOf(e));
|
|
13595
14507
|
}
|
|
@@ -13662,12 +14574,12 @@ function getEvalCallBudgetState() {
|
|
|
13662
14574
|
function evalTruncatedAbs() {
|
|
13663
14575
|
return abs({ k: "unknown" }, void 0, void 0, "opaque");
|
|
13664
14576
|
}
|
|
13665
|
-
function evalCallBudgetKey(name,
|
|
13666
|
-
const id =
|
|
14577
|
+
function evalCallBudgetKey(name, fn2, args) {
|
|
14578
|
+
const id = fn2 && typeof fn2 === "object" ? evalStableId(fn2) : "prim";
|
|
13667
14579
|
return callBudgetKey(name, id, args);
|
|
13668
14580
|
}
|
|
13669
|
-
function evalEnterCall(name,
|
|
13670
|
-
const key = evalCallBudgetKey(name,
|
|
14581
|
+
function evalEnterCall(name, fn2, args) {
|
|
14582
|
+
const key = evalCallBudgetKey(name, fn2, args);
|
|
13671
14583
|
if (evalActiveCallKeys.includes(key) || evalCallDepth >= evalCallDepthLimit || evalTotalCalls >= evalTotalCallsLimit) {
|
|
13672
14584
|
noteAbsTruncation(name);
|
|
13673
14585
|
return { ok: false };
|
|
@@ -13681,13 +14593,19 @@ function evalExitCall() {
|
|
|
13681
14593
|
if (evalCallDepth > 0) evalCallDepth--;
|
|
13682
14594
|
if (evalActiveCallKeys.length > 0) evalActiveCallKeys.pop();
|
|
13683
14595
|
}
|
|
13684
|
-
function $callNamed(name,
|
|
13685
|
-
const
|
|
13686
|
-
const fnObj =
|
|
13687
|
-
|
|
14596
|
+
function $callNamed(name, fn2, args, loc, argLocs) {
|
|
14597
|
+
const faces = resolveContractFacesByName(name) ?? contractFacesOf(fn2);
|
|
14598
|
+
const fnObj = fn2 && (typeof fn2 === "object" || typeof fn2 === "function") ? fn2 : void 0;
|
|
14599
|
+
if (faces && fnObj) attachContractFaces(fnObj, faces);
|
|
14600
|
+
const execArgs = faces ? adoptCallArgsToFaces(args, faces) : args;
|
|
14601
|
+
const pureName = pureFnNameOf(fn2);
|
|
14602
|
+
const pk = pureName && fnObj ? callBudgetKey("pure", "", execArgs) : void 0;
|
|
13688
14603
|
if (fnObj && pk !== void 0) {
|
|
13689
14604
|
const hit = pureCallMemo.get(fnObj)?.get(pk);
|
|
13690
|
-
if (hit !== void 0)
|
|
14605
|
+
if (hit !== void 0) {
|
|
14606
|
+
const routed = routeApplyThrows(hit.abs, hit.throws);
|
|
14607
|
+
return faces ? presentCallResultFace(routed, faces) : routed;
|
|
14608
|
+
}
|
|
13691
14609
|
}
|
|
13692
14610
|
let result = unknown;
|
|
13693
14611
|
let threw = false;
|
|
@@ -13703,42 +14621,42 @@ function $callNamed(name, fn, args, loc, argLocs) {
|
|
|
13703
14621
|
);
|
|
13704
14622
|
if (loc) pushCallLoc({ line: loc[0], column: loc[1] });
|
|
13705
14623
|
try {
|
|
13706
|
-
if (typeof
|
|
14624
|
+
if (typeof fn2 === "function") {
|
|
13707
14625
|
let g;
|
|
13708
|
-
if (GLOBAL_FNS.has(name) &&
|
|
14626
|
+
if (GLOBAL_FNS.has(name) && fn2 === globalThis[name]) {
|
|
13709
14627
|
g = evalGlobalFn(name, args);
|
|
13710
14628
|
} else {
|
|
13711
|
-
const ctorName = hostBuiltinCtorName(
|
|
14629
|
+
const ctorName = hostBuiltinCtorName(fn2);
|
|
13712
14630
|
if (ctorName !== void 0) {
|
|
13713
14631
|
g = evalGlobalFn(ctorName, args);
|
|
13714
14632
|
}
|
|
13715
14633
|
}
|
|
13716
|
-
const blockedHost = g === void 0 ? blockHostSideEffect(
|
|
14634
|
+
const blockedHost = g === void 0 ? blockHostSideEffect(fn2) : null;
|
|
13717
14635
|
if (g !== void 0) {
|
|
13718
14636
|
result = g;
|
|
13719
14637
|
} else if (blockedHost !== null) {
|
|
13720
14638
|
result = blockedHost;
|
|
13721
|
-
} else if (isHostGlobalFn(
|
|
13722
|
-
result = callHostGlobalLiteralOnly(name,
|
|
14639
|
+
} else if (isHostGlobalFn(fn2)) {
|
|
14640
|
+
result = callHostGlobalLiteralOnly(name, fn2, args);
|
|
13723
14641
|
} else {
|
|
13724
|
-
const entered = evalEnterCall(name,
|
|
14642
|
+
const entered = evalEnterCall(name, fn2, execArgs);
|
|
13725
14643
|
if (!entered.ok) {
|
|
13726
14644
|
result = evalTruncatedAbs();
|
|
13727
14645
|
} else {
|
|
13728
14646
|
try {
|
|
13729
|
-
result = callAtFunctionBoundary(() =>
|
|
14647
|
+
result = callAtFunctionBoundary(() => fn2(...execArgs));
|
|
13730
14648
|
} finally {
|
|
13731
14649
|
evalExitCall();
|
|
13732
14650
|
}
|
|
13733
14651
|
}
|
|
13734
14652
|
}
|
|
13735
|
-
} else if (
|
|
13736
|
-
const entered = evalEnterCall(name,
|
|
14653
|
+
} else if (fn2 && typeof fn2 === "object" && "shape" in fn2) {
|
|
14654
|
+
const entered = evalEnterCall(name, fn2, execArgs);
|
|
13737
14655
|
if (!entered.ok) {
|
|
13738
14656
|
result = evalTruncatedAbs();
|
|
13739
14657
|
} else {
|
|
13740
14658
|
try {
|
|
13741
|
-
result = $call(
|
|
14659
|
+
result = $call(fn2, execArgs);
|
|
13742
14660
|
} finally {
|
|
13743
14661
|
evalExitCall();
|
|
13744
14662
|
}
|
|
@@ -13772,7 +14690,7 @@ function $callNamed(name, fn, args, loc, argLocs) {
|
|
|
13772
14690
|
}
|
|
13773
14691
|
}
|
|
13774
14692
|
}
|
|
13775
|
-
return result;
|
|
14693
|
+
return faces ? presentCallResultFace(result, faces) : result;
|
|
13776
14694
|
}
|
|
13777
14695
|
|
|
13778
14696
|
// src/algebra/methods.ts
|
|
@@ -14842,8 +15760,8 @@ function $new(cls, args) {
|
|
|
14842
15760
|
popCtorFrame();
|
|
14843
15761
|
}
|
|
14844
15762
|
}
|
|
14845
|
-
const
|
|
14846
|
-
return abs({ k: "brand", name: clsName, shape }, void 0, void 0, "path");
|
|
15763
|
+
const shape2 = objOf({});
|
|
15764
|
+
return abs({ k: "brand", name: clsName, shape: shape2 }, void 0, void 0, "path");
|
|
14847
15765
|
}
|
|
14848
15766
|
const spec = specOf(cls);
|
|
14849
15767
|
if (!spec) {
|
|
@@ -15119,12 +16037,12 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15119
16037
|
return ["_rest"];
|
|
15120
16038
|
};
|
|
15121
16039
|
if (typeof thisVal === "function") {
|
|
15122
|
-
const
|
|
16040
|
+
const fn2 = thisVal;
|
|
15123
16041
|
if (method === "call") {
|
|
15124
|
-
return callAtFunctionBoundary(() =>
|
|
16042
|
+
return callAtFunctionBoundary(() => fn2.apply(args[0], args.slice(1)));
|
|
15125
16043
|
}
|
|
15126
16044
|
if (method === "apply") {
|
|
15127
|
-
return callAtFunctionBoundary(() =>
|
|
16045
|
+
return callAtFunctionBoundary(() => fn2.apply(args[0], expandApplyArgs(args[1])));
|
|
15128
16046
|
}
|
|
15129
16047
|
const boundThis = args[0];
|
|
15130
16048
|
const bound = args.slice(1);
|
|
@@ -15132,7 +16050,7 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15132
16050
|
return absFunction(
|
|
15133
16051
|
boundFnParams(thisVal, bound.length),
|
|
15134
16052
|
{
|
|
15135
|
-
apply: (callArgs) => callAtFunctionBoundary(() =>
|
|
16053
|
+
apply: (callArgs) => callAtFunctionBoundary(() => fn2.apply(boundThis, [...bound, ...callArgs]))
|
|
15136
16054
|
},
|
|
15137
16055
|
hostFacet !== void 0 ? { ctor: hostFacet } : void 0
|
|
15138
16056
|
);
|
|
@@ -15386,9 +16304,9 @@ function $invokeInner(thisVal, method, args, loc) {
|
|
|
15386
16304
|
noteUnknownMemberMissing(thisVal, method, "method", loc);
|
|
15387
16305
|
return unknown;
|
|
15388
16306
|
}
|
|
15389
|
-
function refineFnReturnType(
|
|
15390
|
-
if (!
|
|
15391
|
-
const s =
|
|
16307
|
+
function refineFnReturnType(fn2, result) {
|
|
16308
|
+
if (!fn2 || typeof fn2 !== "object" || !("shape" in fn2)) return;
|
|
16309
|
+
const s = fn2.shape;
|
|
15392
16310
|
if (s.k !== "fn") return;
|
|
15393
16311
|
if (s.returnType === void 0) {
|
|
15394
16312
|
s.returnType = result;
|
|
@@ -15408,8 +16326,8 @@ function memberLikelyHasMethod(m, method) {
|
|
|
15408
16326
|
return false;
|
|
15409
16327
|
}
|
|
15410
16328
|
function invokeArrMethod(arr, method, args) {
|
|
15411
|
-
const
|
|
15412
|
-
const holes =
|
|
16329
|
+
const shape2 = arr.shape;
|
|
16330
|
+
const holes = shape2.k === "tuple" ? arr.shape.holes ?? [] : [];
|
|
15413
16331
|
const isHole = (i) => holes.includes(i);
|
|
15414
16332
|
const unknownIdx = () => abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
15415
16333
|
const callbackTruth = (r) => {
|
|
@@ -15420,7 +16338,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15420
16338
|
if (typeof v2 === "number" && (v2 === 0 || Number.isNaN(v2))) return false;
|
|
15421
16339
|
return true;
|
|
15422
16340
|
};
|
|
15423
|
-
const callFn = (
|
|
16341
|
+
const callFn = (fn2, ...fnArgs) => {
|
|
15424
16342
|
const sumIdx = fnArgs.findIndex(
|
|
15425
16343
|
(a) => a && typeof a === "object" && "shape" in a && a.shape.k === "sum"
|
|
15426
16344
|
);
|
|
@@ -15429,24 +16347,24 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15429
16347
|
let acc;
|
|
15430
16348
|
for (const m of members) {
|
|
15431
16349
|
const next = fnArgs.map((a, i) => i === sumIdx ? m : a);
|
|
15432
|
-
const r = callFn(
|
|
16350
|
+
const r = callFn(fn2, ...next);
|
|
15433
16351
|
acc = acc === void 0 ? r : joinAbs(acc, r);
|
|
15434
16352
|
}
|
|
15435
16353
|
return acc ?? unknown;
|
|
15436
16354
|
}
|
|
15437
|
-
if (typeof
|
|
15438
|
-
const r = callAtFunctionBoundary(() =>
|
|
16355
|
+
if (typeof fn2 === "function") {
|
|
16356
|
+
const r = callAtFunctionBoundary(() => fn2(...fnArgs));
|
|
15439
16357
|
if (r && typeof r === "object" && "shape" in r) return r;
|
|
15440
16358
|
return unknown;
|
|
15441
16359
|
}
|
|
15442
|
-
const absFn = asAbs(
|
|
16360
|
+
const absFn = asAbs(fn2);
|
|
15443
16361
|
if (absFn) {
|
|
15444
16362
|
return applyCallbackAbs(absFn, fnArgs, emptyEnv(), pTrue, defaultLeakBudget);
|
|
15445
16363
|
}
|
|
15446
16364
|
return unknown;
|
|
15447
16365
|
};
|
|
15448
|
-
const isRelationOnly = (
|
|
15449
|
-
const a = asAbs(
|
|
16366
|
+
const isRelationOnly = (fn2) => {
|
|
16367
|
+
const a = asAbs(fn2);
|
|
15450
16368
|
if (!a) return false;
|
|
15451
16369
|
const impl = getFnImpl(a);
|
|
15452
16370
|
if (impl?.body || impl?.apply) return false;
|
|
@@ -15454,8 +16372,8 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15454
16372
|
};
|
|
15455
16373
|
if (method === "map") {
|
|
15456
16374
|
validateCallableArg(args[0], "map callback may not be callable");
|
|
15457
|
-
if (
|
|
15458
|
-
const mapped =
|
|
16375
|
+
if (shape2.k === "tuple") {
|
|
16376
|
+
const mapped = shape2.elements.map(
|
|
15459
16377
|
(el2, i) => isHole(i) ? el2 : callFn(args[0], el2, $lit(i), arr)
|
|
15460
16378
|
);
|
|
15461
16379
|
return abs(
|
|
@@ -15465,70 +16383,70 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15465
16383
|
"path"
|
|
15466
16384
|
);
|
|
15467
16385
|
}
|
|
15468
|
-
const out = callFn(args[0],
|
|
15469
|
-
const el = mapElementFallback(asAbs(args[0]),
|
|
16386
|
+
const out = callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
16387
|
+
const el = mapElementFallback(asAbs(args[0]), shape2.element, out);
|
|
15470
16388
|
const conf = el === out ? confJoin(arr.conf, out.conf) : "partial";
|
|
15471
16389
|
return abs({ k: "arr", element: el }, void 0, void 0, conf);
|
|
15472
16390
|
}
|
|
15473
16391
|
if (method === "reduce") {
|
|
15474
16392
|
validateCallableArg(args[0], "reduce callback may not be callable");
|
|
15475
|
-
const
|
|
16393
|
+
const fn2 = args[0];
|
|
15476
16394
|
const noInitial = args.length < 2;
|
|
15477
16395
|
let acc = args[1] ?? unknown;
|
|
15478
|
-
if (noInitial &&
|
|
16396
|
+
if (noInitial && shape2.k === "arr") {
|
|
15479
16397
|
recordMayThrow({
|
|
15480
16398
|
kind: "TypeError",
|
|
15481
16399
|
cause: "reduce of possibly-empty array with no initial value"
|
|
15482
16400
|
});
|
|
15483
16401
|
}
|
|
15484
|
-
if (isRelationOnly(
|
|
15485
|
-
const d = instantiateReturn(
|
|
16402
|
+
if (isRelationOnly(fn2) && shape2.k === "arr") {
|
|
16403
|
+
const d = instantiateReturn(fn2, [acc, shape2.element]);
|
|
15486
16404
|
return joinAbs(acc, d);
|
|
15487
16405
|
}
|
|
15488
|
-
if (
|
|
16406
|
+
if (shape2.k === "tuple") {
|
|
15489
16407
|
if (noInitial) {
|
|
15490
|
-
const firstIdx =
|
|
16408
|
+
const firstIdx = shape2.elements.findIndex((_, i) => !isHole(i));
|
|
15491
16409
|
if (firstIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
15492
|
-
let acc2 =
|
|
15493
|
-
for (let i = firstIdx + 1; i <
|
|
16410
|
+
let acc2 = shape2.elements[firstIdx];
|
|
16411
|
+
for (let i = firstIdx + 1; i < shape2.elements.length; i++) {
|
|
15494
16412
|
if (isHole(i)) continue;
|
|
15495
|
-
acc2 = callFn(
|
|
16413
|
+
acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
|
|
15496
16414
|
}
|
|
15497
16415
|
return acc2;
|
|
15498
16416
|
}
|
|
15499
|
-
for (let i = 0; i <
|
|
16417
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
15500
16418
|
if (isHole(i)) continue;
|
|
15501
|
-
acc = callFn(
|
|
16419
|
+
acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
|
|
15502
16420
|
}
|
|
15503
16421
|
return acc;
|
|
15504
16422
|
}
|
|
15505
|
-
return callFn(
|
|
16423
|
+
return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
|
|
15506
16424
|
}
|
|
15507
16425
|
if (method === "reduceRight") {
|
|
15508
16426
|
validateCallableArg(args[0], "reduceRight callback may not be callable");
|
|
15509
|
-
const
|
|
16427
|
+
const fn2 = args[0];
|
|
15510
16428
|
const noInitial = args.length < 2;
|
|
15511
16429
|
let acc = args[1] ?? unknown;
|
|
15512
|
-
if (
|
|
16430
|
+
if (shape2.k === "tuple") {
|
|
15513
16431
|
if (noInitial) {
|
|
15514
16432
|
let lastIdx = -1;
|
|
15515
|
-
for (let i =
|
|
16433
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
15516
16434
|
if (!isHole(i)) {
|
|
15517
16435
|
lastIdx = i;
|
|
15518
16436
|
break;
|
|
15519
16437
|
}
|
|
15520
16438
|
}
|
|
15521
16439
|
if (lastIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
15522
|
-
let acc2 =
|
|
16440
|
+
let acc2 = shape2.elements[lastIdx];
|
|
15523
16441
|
for (let i = lastIdx - 1; i >= 0; i--) {
|
|
15524
16442
|
if (isHole(i)) continue;
|
|
15525
|
-
acc2 = callFn(
|
|
16443
|
+
acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
|
|
15526
16444
|
}
|
|
15527
16445
|
return acc2;
|
|
15528
16446
|
}
|
|
15529
|
-
for (let i =
|
|
16447
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
15530
16448
|
if (isHole(i)) continue;
|
|
15531
|
-
acc = callFn(
|
|
16449
|
+
acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
|
|
15532
16450
|
}
|
|
15533
16451
|
return acc;
|
|
15534
16452
|
}
|
|
@@ -15538,14 +16456,14 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15538
16456
|
cause: "reduceRight of possibly-empty array with no initial value"
|
|
15539
16457
|
});
|
|
15540
16458
|
}
|
|
15541
|
-
return callFn(
|
|
16459
|
+
return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
|
|
15542
16460
|
}
|
|
15543
16461
|
if (method === "filter") {
|
|
15544
16462
|
validateCallableArg(args[0], "filter callback may not be callable");
|
|
15545
|
-
if (
|
|
16463
|
+
if (shape2.k === "tuple") {
|
|
15546
16464
|
const kept = [];
|
|
15547
16465
|
let anyUncertain = false;
|
|
15548
|
-
|
|
16466
|
+
shape2.elements.forEach((el2, i) => {
|
|
15549
16467
|
if (isHole(i)) return;
|
|
15550
16468
|
const p = callFn(args[0], el2, $lit(i), arr);
|
|
15551
16469
|
const t = callbackTruth(p);
|
|
@@ -15577,33 +16495,33 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15577
16495
|
}
|
|
15578
16496
|
if (method === "flatMap") {
|
|
15579
16497
|
validateCallableArg(args[0], "flatMap callback may not be callable");
|
|
15580
|
-
if (
|
|
15581
|
-
const mapped =
|
|
16498
|
+
if (shape2.k === "tuple") {
|
|
16499
|
+
const mapped = shape2.elements.map(
|
|
15582
16500
|
(el, i) => isHole(i) ? abs({ k: "tuple", elements: [] }, void 0, void 0, "exact") : callFn(args[0], el, $lit(i), arr)
|
|
15583
16501
|
);
|
|
15584
16502
|
return projectFlatMapResult(arr.conf, mapped);
|
|
15585
16503
|
}
|
|
15586
|
-
const out = callFn(args[0],
|
|
16504
|
+
const out = callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
15587
16505
|
return projectFlatMapResult(arr.conf, [out]);
|
|
15588
16506
|
}
|
|
15589
16507
|
if (method === "forEach") {
|
|
15590
16508
|
validateCallableArg(args[0], "forEach callback may not be callable");
|
|
15591
|
-
if (
|
|
15592
|
-
|
|
16509
|
+
if (shape2.k === "tuple") {
|
|
16510
|
+
shape2.elements.forEach((el, i) => {
|
|
15593
16511
|
if (!isHole(i)) callFn(args[0], el, $lit(i), arr);
|
|
15594
16512
|
});
|
|
15595
16513
|
} else {
|
|
15596
|
-
callFn(args[0],
|
|
16514
|
+
callFn(args[0], shape2.element, unknownIdx(), arr);
|
|
15597
16515
|
}
|
|
15598
16516
|
return undefAbs();
|
|
15599
16517
|
}
|
|
15600
16518
|
if (method === "some" || method === "every") {
|
|
15601
16519
|
validateCallableArg(args[0], `${method} callback may not be callable`);
|
|
15602
16520
|
let undecided = false;
|
|
15603
|
-
if (
|
|
15604
|
-
for (let i = 0; i <
|
|
16521
|
+
if (shape2.k === "tuple") {
|
|
16522
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
15605
16523
|
if (isHole(i)) continue;
|
|
15606
|
-
const t = callbackTruth(callFn(args[0],
|
|
16524
|
+
const t = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
15607
16525
|
if (t === void 0) {
|
|
15608
16526
|
undecided = true;
|
|
15609
16527
|
continue;
|
|
@@ -15612,7 +16530,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15612
16530
|
if (method === "every" && !t) return boolLit(false);
|
|
15613
16531
|
}
|
|
15614
16532
|
} else {
|
|
15615
|
-
const t = callbackTruth(callFn(args[0],
|
|
16533
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15616
16534
|
if (t === void 0) return bool();
|
|
15617
16535
|
if (method === "some" && t) return boolLit(true);
|
|
15618
16536
|
if (method === "every" && !t) return boolLit(false);
|
|
@@ -15623,21 +16541,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15623
16541
|
}
|
|
15624
16542
|
if (method === "find") {
|
|
15625
16543
|
validateCallableArg(args[0], "find callback may not be callable");
|
|
15626
|
-
if (
|
|
16544
|
+
if (shape2.k === "tuple") {
|
|
15627
16545
|
let undecided = false;
|
|
15628
|
-
for (let i = 0; i <
|
|
15629
|
-
const el2 =
|
|
16546
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
16547
|
+
const el2 = shape2.elements[i];
|
|
15630
16548
|
const t2 = callbackTruth(callFn(args[0], el2, $lit(i), arr));
|
|
15631
16549
|
if (t2 === true) return el2;
|
|
15632
16550
|
if (t2 === void 0) undecided = true;
|
|
15633
16551
|
}
|
|
15634
16552
|
if (undecided) {
|
|
15635
|
-
const joined =
|
|
16553
|
+
const joined = shape2.elements.reduce((a, b) => joinAbs(a, b));
|
|
15636
16554
|
return joinAbs(joined, undefAbs());
|
|
15637
16555
|
}
|
|
15638
16556
|
return undefAbs();
|
|
15639
16557
|
}
|
|
15640
|
-
const el =
|
|
16558
|
+
const el = shape2.element;
|
|
15641
16559
|
const t = callbackTruth(callFn(args[0], el, unknownIdx(), arr));
|
|
15642
16560
|
if (t === true) return el;
|
|
15643
16561
|
if (t === false) return undefAbs();
|
|
@@ -15645,17 +16563,17 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15645
16563
|
}
|
|
15646
16564
|
if (method === "findIndex") {
|
|
15647
16565
|
validateCallableArg(args[0], "findIndex callback may not be callable");
|
|
15648
|
-
if (
|
|
16566
|
+
if (shape2.k === "tuple") {
|
|
15649
16567
|
let undecided = false;
|
|
15650
|
-
for (let i = 0; i <
|
|
15651
|
-
const t2 = callbackTruth(callFn(args[0],
|
|
16568
|
+
for (let i = 0; i < shape2.elements.length; i++) {
|
|
16569
|
+
const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
15652
16570
|
if (t2 === true) return $lit(i);
|
|
15653
16571
|
if (t2 === void 0) undecided = true;
|
|
15654
16572
|
}
|
|
15655
16573
|
if (undecided) return joinAbs(unknownIdx(), $lit(-1));
|
|
15656
16574
|
return $lit(-1);
|
|
15657
16575
|
}
|
|
15658
|
-
const t = callbackTruth(callFn(args[0],
|
|
16576
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15659
16577
|
if (t === true) return unknownIdx();
|
|
15660
16578
|
if (t === false) return $lit(-1);
|
|
15661
16579
|
return joinAbs(unknownIdx(), $lit(-1));
|
|
@@ -15663,28 +16581,28 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15663
16581
|
if (method === "findLast" || method === "findLastIndex") {
|
|
15664
16582
|
validateCallableArg(args[0], `${method} callback may not be callable`);
|
|
15665
16583
|
const wantIndex = method === "findLastIndex";
|
|
15666
|
-
if (
|
|
16584
|
+
if (shape2.k === "tuple") {
|
|
15667
16585
|
let undecided = false;
|
|
15668
|
-
for (let i =
|
|
15669
|
-
const t2 = callbackTruth(callFn(args[0],
|
|
15670
|
-
if (t2 === true) return wantIndex ? $lit(i) :
|
|
16586
|
+
for (let i = shape2.elements.length - 1; i >= 0; i--) {
|
|
16587
|
+
const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
|
|
16588
|
+
if (t2 === true) return wantIndex ? $lit(i) : shape2.elements[i];
|
|
15671
16589
|
if (t2 === void 0) undecided = true;
|
|
15672
16590
|
}
|
|
15673
16591
|
if (undecided) {
|
|
15674
|
-
const joined =
|
|
16592
|
+
const joined = shape2.elements.length ? shape2.elements.reduce((a, b) => joinAbs(a, b)) : unknown;
|
|
15675
16593
|
return wantIndex ? joinAbs(unknownIdx(), $lit(-1)) : joinAbs(joined, undefAbs());
|
|
15676
16594
|
}
|
|
15677
16595
|
return wantIndex ? $lit(-1) : undefAbs();
|
|
15678
16596
|
}
|
|
15679
|
-
const t = callbackTruth(callFn(args[0],
|
|
16597
|
+
const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
|
|
15680
16598
|
if (wantIndex) {
|
|
15681
16599
|
if (t === true) return unknownIdx();
|
|
15682
16600
|
if (t === false) return $lit(-1);
|
|
15683
16601
|
return joinAbs(unknownIdx(), $lit(-1));
|
|
15684
16602
|
}
|
|
15685
|
-
if (t === true) return
|
|
16603
|
+
if (t === true) return shape2.element;
|
|
15686
16604
|
if (t === false) return undefAbs();
|
|
15687
|
-
return joinAbs(
|
|
16605
|
+
return joinAbs(shape2.element, undefAbs());
|
|
15688
16606
|
}
|
|
15689
16607
|
if (method === "join") {
|
|
15690
16608
|
const folded = arrayJoinWithSep(arr, args[0]);
|
|
@@ -15696,11 +16614,11 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15696
16614
|
return arrayJoinToString(arr);
|
|
15697
16615
|
}
|
|
15698
16616
|
if (method === "keys") {
|
|
15699
|
-
if (
|
|
16617
|
+
if (shape2.k === "tuple") {
|
|
15700
16618
|
return abs(
|
|
15701
16619
|
{
|
|
15702
16620
|
k: "tuple",
|
|
15703
|
-
elements:
|
|
16621
|
+
elements: shape2.elements.map((_, i) => numLit(i))
|
|
15704
16622
|
},
|
|
15705
16623
|
void 0,
|
|
15706
16624
|
void 0,
|
|
@@ -15710,12 +16628,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15710
16628
|
return abs({ k: "arr", element: unknownIdx() }, void 0, void 0, "partial");
|
|
15711
16629
|
}
|
|
15712
16630
|
if (method === "values") {
|
|
15713
|
-
if (
|
|
15714
|
-
const holes2 =
|
|
16631
|
+
if (shape2.k === "tuple") {
|
|
16632
|
+
const holes2 = shape2.holes ?? [];
|
|
15715
16633
|
return abs(
|
|
15716
16634
|
{
|
|
15717
16635
|
k: "tuple",
|
|
15718
|
-
elements:
|
|
16636
|
+
elements: shape2.elements.map((el, i) => holes2.includes(i) ? undefAbs() : el)
|
|
15719
16637
|
},
|
|
15720
16638
|
void 0,
|
|
15721
16639
|
void 0,
|
|
@@ -15725,12 +16643,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15725
16643
|
return arr;
|
|
15726
16644
|
}
|
|
15727
16645
|
if (method === "entries") {
|
|
15728
|
-
if (
|
|
15729
|
-
const holes2 =
|
|
16646
|
+
if (shape2.k === "tuple") {
|
|
16647
|
+
const holes2 = shape2.holes ?? [];
|
|
15730
16648
|
return abs(
|
|
15731
16649
|
{
|
|
15732
16650
|
k: "tuple",
|
|
15733
|
-
elements:
|
|
16651
|
+
elements: shape2.elements.map(
|
|
15734
16652
|
(el, i) => abs(
|
|
15735
16653
|
{ k: "tuple", elements: [numLit(i), holes2.includes(i) ? undefAbs() : el] },
|
|
15736
16654
|
void 0,
|
|
@@ -15748,7 +16666,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15748
16666
|
{
|
|
15749
16667
|
k: "arr",
|
|
15750
16668
|
element: abs(
|
|
15751
|
-
{ k: "tuple", elements: [unknownIdx(),
|
|
16669
|
+
{ k: "tuple", elements: [unknownIdx(), shape2.element] },
|
|
15752
16670
|
void 0,
|
|
15753
16671
|
void 0,
|
|
15754
16672
|
"partial"
|
|
@@ -15760,16 +16678,16 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15760
16678
|
);
|
|
15761
16679
|
}
|
|
15762
16680
|
if (method === "fill" && args.length >= 1) {
|
|
15763
|
-
return fillTuple(
|
|
16681
|
+
return fillTuple(shape2, args, arr);
|
|
15764
16682
|
}
|
|
15765
16683
|
if (method === "sort" || method === "toSorted") {
|
|
15766
16684
|
validateCallableArg(args[0], `${method} comparator may not be callable`, {
|
|
15767
16685
|
undefinedOk: true
|
|
15768
16686
|
});
|
|
15769
|
-
if (
|
|
15770
|
-
return abs({ k: "arr", element:
|
|
16687
|
+
if (shape2.k === "arr") {
|
|
16688
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15771
16689
|
}
|
|
15772
|
-
const slots =
|
|
16690
|
+
const slots = shape2.elements.map((el2, i) => isHole(i) ? undefAbs() : el2);
|
|
15773
16691
|
const isUndefLit = (el2) => el2.term?.op === "lit" && el2.term.value === void 0;
|
|
15774
16692
|
const isDefaultCmp = args[0] === void 0 || !!asAbs(args[0])?.term && asAbs(args[0]).term.op === "lit" && asAbs(args[0]).term.value === void 0;
|
|
15775
16693
|
if (isDefaultCmp) {
|
|
@@ -15798,17 +16716,17 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15798
16716
|
}
|
|
15799
16717
|
}
|
|
15800
16718
|
}
|
|
15801
|
-
const el =
|
|
16719
|
+
const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15802
16720
|
return abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"));
|
|
15803
16721
|
}
|
|
15804
16722
|
if (method === "reverse") {
|
|
15805
|
-
if (
|
|
15806
|
-
const len =
|
|
15807
|
-
const holesR =
|
|
16723
|
+
if (shape2.k === "tuple") {
|
|
16724
|
+
const len = shape2.elements.length;
|
|
16725
|
+
const holesR = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
|
|
15808
16726
|
return abs(
|
|
15809
16727
|
{
|
|
15810
16728
|
k: "tuple",
|
|
15811
|
-
elements: [...
|
|
16729
|
+
elements: [...shape2.elements].reverse(),
|
|
15812
16730
|
holes: holesR && holesR.length > 0 ? holesR : void 0
|
|
15813
16731
|
},
|
|
15814
16732
|
void 0,
|
|
@@ -15816,21 +16734,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15816
16734
|
confJoin(arr.conf, "path")
|
|
15817
16735
|
);
|
|
15818
16736
|
}
|
|
15819
|
-
return abs({ k: "arr", element:
|
|
16737
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15820
16738
|
}
|
|
15821
16739
|
if (method === "toReversed") {
|
|
15822
|
-
if (
|
|
16740
|
+
if (shape2.k === "tuple") {
|
|
15823
16741
|
return abs(
|
|
15824
16742
|
{
|
|
15825
16743
|
k: "tuple",
|
|
15826
|
-
elements: [...
|
|
16744
|
+
elements: [...shape2.elements].reverse().map((el, i) => (shape2.holes ?? []).includes(shape2.elements.length - 1 - i) ? undefAbs() : el)
|
|
15827
16745
|
},
|
|
15828
16746
|
void 0,
|
|
15829
16747
|
void 0,
|
|
15830
16748
|
confJoin(arr.conf, "path")
|
|
15831
16749
|
);
|
|
15832
16750
|
}
|
|
15833
|
-
return abs({ k: "arr", element:
|
|
16751
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
15834
16752
|
}
|
|
15835
16753
|
if (method === "flat") {
|
|
15836
16754
|
validateIndexArg(args[0], "flat depth may not be convertible to a number");
|
|
@@ -15858,10 +16776,10 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15858
16776
|
}
|
|
15859
16777
|
return { els: out, degraded };
|
|
15860
16778
|
};
|
|
15861
|
-
if (
|
|
15862
|
-
const es =
|
|
16779
|
+
if (shape2.k === "arr") {
|
|
16780
|
+
const es = shape2.element.shape;
|
|
15863
16781
|
const innerEls = es.k === "tuple" ? es.elements.length ? es.elements.reduce((x, y) => joinAbs(x, y)) : unknown : es.k === "arr" ? es.element : void 0;
|
|
15864
|
-
const el = innerEls !== void 0 ? joinAbs(
|
|
16782
|
+
const el = innerEls !== void 0 ? joinAbs(shape2.element, innerEls) : shape2.element;
|
|
15865
16783
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15866
16784
|
}
|
|
15867
16785
|
if (depthRaw === null) {
|
|
@@ -15869,8 +16787,8 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15869
16787
|
kind: "TypeError",
|
|
15870
16788
|
cause: "flat depth may not be convertible to a number"
|
|
15871
16789
|
});
|
|
15872
|
-
const shallow = rec(
|
|
15873
|
-
const deep = rec(
|
|
16790
|
+
const shallow = rec(shape2.elements, holeSet, 0);
|
|
16791
|
+
const deep = rec(shape2.elements, holeSet, Number.MAX_SAFE_INTEGER);
|
|
15874
16792
|
if (shallow !== null && deep !== null) {
|
|
15875
16793
|
const el = [...shallow.els, ...deep.els].reduce((x, y) => joinAbs(x, y));
|
|
15876
16794
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
@@ -15878,9 +16796,9 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15878
16796
|
return unknown;
|
|
15879
16797
|
}
|
|
15880
16798
|
const depth = depthRaw === void 0 ? 1 : Math.max(depthRaw, 0);
|
|
15881
|
-
const r = rec(
|
|
16799
|
+
const r = rec(shape2.elements, holeSet, depth);
|
|
15882
16800
|
if (r === null) {
|
|
15883
|
-
const shallow = rec(
|
|
16801
|
+
const shallow = rec(shape2.elements, holeSet, 0);
|
|
15884
16802
|
const el = shallow && shallow.els.length ? shallow.els.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15885
16803
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15886
16804
|
}
|
|
@@ -15899,22 +16817,22 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15899
16817
|
validateIndexArg(args[0], "toSpliced start may not be convertible to a number");
|
|
15900
16818
|
validateIndexArg(args[1], "toSpliced skipCount may not be convertible to a number");
|
|
15901
16819
|
const items = args.slice(2);
|
|
15902
|
-
if (
|
|
16820
|
+
if (shape2.k === "tuple") {
|
|
15903
16821
|
const st = toIOI(args[0]);
|
|
15904
16822
|
const dc = args[1] === void 0 ? void 0 : toIOI(args[1]);
|
|
15905
16823
|
if (st === null || dc === null) {
|
|
15906
|
-
const parts2 = [...
|
|
16824
|
+
const parts2 = [...shape2.elements.filter((_, i) => !isHole(i)), ...items];
|
|
15907
16825
|
const el = parts2.length ? parts2.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
15908
16826
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
15909
16827
|
}
|
|
15910
|
-
const len =
|
|
16828
|
+
const len = shape2.elements.length;
|
|
15911
16829
|
const a = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
|
|
15912
16830
|
const skip = dc === void 0 ? len - a : Math.max(0, Math.min(dc, len - a));
|
|
15913
16831
|
const solid = (el, i) => isHole(i) ? undefAbs() : el;
|
|
15914
16832
|
const els = [
|
|
15915
|
-
...
|
|
16833
|
+
...shape2.elements.slice(0, a).map(solid),
|
|
15916
16834
|
...items,
|
|
15917
|
-
...
|
|
16835
|
+
...shape2.elements.slice(a + skip).map((el, i) => solid(el, a + skip + i))
|
|
15918
16836
|
];
|
|
15919
16837
|
return abs(
|
|
15920
16838
|
{ k: "tuple", elements: els },
|
|
@@ -15923,7 +16841,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15923
16841
|
confJoin(arr.conf, "path")
|
|
15924
16842
|
);
|
|
15925
16843
|
}
|
|
15926
|
-
const parts = [
|
|
16844
|
+
const parts = [shape2.element, ...items];
|
|
15927
16845
|
return abs(
|
|
15928
16846
|
{ k: "arr", element: parts.reduce((x, y) => joinAbs(x, y)) },
|
|
15929
16847
|
void 0,
|
|
@@ -15934,21 +16852,21 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15934
16852
|
if (method === "with") {
|
|
15935
16853
|
validateIndexArg(args[0], "with index may not be convertible to a number");
|
|
15936
16854
|
const v2 = args[1] ?? undefAbs();
|
|
15937
|
-
if (
|
|
16855
|
+
if (shape2.k === "tuple") {
|
|
15938
16856
|
const iv = toIOI(args[0]) ?? 0;
|
|
15939
16857
|
if (iv === null) {
|
|
15940
16858
|
recordMayThrow({ kind: "RangeError", cause: "with index may be out of range" });
|
|
15941
16859
|
return abs(
|
|
15942
|
-
{ k: "tuple", elements:
|
|
16860
|
+
{ k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
|
|
15943
16861
|
void 0,
|
|
15944
16862
|
void 0,
|
|
15945
16863
|
"partial"
|
|
15946
16864
|
);
|
|
15947
16865
|
}
|
|
15948
|
-
const len =
|
|
16866
|
+
const len = shape2.elements.length;
|
|
15949
16867
|
const idx = iv < 0 ? len + iv : iv;
|
|
15950
16868
|
if (idx < 0 || idx >= len) throw new NudoThrow(errorTypeAbs("RangeError"));
|
|
15951
|
-
const els =
|
|
16869
|
+
const els = shape2.elements.map(
|
|
15952
16870
|
(el, i) => i === idx ? v2 : isHole(i) ? undefAbs() : el
|
|
15953
16871
|
);
|
|
15954
16872
|
return abs(
|
|
@@ -15959,15 +16877,15 @@ function invokeArrMethod(arr, method, args) {
|
|
|
15959
16877
|
);
|
|
15960
16878
|
}
|
|
15961
16879
|
return abs(
|
|
15962
|
-
{ k: "arr", element: joinAbs(
|
|
16880
|
+
{ k: "arr", element: joinAbs(shape2.element, v2) },
|
|
15963
16881
|
void 0,
|
|
15964
16882
|
void 0,
|
|
15965
16883
|
"partial"
|
|
15966
16884
|
);
|
|
15967
16885
|
}
|
|
15968
16886
|
if (method === "concat") {
|
|
15969
|
-
if (
|
|
15970
|
-
const out = [...
|
|
16887
|
+
if (shape2.k === "tuple") {
|
|
16888
|
+
const out = [...shape2.elements];
|
|
15971
16889
|
const holesC = new Set(holes);
|
|
15972
16890
|
let degraded = false;
|
|
15973
16891
|
for (const a of args) {
|
|
@@ -16000,7 +16918,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16000
16918
|
confJoin(arr.conf, "path")
|
|
16001
16919
|
);
|
|
16002
16920
|
}
|
|
16003
|
-
const parts = [
|
|
16921
|
+
const parts = [shape2.element, ...args.map((a) => {
|
|
16004
16922
|
const aa = asAbs(a) ?? unknown;
|
|
16005
16923
|
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;
|
|
16006
16924
|
})];
|
|
@@ -16014,24 +16932,24 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16014
16932
|
if (method === "slice") {
|
|
16015
16933
|
validateIndexArg(args[0], "slice start may not be convertible to a number");
|
|
16016
16934
|
validateIndexArg(args[1], "slice end may not be convertible to a number");
|
|
16017
|
-
if (
|
|
16935
|
+
if (shape2.k === "tuple") {
|
|
16018
16936
|
const st = toIOI(args[0]);
|
|
16019
16937
|
const en = toIOI(args[1]);
|
|
16020
16938
|
if (st === null || en === null) {
|
|
16021
|
-
const el =
|
|
16939
|
+
const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
|
|
16022
16940
|
return abs({ k: "arr", element: el }, void 0, void 0, "partial");
|
|
16023
16941
|
}
|
|
16024
|
-
const len =
|
|
16942
|
+
const len = shape2.elements.length;
|
|
16025
16943
|
const s = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
|
|
16026
16944
|
const e = en === void 0 ? len : en < 0 ? Math.max(len + en, 0) : Math.min(en, len);
|
|
16027
16945
|
if (e <= s) {
|
|
16028
16946
|
return abs({ k: "tuple", elements: [] }, void 0, void 0, confJoin(arr.conf, "exact"));
|
|
16029
16947
|
}
|
|
16030
|
-
const holesS = (
|
|
16948
|
+
const holesS = (shape2.holes ?? []).filter((h) => h >= s && h < e).map((h) => h - s);
|
|
16031
16949
|
return abs(
|
|
16032
16950
|
{
|
|
16033
16951
|
k: "tuple",
|
|
16034
|
-
elements:
|
|
16952
|
+
elements: shape2.elements.slice(s, e),
|
|
16035
16953
|
holes: holesS.length > 0 ? holesS : void 0
|
|
16036
16954
|
},
|
|
16037
16955
|
void 0,
|
|
@@ -16039,12 +16957,12 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16039
16957
|
confJoin(arr.conf, "path")
|
|
16040
16958
|
);
|
|
16041
16959
|
}
|
|
16042
|
-
return abs({ k: "arr", element:
|
|
16960
|
+
return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
|
|
16043
16961
|
}
|
|
16044
16962
|
if (method === "indexOf" || method === "lastIndexOf") {
|
|
16045
16963
|
validateIndexArg(args[1], `${method} fromIndex may not be convertible to a number`);
|
|
16046
|
-
if (
|
|
16047
|
-
const els =
|
|
16964
|
+
if (shape2.k === "tuple") {
|
|
16965
|
+
const els = shape2.elements;
|
|
16048
16966
|
const search = args[0];
|
|
16049
16967
|
const searchLit = search !== void 0 && search.term?.op === "lit" ? litValue(search) : void 0;
|
|
16050
16968
|
const hasLitSearch = search !== void 0 && search.term?.op === "lit";
|
|
@@ -16089,22 +17007,22 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16089
17007
|
return abs({ k: "prim", type: "number" }, void 0, void 0, "path");
|
|
16090
17008
|
}
|
|
16091
17009
|
if (method === "pop") {
|
|
16092
|
-
if (
|
|
16093
|
-
return
|
|
17010
|
+
if (shape2.k === "tuple") {
|
|
17011
|
+
return shape2.elements.length > 0 ? shape2.elements[shape2.elements.length - 1] ?? unknown : undefAbs();
|
|
16094
17012
|
}
|
|
16095
|
-
if (
|
|
17013
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16096
17014
|
}
|
|
16097
17015
|
if (method === "shift") {
|
|
16098
|
-
if (
|
|
16099
|
-
return
|
|
17016
|
+
if (shape2.k === "tuple" && shape2.elements.length > 0) {
|
|
17017
|
+
return shape2.elements[0] ?? unknown;
|
|
16100
17018
|
}
|
|
16101
|
-
if (
|
|
17019
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16102
17020
|
}
|
|
16103
17021
|
if (method === "at") {
|
|
16104
17022
|
validateIndexArg(args[0], "at index may not be convertible to a number");
|
|
16105
17023
|
const iv = toIntegerOrInfinityLit(args[0]);
|
|
16106
|
-
if (
|
|
16107
|
-
const els =
|
|
17024
|
+
if (shape2.k === "tuple") {
|
|
17025
|
+
const els = shape2.elements;
|
|
16108
17026
|
if (iv === void 0) {
|
|
16109
17027
|
if (els.length === 0) return undefAbs();
|
|
16110
17028
|
return joinAbs(els.reduce((a, b) => joinAbs(a, b)), undefAbs());
|
|
@@ -16113,7 +17031,7 @@ function invokeArrMethod(arr, method, args) {
|
|
|
16113
17031
|
if (idx >= 0 && idx < els.length) return els[idx] ?? unknown;
|
|
16114
17032
|
return undefAbs();
|
|
16115
17033
|
}
|
|
16116
|
-
if (
|
|
17034
|
+
if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
|
|
16117
17035
|
}
|
|
16118
17036
|
return void 0;
|
|
16119
17037
|
}
|
|
@@ -16327,11 +17245,11 @@ function $setKey(o, key, value) {
|
|
|
16327
17245
|
confJoin("path", value.conf)
|
|
16328
17246
|
);
|
|
16329
17247
|
}
|
|
16330
|
-
const
|
|
16331
|
-
const prevIndex =
|
|
17248
|
+
const shape2 = o.shape;
|
|
17249
|
+
const prevIndex = shape2.index?.value;
|
|
16332
17250
|
const indexVal = prevIndex ? joinAbs(prevIndex, val) : val;
|
|
16333
|
-
const next = objOf({ ...
|
|
16334
|
-
index: { key:
|
|
17251
|
+
const next = objOf({ ...shape2.slots }, {
|
|
17252
|
+
index: { key: shape2.index?.key ?? unknown, value: indexVal },
|
|
16335
17253
|
open: true
|
|
16336
17254
|
});
|
|
16337
17255
|
next.conf = confJoin(o.conf, value.conf);
|
|
@@ -17339,12 +18257,12 @@ ${js}`;
|
|
|
17339
18257
|
}
|
|
17340
18258
|
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; })()` : "{}";
|
|
17341
18259
|
const ret = `return { ...__nudoExports, ...${cjsMerge}, ${names.join(", ")} };`;
|
|
17342
|
-
const
|
|
18260
|
+
const fn2 = new Function(...argNames, `${js}
|
|
17343
18261
|
${ret}`);
|
|
17344
18262
|
setEvalBindingSink(bindings);
|
|
17345
18263
|
beginClassEpoch();
|
|
17346
18264
|
try {
|
|
17347
|
-
const result =
|
|
18265
|
+
const result = fn2(...args);
|
|
17348
18266
|
runBindings.set(result, bindings);
|
|
17349
18267
|
return result;
|
|
17350
18268
|
} finally {
|
|
@@ -17436,14 +18354,14 @@ function callTranspiledExportFull(exports, name, args, opts) {
|
|
|
17436
18354
|
});
|
|
17437
18355
|
}
|
|
17438
18356
|
function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
17439
|
-
const
|
|
17440
|
-
if (typeof
|
|
18357
|
+
const fn2 = Object.hasOwn(exports, name) ? exports[name] : void 0;
|
|
18358
|
+
if (typeof fn2 === "function") {
|
|
17441
18359
|
const callArgs = args.map(
|
|
17442
18360
|
(a) => a && typeof a === "object" && "shape" in a ? $copy(a) : asAbsVal(a)
|
|
17443
18361
|
);
|
|
17444
18362
|
return runWithLoopExits(() => {
|
|
17445
18363
|
try {
|
|
17446
|
-
const invoke = () => withNewTargetReset(() =>
|
|
18364
|
+
const invoke = () => withNewTargetReset(() => fn2(...callArgs));
|
|
17447
18365
|
const r = opts?.phi ? withExecPhi(opts.phi, invoke) : invoke();
|
|
17448
18366
|
drainPromiseMicros();
|
|
17449
18367
|
if (!isAbsVal(r)) return joinControlExits(unknown);
|
|
@@ -17472,11 +18390,11 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
|
17472
18390
|
}
|
|
17473
18391
|
});
|
|
17474
18392
|
}
|
|
17475
|
-
if (isAbsVal(
|
|
17476
|
-
if (
|
|
18393
|
+
if (isAbsVal(fn2)) {
|
|
18394
|
+
if (fn2.shape.k === "fn") {
|
|
17477
18395
|
return runWithLoopExits(() => {
|
|
17478
18396
|
try {
|
|
17479
|
-
const r = $call(
|
|
18397
|
+
const r = $call(fn2, args);
|
|
17480
18398
|
drainPromiseMicros();
|
|
17481
18399
|
return joinControlExits(r);
|
|
17482
18400
|
} catch (e) {
|
|
@@ -17496,7 +18414,7 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
|
|
|
17496
18414
|
});
|
|
17497
18415
|
}
|
|
17498
18416
|
drainPromiseMicros();
|
|
17499
|
-
return { result:
|
|
18417
|
+
return { result: fn2, throws: never };
|
|
17500
18418
|
}
|
|
17501
18419
|
drainPromiseMicros();
|
|
17502
18420
|
return { result: unknown, throws: never };
|
|
@@ -17680,26 +18598,31 @@ function joinThrowsSince2(mark) {
|
|
|
17680
18598
|
if (items.length === 1) return items[0];
|
|
17681
18599
|
return items.reduce((a, b) => joinAbs(a, b));
|
|
17682
18600
|
}
|
|
17683
|
-
function $call(
|
|
17684
|
-
return withNewTargetReset(() => $callInner(
|
|
18601
|
+
function $call(fn2, args, thisVal) {
|
|
18602
|
+
return withNewTargetReset(() => $callInner(fn2, args, thisVal));
|
|
17685
18603
|
}
|
|
17686
|
-
function $callInner(
|
|
17687
|
-
if (
|
|
17688
|
-
const results =
|
|
17689
|
-
if (results.every((
|
|
18604
|
+
function $callInner(fn2, args, thisVal) {
|
|
18605
|
+
if (fn2?.shape?.k === "sum") {
|
|
18606
|
+
const results = fn2.shape.members.map((m) => $call(m, args, thisVal));
|
|
18607
|
+
if (results.every((r2) => r2.shape.k === "unknown")) return unknown;
|
|
17690
18608
|
return results.reduce((a, b) => joinAbs(a, b));
|
|
17691
18609
|
}
|
|
17692
|
-
const
|
|
17693
|
-
const
|
|
18610
|
+
const faces = contractFacesOf(fn2);
|
|
18611
|
+
const r = $callDispatch(fn2, faces ? adoptCallArgsToFaces(args, faces) : args, thisVal);
|
|
18612
|
+
return faces ? presentCallResultFace(r, faces) : r;
|
|
18613
|
+
}
|
|
18614
|
+
function $callDispatch(fn2, args, thisVal) {
|
|
18615
|
+
const pureName = pureFnNameOf(fn2);
|
|
18616
|
+
const fnObj = fn2 && typeof fn2 === "object" ? fn2 : void 0;
|
|
17694
18617
|
const pk = pureName && fnObj ? pureMemoKey(args) : void 0;
|
|
17695
18618
|
if (fnObj && pk !== void 0) {
|
|
17696
18619
|
const hit = pureMemo.get(fnObj)?.get(pk);
|
|
17697
18620
|
if (hit !== void 0) return routeApplyThrows(hit.abs, hit.throws);
|
|
17698
18621
|
}
|
|
17699
|
-
const impl = getFnImpl(
|
|
18622
|
+
const impl = getFnImpl(fn2);
|
|
17700
18623
|
if (!impl?.body && !impl?.apply) {
|
|
17701
|
-
if (impl?.relation || isRelFn(
|
|
17702
|
-
const calleeAbs =
|
|
18624
|
+
if (impl?.relation || isRelFn(fn2)) return instantiateReturn(fn2, args);
|
|
18625
|
+
const calleeAbs = fn2 && typeof fn2 === "object" ? fn2 : void 0;
|
|
17703
18626
|
const calleeK = calleeAbs?.shape?.k;
|
|
17704
18627
|
if (calleeK === "prim" || calleeAbs !== void 0 && isNullishLitAbs(calleeAbs)) {
|
|
17705
18628
|
throw new NudoThrow(errorTypeAbs("TypeError"));
|
|
@@ -17713,8 +18636,8 @@ function $callInner(fn, args, thisVal) {
|
|
|
17713
18636
|
return unknown;
|
|
17714
18637
|
}
|
|
17715
18638
|
if (impl?.apply) {
|
|
17716
|
-
const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(
|
|
17717
|
-
const label =
|
|
18639
|
+
const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(fn2), args);
|
|
18640
|
+
const label = fn2.shape.name ?? "anonymous";
|
|
17718
18641
|
if (!enterCall(key, label)) return truncatedAbs();
|
|
17719
18642
|
try {
|
|
17720
18643
|
try {
|
|
@@ -17740,8 +18663,8 @@ function $callInner(fn, args, thisVal) {
|
|
|
17740
18663
|
}
|
|
17741
18664
|
const compiled = compiledBodyOf(impl);
|
|
17742
18665
|
if (compiled) {
|
|
17743
|
-
const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(
|
|
17744
|
-
const label =
|
|
18666
|
+
const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(fn2), args);
|
|
18667
|
+
const label = fn2.shape.name ?? "anonymous";
|
|
17745
18668
|
if (!enterCall(key, label)) return truncatedAbs();
|
|
17746
18669
|
try {
|
|
17747
18670
|
const throwMark = throwExitsMark();
|
|
@@ -18118,9 +19041,9 @@ function evalObjectMethod(name, args) {
|
|
|
18118
19041
|
const key = keyR?.ok ? keyR.value : void 0;
|
|
18119
19042
|
if (typeof key !== "string") return boolPrim();
|
|
18120
19043
|
if (a0.shape.k === "obj") {
|
|
18121
|
-
const
|
|
18122
|
-
if (Object.prototype.hasOwnProperty.call(
|
|
18123
|
-
if (!
|
|
19044
|
+
const shape2 = a0.shape;
|
|
19045
|
+
if (Object.prototype.hasOwnProperty.call(shape2.slots, key)) return boolLit(true);
|
|
19046
|
+
if (!shape2.open && a0.conf === "exact") return boolLit(false);
|
|
18124
19047
|
return boolPrim();
|
|
18125
19048
|
}
|
|
18126
19049
|
return boolPrim();
|
|
@@ -20315,7 +21238,12 @@ function isKnownNonBigintNumeric2(a) {
|
|
|
20315
21238
|
if (a.term?.op === "lit" && a.term.value === void 0) return true;
|
|
20316
21239
|
return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
|
|
20317
21240
|
}
|
|
21241
|
+
function isNullishLitOperand2(a) {
|
|
21242
|
+
const r = litValue(a);
|
|
21243
|
+
return r.ok && (r.value === null || r.value === void 0);
|
|
21244
|
+
}
|
|
20318
21245
|
function isMaybeBigintOperand2(a) {
|
|
21246
|
+
if (isNullishLitOperand2(a)) return false;
|
|
20319
21247
|
const k = a.shape.k;
|
|
20320
21248
|
if (k === "sum") {
|
|
20321
21249
|
const members = a.shape.members;
|
|
@@ -21332,8 +22260,43 @@ export {
|
|
|
21332
22260
|
$removeNullish,
|
|
21333
22261
|
$removeNull,
|
|
21334
22262
|
$removeUndefined,
|
|
22263
|
+
$removeMemberNullish,
|
|
21335
22264
|
$narrowTypeOf,
|
|
21336
22265
|
$nullishTest,
|
|
22266
|
+
SELF,
|
|
22267
|
+
getTerm,
|
|
22268
|
+
lenTerm,
|
|
22269
|
+
isNudoConstraint,
|
|
22270
|
+
isIntFlag,
|
|
22271
|
+
number,
|
|
22272
|
+
string,
|
|
22273
|
+
boolean,
|
|
22274
|
+
any,
|
|
22275
|
+
array,
|
|
22276
|
+
shape,
|
|
22277
|
+
litC,
|
|
22278
|
+
union,
|
|
22279
|
+
nullable,
|
|
22280
|
+
lazy,
|
|
22281
|
+
derefConstraint,
|
|
22282
|
+
constraintAdmitsNullish,
|
|
22283
|
+
fn,
|
|
22284
|
+
andC,
|
|
22285
|
+
partial,
|
|
22286
|
+
pick,
|
|
22287
|
+
omit,
|
|
22288
|
+
CONSTRAINT_BUILDERS,
|
|
22289
|
+
CONSTRAINT_BUILDER_NAMES,
|
|
22290
|
+
CONSTRAINT_EXPR_RE,
|
|
22291
|
+
instantiateConstraint,
|
|
22292
|
+
instantiateOnTerm,
|
|
22293
|
+
constraintToEntryAbs,
|
|
22294
|
+
fnConstraintToEntryReqs,
|
|
22295
|
+
throwConstraintToKinds,
|
|
22296
|
+
literalMeetsConstraint,
|
|
22297
|
+
attachContractFaces,
|
|
22298
|
+
setContractFaceResolver,
|
|
22299
|
+
contractFacesFromEffectiveInterface,
|
|
21337
22300
|
clearPureCallMemo,
|
|
21338
22301
|
setEvalAssignCollector,
|
|
21339
22302
|
$assignRecord,
|