nudojs 1.3.9 → 1.3.11

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.
Files changed (3) hide show
  1. package/README.md +1 -1
  2. package/dist/index.js +101 -20
  3. package/package.json +6 -6
package/README.md CHANGED
@@ -21,6 +21,6 @@ nudojs <version>
21
21
  @nudojs/core <version> # when resolvable
22
22
  ```
23
23
 
24
- > **Migration:** `@nudojs/cli` is a deprecated stub that forwards here. Install `nudojs` only.
24
+ > **Migration:** the `@nudojs/cli` forward stub has been retired — install `nudojs` only.
25
25
 
26
26
  Full documentation: <https://nudojs.github.io/nudo/>
package/dist/index.js CHANGED
@@ -17880,7 +17880,12 @@ function isKnownNonBigintNumeric(a) {
17880
17880
  if (r.ok && r.value === void 0) return true;
17881
17881
  return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
17882
17882
  }
17883
+ function isNullishLitOperand(a) {
17884
+ const r = litValue(a);
17885
+ return r.ok && (r.value === null || r.value === void 0);
17886
+ }
17883
17887
  function isMaybeBigintOperand(a) {
17888
+ if (isNullishLitOperand(a)) return false;
17884
17889
  const k = a.shape.k;
17885
17890
  if (k === "sum") {
17886
17891
  const members = a.shape.members;
@@ -21654,9 +21659,15 @@ function nullishGuardOf(test) {
21654
21659
  if (t?.type === "UnaryExpression" && t.operator === "!" && t.argument?.type === "Identifier" && t.argument.name) {
21655
21660
  return { name: t.argument.name, arm: "alt", grain: "nullish" };
21656
21661
  }
21662
+ if (t?.type === "UnaryExpression" && t.operator === "!") {
21663
+ const m = memberGuardTarget(t.argument);
21664
+ if (m) return { name: m.name, arm: "alt", grain: "nullish", memberKey: m.key };
21665
+ }
21657
21666
  if (t?.type === "Identifier" && t.name) {
21658
21667
  return { name: t.name, arm: "cons", grain: "nullish" };
21659
21668
  }
21669
+ const bare = memberGuardTarget(t);
21670
+ if (bare) return { name: bare.name, arm: "cons", grain: "nullish", memberKey: bare.key };
21660
21671
  if (t?.type !== "BinaryExpression") return void 0;
21661
21672
  const op = t.operator;
21662
21673
  if (op !== "===" && op !== "!==" && op !== "==" && op !== "!=") return void 0;
@@ -21693,15 +21704,20 @@ function nullishGuardOf(test) {
21693
21704
  function compositeNullishGuardOf(test) {
21694
21705
  const t = test;
21695
21706
  if (t?.type !== "LogicalExpression" || t.operator !== "||" && t.operator !== "&&") return void 0;
21707
+ const wantArm = t.operator === "||" ? "alt" : "cons";
21696
21708
  const l = nullishGuardOf(t.left);
21697
21709
  const r = nullishGuardOf(t.right);
21698
- if (!l || !r || l.name !== r.name) return void 0;
21699
- const wantArm = t.operator === "||" ? "alt" : "cons";
21700
- if (l.arm !== wantArm || r.arm !== wantArm) return void 0;
21701
- const g1 = l.grain === "null" || l.grain === "undefined" ? l.grain : null;
21702
- const g2 = r.grain === "null" || r.grain === "undefined" ? r.grain : null;
21703
- const grain = g1 === null || g2 === null ? "nullish" : mergeGrain(g1, g2);
21704
- return { name: l.name, arm: wantArm, grain };
21710
+ const lg = l && l.arm === wantArm ? l : void 0;
21711
+ const rg = r && r.arm === wantArm ? r : void 0;
21712
+ if (lg && rg) {
21713
+ if (lg.name !== rg.name) return void 0;
21714
+ const g1 = lg.grain === "null" || lg.grain === "undefined" ? lg.grain : null;
21715
+ const g2 = rg.grain === "null" || rg.grain === "undefined" ? rg.grain : null;
21716
+ const grain = g1 === null || g2 === null ? "nullish" : mergeGrain(g1, g2);
21717
+ const memberKey = lg.memberKey ?? rg.memberKey;
21718
+ return { name: lg.name, arm: wantArm, grain, ...memberKey !== void 0 ? { memberKey } : {} };
21719
+ }
21720
+ return lg ?? rg;
21705
21721
  }
21706
21722
  function typeGuardOf(test) {
21707
21723
  const t = test;
@@ -21716,16 +21732,19 @@ function typeGuardOf(test) {
21716
21732
  if (litSide.value === "undefined" || !TYPEOF_NAMES2.has(litSide.value)) return void 0;
21717
21733
  return { name, typeOf: litSide.value, arm: op === "===" || op === "==" ? "cons" : "alt" };
21718
21734
  }
21719
- function removeCallOf(grain) {
21720
- if (grain === "undefined") return "$removeUndefined";
21721
- if (grain === "null") return "$removeNull";
21722
- return "$removeNullish";
21735
+ function nullishRemoveCallOf(guard) {
21736
+ if (guard.memberKey !== void 0) {
21737
+ return `$removeMemberNullish($removeNullish(${guard.name}), ${JSON.stringify(guard.memberKey)})`;
21738
+ }
21739
+ if (guard.grain === "undefined") return `$removeUndefined(${guard.name})`;
21740
+ if (guard.grain === "null") return `$removeNull(${guard.name})`;
21741
+ return `$removeNullish(${guard.name})`;
21723
21742
  }
21724
21743
  function narrowNullishArmThunk(thunk, guard, arm, forkBindingNames) {
21725
21744
  if (!guard || guard.arm !== arm) return thunk;
21726
21745
  const names2 = forkBindingNames instanceof Set ? forkBindingNames : new Set(forkBindingNames);
21727
21746
  if (names2.has(guard.name)) return thunk;
21728
- return `((${guard.name}) => ${thunk})(${removeCallOf(guard.grain)}(${guard.name}))`;
21747
+ return `((${guard.name}) => ${thunk})(${nullishRemoveCallOf(guard)})`;
21729
21748
  }
21730
21749
  function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
21731
21750
  if (!guard) return thunk;
@@ -21734,7 +21753,7 @@ function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
21734
21753
  const keep = arm === guard.arm;
21735
21754
  return `((${guard.name}) => ${thunk})($narrowTypeOf(${guard.name}, ${JSON.stringify(guard.typeOf)}, ${keep}))`;
21736
21755
  }
21737
- var TYPEOF_NAMES2, isStrLitNode, typeofArgName;
21756
+ var TYPEOF_NAMES2, isStrLitNode, typeofArgName, memberGuardTarget;
21738
21757
  var init_stmt_predicates = __esm({
21739
21758
  "../core/src/algebra/exec/transpile/stmt-predicates.ts"() {
21740
21759
  "use strict";
@@ -21760,6 +21779,17 @@ var init_stmt_predicates = __esm({
21760
21779
  }
21761
21780
  return void 0;
21762
21781
  };
21782
+ memberGuardTarget = (n) => {
21783
+ const t = n;
21784
+ const m = t?.type === "ChainExpression" ? t.expression : t;
21785
+ if (m?.type !== "MemberExpression" && m?.type !== "OptionalMemberExpression") return void 0;
21786
+ if (m.computed) return void 0;
21787
+ if (m.object?.type !== "Identifier" || !m.object.name) return void 0;
21788
+ const p = m.property;
21789
+ const key = p?.type === "Identifier" ? p.name : p?.type === "StringLiteral" && typeof p.value === "string" ? p.value : void 0;
21790
+ if (key === void 0) return void 0;
21791
+ return { name: m.object.name, key };
21792
+ };
21763
21793
  }
21764
21794
  });
21765
21795
 
@@ -21855,13 +21885,24 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
21855
21885
  };
21856
21886
  const testRecvs = collectArrMutatorReceivers(stmt.test);
21857
21887
  const testRebinds = testRecvs.size ? emitArrMutatorRebinds(stmt.test, scopedOpts, pad) : [];
21858
- const cons = wrapArm(transpileBlockAsThunk(stmt.consequent, depth, scopedOpts), "fk1_");
21888
+ const earlyGuard = nullishGuardOf(stmt.test);
21889
+ const earlyTGuard = typeGuardOf(stmt.test);
21890
+ const consNarrowed = narrowTypeArmThunk(
21891
+ narrowNullishArmThunk(
21892
+ transpileBlockAsThunk(stmt.consequent, depth, scopedOpts),
21893
+ earlyGuard,
21894
+ "cons",
21895
+ recvSet
21896
+ ),
21897
+ earlyTGuard,
21898
+ "cons",
21899
+ recvSet
21900
+ );
21901
+ const cons = wrapArm(consNarrowed, "fk1_");
21859
21902
  const altBody = transpileFnBodyStmts(rest, depth + 1, { ...scopedOpts, inLoop: opts.inLoop });
21860
21903
  const altThunk = `() => {
21861
21904
  ${altBody}
21862
21905
  ${pad}}`;
21863
- const earlyGuard = nullishGuardOf(stmt.test);
21864
- const earlyTGuard = typeGuardOf(stmt.test);
21865
21906
  const altNarrowed = narrowTypeArmThunk(
21866
21907
  narrowNullishArmThunk(altThunk, earlyGuard, "alt", recvSet),
21867
21908
  earlyTGuard,
@@ -23117,9 +23158,9 @@ function transpileShortCircuitExpr(opts, parts) {
23117
23158
  let altExpr = parts.altSrc === "__test" ? parts.alwaysSrc : parts.altSrc;
23118
23159
  if (parts.narrowGuard) {
23119
23160
  if (parts.narrowGuard.arm === "cons") {
23120
- consExpr = `((${parts.narrowGuard.name}) => (${consExpr}))($removeNullish(${parts.narrowGuard.name}))`;
23161
+ consExpr = `((${parts.narrowGuard.name}) => (${consExpr}))(${nullishRemoveCallOf(parts.narrowGuard)})`;
23121
23162
  } else {
23122
- altExpr = `((${parts.narrowGuard.name}) => (${altExpr}))($removeNullish(${parts.narrowGuard.name}))`;
23163
+ altExpr = `((${parts.narrowGuard.name}) => (${altExpr}))(${nullishRemoveCallOf(parts.narrowGuard)})`;
23123
23164
  }
23124
23165
  }
23125
23166
  if (parts.typeGuard) {
@@ -24153,7 +24194,7 @@ function transpileSource(source, opts = {}) {
24153
24194
  return transpileFile(file, { ...opts, source: opts.source ?? source });
24154
24195
  }
24155
24196
  function runtimeImportOf(runtime) {
24156
- 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)};`;
24197
+ 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)};`;
24157
24198
  }
24158
24199
  function transpileFile(file, opts = {}) {
24159
24200
  const runtime = opts.runtimeImport ?? "@nudojs/core/exec";
@@ -24174,7 +24215,7 @@ function transpileFile(file, opts = {}) {
24174
24215
  };
24175
24216
  const lines = [
24176
24217
  `// nudo evaluator transpile \u2014 values are Abs; operators are overloaded calls`,
24177
- `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)};`,
24218
+ `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)};`,
24178
24219
  ``
24179
24220
  ];
24180
24221
  if (varHoistLine) lines.push(varHoistLine);
@@ -28152,6 +28193,28 @@ function $removeUndefined(a) {
28152
28193
  }
28153
28194
  return a;
28154
28195
  }
28196
+ function $removeMemberNullish(a, key) {
28197
+ if (!a || typeof a !== "object" || !("shape" in a)) return a;
28198
+ if (a.shape.k !== "obj") return a;
28199
+ const slots = a.shape.slots;
28200
+ if (!Object.prototype.hasOwnProperty.call(slots, key)) return a;
28201
+ const slot = slots[key];
28202
+ let value = slot.value;
28203
+ let changed = false;
28204
+ if (!definitelyNotNullishShape(value.shape) && value.shape.k === "sum") {
28205
+ const members = value.shape.members;
28206
+ const kept = members.filter((m) => !isNullishLitAbs(m));
28207
+ if (kept.length > 0 && kept.length < members.length) {
28208
+ value = kept.length === 1 ? kept[0] : { ...value, shape: { k: "sum", members: kept } };
28209
+ changed = true;
28210
+ }
28211
+ }
28212
+ if (slot.optional) changed = true;
28213
+ if (!changed) return a;
28214
+ const next = { ...slot, value };
28215
+ delete next.optional;
28216
+ return { ...a, shape: { ...a.shape, slots: { ...slots, [key]: next } } };
28217
+ }
28155
28218
  function typeofOfMember(m) {
28156
28219
  const t = m.term;
28157
28220
  if (t?.op === "lit") {
@@ -28289,6 +28352,7 @@ __export(runtime_exports, {
28289
28352
  $pushLoopExit: () => $pushLoopExit,
28290
28353
  $rawThis: () => $rawThis,
28291
28354
  $regex: () => $regex,
28355
+ $removeMemberNullish: () => $removeMemberNullish,
28292
28356
  $removeNull: () => $removeNull,
28293
28357
  $removeNullish: () => $removeNullish,
28294
28358
  $removeUndefined: () => $removeUndefined,
@@ -35718,7 +35782,12 @@ function isKnownNonBigintNumeric2(a) {
35718
35782
  if (a.term?.op === "lit" && a.term.value === void 0) return true;
35719
35783
  return a.shape.k === "prim" && (a.shape.type === "number" || a.shape.type === "boolean");
35720
35784
  }
35785
+ function isNullishLitOperand2(a) {
35786
+ const r = litValue(a);
35787
+ return r.ok && (r.value === null || r.value === void 0);
35788
+ }
35721
35789
  function isMaybeBigintOperand2(a) {
35790
+ if (isNullishLitOperand2(a)) return false;
35722
35791
  const k = a.shape.k;
35723
35792
  if (k === "sum") {
35724
35793
  const members = a.shape.members;
@@ -40820,6 +40889,15 @@ function flattenSumArms(ret) {
40820
40889
  function isWidenedSumArm(m, parent) {
40821
40890
  return parent.conf === "partial" && m.shape.k === "prim" && !m.term && (!m.pred || m.pred.op === "true");
40822
40891
  }
40892
+ function provesBarePrimDomain(arm, constraint) {
40893
+ if (!constraint.prim || constraint.preds.length > 0 || isIntFlag(constraint)) {
40894
+ return false;
40895
+ }
40896
+ if (constraint.fields || constraint.element || constraint.members || constraint.fn) {
40897
+ return false;
40898
+ }
40899
+ return arm.shape.k === "prim" && arm.shape.type === constraint.prim;
40900
+ }
40823
40901
  function assertImplies(ret, constraint, opts) {
40824
40902
  const phi2 = opts?.phi ?? pTrue;
40825
40903
  if (ret.shape.k === "never") return proved();
@@ -40854,6 +40932,9 @@ function assertSumArms(arms, parent, constraint, opts, phi2) {
40854
40932
  continue;
40855
40933
  }
40856
40934
  if (isValueSetUnknown(arm) || isWidenedSumArm(arm, parent)) {
40935
+ if (isWidenedSumArm(arm, parent) && provesBarePrimDomain(arm, constraint)) {
40936
+ continue;
40937
+ }
40857
40938
  sawUnprovable = true;
40858
40939
  continue;
40859
40940
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nudojs",
3
- "version": "1.3.9",
3
+ "version": "1.3.11",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },
@@ -46,11 +46,11 @@
46
46
  "dependencies": {
47
47
  "@babel/generator": "^8.0.6",
48
48
  "@babel/types": "^8.0.6",
49
- "@nudojs/core": "1.7.8",
50
- "@nudojs/env": "0.4.23",
51
- "@nudojs/harvester": "0.3.9",
52
- "@nudojs/parser": "1.4.5",
53
- "@nudojs/service": "1.6.8",
49
+ "@nudojs/core": "1.7.10",
50
+ "@nudojs/env": "0.4.25",
51
+ "@nudojs/harvester": "0.3.11",
52
+ "@nudojs/parser": "1.4.7",
53
+ "@nudojs/service": "1.6.10",
54
54
  "commander": "^15.0.0"
55
55
  },
56
56
  "devDependencies": {