nudojs 1.3.16 → 1.3.17

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 (2) hide show
  1. package/dist/index.js +150 -50
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -19481,7 +19481,12 @@ var init_unsupported = __esm({
19481
19481
  });
19482
19482
 
19483
19483
  // ../core/src/algebra/param-surface.ts
19484
- function collectPatternNames(p, top, nested, depth, propKey) {
19484
+ function pushNestedPath(prefix2, key, nestedPaths) {
19485
+ if (prefix2.length === 0 || !key) return;
19486
+ if (key.includes(".") || prefix2.some((seg) => seg.includes("."))) return;
19487
+ nestedPaths.push([...prefix2, key].join("."));
19488
+ }
19489
+ function collectPatternNames(p, top, nested, depth, propKey, prefix2, nestedPaths) {
19485
19490
  if (!p) return;
19486
19491
  if (p.type === "Identifier" && p.name) {
19487
19492
  if (depth === 0) top.push(p.name);
@@ -19489,17 +19494,17 @@ function collectPatternNames(p, top, nested, depth, propKey) {
19489
19494
  return;
19490
19495
  }
19491
19496
  if (p.type === "AssignmentPattern") {
19492
- collectPatternNames(p.left, top, nested, depth, propKey);
19497
+ collectPatternNames(p.left, top, nested, depth, propKey, prefix2, nestedPaths);
19493
19498
  return;
19494
19499
  }
19495
19500
  if (p.type === "RestElement") {
19496
- collectPatternNames(p.argument, top, nested, depth, propKey);
19501
+ collectPatternNames(p.argument, top, nested, depth, propKey, prefix2, nestedPaths);
19497
19502
  return;
19498
19503
  }
19499
19504
  if (p.type === "ObjectPattern") {
19500
19505
  for (const prop of p.properties ?? []) {
19501
19506
  if (prop.type === "RestElement" || prop.argument) {
19502
- collectPatternNames(prop.argument, top, nested, depth, propKey);
19507
+ collectPatternNames(prop.argument, top, nested, depth, propKey, prefix2, nestedPaths);
19503
19508
  continue;
19504
19509
  }
19505
19510
  const keyName = prop.key?.type === "Identifier" && prop.key.name ? prop.key.name : prop.key && "value" in prop.key ? String(prop.key.value ?? "") : void 0;
@@ -19511,7 +19516,17 @@ function collectPatternNames(p, top, nested, depth, propKey) {
19511
19516
  else nested.push(keyName);
19512
19517
  if (propKey && depth === 0) propKey[keyName] = keyName;
19513
19518
  }
19519
+ const patternValueKeyRule = () => {
19520
+ if (!keyName) return;
19521
+ if (depth === 0 && prefix2.length === 0) {
19522
+ top.push(keyName);
19523
+ if (propKey) propKey[keyName] = keyName;
19524
+ } else {
19525
+ pushNestedPath(prefix2, keyName, nestedPaths);
19526
+ }
19527
+ };
19514
19528
  if (v2.type === "Identifier" && v2.name) {
19529
+ pushNestedPath(prefix2, keyName ?? "", nestedPaths);
19515
19530
  if (depth === 0) {
19516
19531
  top.push(v2.name);
19517
19532
  if (propKey && keyName) propKey[v2.name] = keyName;
@@ -19519,15 +19534,38 @@ function collectPatternNames(p, top, nested, depth, propKey) {
19519
19534
  } else if (v2.type === "AssignmentPattern") {
19520
19535
  const left = v2.left;
19521
19536
  if (left?.type === "Identifier" && left.name) {
19537
+ pushNestedPath(prefix2, keyName ?? "", nestedPaths);
19522
19538
  if (depth === 0) {
19523
19539
  top.push(left.name);
19524
19540
  if (propKey && keyName) propKey[left.name] = keyName;
19525
19541
  } else nested.push(left.name);
19542
+ } else if (left && (left.type === "ObjectPattern" || left.type === "ArrayPattern")) {
19543
+ patternValueKeyRule();
19544
+ collectPatternNames(
19545
+ v2,
19546
+ top,
19547
+ nested,
19548
+ depth,
19549
+ propKey,
19550
+ prefix2.concat(keyName ? [keyName] : []),
19551
+ nestedPaths
19552
+ );
19526
19553
  } else {
19527
- collectPatternNames(v2, top, nested, depth, propKey);
19528
- }
19554
+ collectPatternNames(v2, top, nested, depth, propKey, prefix2, nestedPaths);
19555
+ }
19556
+ } else if (v2.type === "ObjectPattern" || v2.type === "ArrayPattern") {
19557
+ patternValueKeyRule();
19558
+ collectPatternNames(
19559
+ v2,
19560
+ top,
19561
+ nested,
19562
+ depth + 1,
19563
+ propKey,
19564
+ prefix2.concat(keyName ? [keyName] : []),
19565
+ nestedPaths
19566
+ );
19529
19567
  } else {
19530
- collectPatternNames(v2, top, nested, depth + 1, propKey);
19568
+ collectPatternNames(v2, top, nested, depth + 1, propKey, prefix2, nestedPaths);
19531
19569
  }
19532
19570
  }
19533
19571
  return;
@@ -19539,9 +19577,9 @@ function collectPatternNames(p, top, nested, depth, propKey) {
19539
19577
  if (depth === 0) top.push(el.name);
19540
19578
  else nested.push(el.name);
19541
19579
  } else if (el.type === "AssignmentPattern") {
19542
- collectPatternNames(el, top, nested, depth, propKey);
19580
+ collectPatternNames(el, top, nested, depth, propKey, [], nestedPaths);
19543
19581
  } else {
19544
- collectPatternNames(el, top, nested, depth + 1, propKey);
19582
+ collectPatternNames(el, top, nested, depth + 1, propKey, [], nestedPaths);
19545
19583
  }
19546
19584
  }
19547
19585
  }
@@ -19560,13 +19598,15 @@ function formalParamsFromNodes(params) {
19560
19598
  const top2 = [];
19561
19599
  const nested2 = [];
19562
19600
  const propKey2 = {};
19563
- if (left) collectPatternNames(left, top2, nested2, 0, propKey2);
19601
+ const nestedPaths2 = [];
19602
+ if (left) collectPatternNames(left, top2, nested2, 0, propKey2, [], nestedPaths2);
19564
19603
  return {
19565
19604
  kind: "pattern",
19566
19605
  placeholder: `_p${index2}`,
19567
19606
  bound: top2,
19568
19607
  propKey: propKey2,
19569
19608
  nested: nested2,
19609
+ nestedPaths: nestedPaths2,
19570
19610
  index: index2
19571
19611
  };
19572
19612
  }
@@ -19578,13 +19618,15 @@ function formalParamsFromNodes(params) {
19578
19618
  const top = [];
19579
19619
  const nested = [];
19580
19620
  const propKey = {};
19581
- if (p) collectPatternNames(p, top, nested, 0, propKey);
19621
+ const nestedPaths = [];
19622
+ if (p) collectPatternNames(p, top, nested, 0, propKey, [], nestedPaths);
19582
19623
  return {
19583
19624
  kind: "pattern",
19584
19625
  placeholder: `_p${index2}`,
19585
19626
  bound: top,
19586
19627
  propKey,
19587
19628
  nested,
19629
+ nestedPaths,
19588
19630
  index: index2
19589
19631
  };
19590
19632
  });
@@ -19626,6 +19668,7 @@ function contractParamNameSet(formals) {
19626
19668
  out.add(f.placeholder);
19627
19669
  out.add("_");
19628
19670
  for (const b of f.bound) out.add(b);
19671
+ for (const np of f.nestedPaths) out.add(np);
19629
19672
  }
19630
19673
  }
19631
19674
  return out;
@@ -19643,10 +19686,16 @@ function locateContractParam(formals, contractName) {
19643
19686
  return { index: f.index };
19644
19687
  }
19645
19688
  if (f.bound.includes(contractName)) {
19646
- return { index: f.index, field: f.propKey?.[contractName] ?? contractName };
19689
+ const field = f.propKey?.[contractName] ?? contractName;
19690
+ return { index: f.index, field, fieldPath: [field] };
19647
19691
  }
19648
19692
  }
19649
19693
  }
19694
+ for (const f of formals) {
19695
+ if (f.kind === "pattern" && f.nestedPaths.includes(contractName)) {
19696
+ return { index: f.index, field: contractName, fieldPath: contractName.split(".") };
19697
+ }
19698
+ }
19650
19699
  return void 0;
19651
19700
  }
19652
19701
  var init_param_surface = __esm({
@@ -42869,10 +42918,33 @@ function generalizeFromAstUncached(fnName, source, opts = {}) {
42869
42918
  patternFields.set(hit.index, bag);
42870
42919
  }
42871
42920
  const fieldAbs = constraintToEntryAbs(e.constraint, e.param);
42872
- bag[hit.field] = {
42921
+ const leaf = {
42873
42922
  abs: fieldAbs,
42874
42923
  ...e.constraint.isOptional ? { optional: true } : {}
42875
42924
  };
42925
+ const segs = hit.fieldPath ?? [hit.field];
42926
+ if (segs.length <= 1) {
42927
+ bag[hit.field] = leaf;
42928
+ continue;
42929
+ }
42930
+ let level = bag;
42931
+ let skip2 = false;
42932
+ for (let i = 0; i < segs.length - 1; i++) {
42933
+ const node = level[segs[i]];
42934
+ if (node === void 0) {
42935
+ const sub2 = { slots: {} };
42936
+ level[segs[i]] = sub2;
42937
+ level = sub2.slots;
42938
+ } else if ("slots" in node) {
42939
+ level = node.slots;
42940
+ } else {
42941
+ skip2 = true;
42942
+ break;
42943
+ }
42944
+ }
42945
+ if (!skip2) {
42946
+ level[segs[segs.length - 1]] = leaf;
42947
+ }
42876
42948
  } else if (hit) {
42877
42949
  const entryAbs = constraintToEntryAbs(e.constraint, e.param);
42878
42950
  typeParams[hit.index] = {
@@ -42885,20 +42957,34 @@ function generalizeFromAstUncached(fnName, source, opts = {}) {
42885
42957
  });
42886
42958
  }
42887
42959
  }
42888
- for (const [pIdx, bag] of patternFields) {
42960
+ const sigNames = formalParamSignatureNames(formals);
42961
+ const buildPatternObjAbs = (slotsBag, sigName, walked) => {
42889
42962
  const slots = {};
42890
- for (const [key, rec] of Object.entries(bag)) {
42891
- slots[key] = {
42892
- value: rec.abs,
42893
- ...rec.optional ? { optional: true } : {}
42894
- };
42963
+ for (const [key, node] of Object.entries(slotsBag)) {
42964
+ if ("abs" in node) {
42965
+ slots[key] = {
42966
+ value: node.abs,
42967
+ ...node.optional ? { optional: true } : {}
42968
+ };
42969
+ } else {
42970
+ slots[key] = {
42971
+ value: buildPatternObjAbs(node.slots, sigName, [...walked, key])
42972
+ };
42973
+ }
42895
42974
  }
42896
- const objAbs2 = abs(
42975
+ return abs(
42897
42976
  { k: "obj", slots },
42898
- v(params[pIdx] ?? `_p${pIdx}`),
42977
+ v(walked.length === 0 ? sigName : `${sigName}.${walked.join(".")}`),
42899
42978
  void 0,
42900
42979
  "path"
42901
42980
  );
42981
+ };
42982
+ for (const [pIdx, bag] of patternFields) {
42983
+ const objAbs2 = buildPatternObjAbs(
42984
+ bag,
42985
+ sigNames[pIdx] ?? params[pIdx] ?? `_p${pIdx}`,
42986
+ []
42987
+ );
42902
42988
  typeParams[pIdx] = {
42903
42989
  id: typeParams[pIdx].id,
42904
42990
  value: objAbs2
@@ -43042,6 +43128,7 @@ function generalizeFromAstUncached(fnName, source, opts = {}) {
43042
43128
  }));
43043
43129
  }
43044
43130
  }
43131
+ const renderNames = formals.length > 0 ? formalParamSignatureNames(formals) : params;
43045
43132
  return {
43046
43133
  name: fnName,
43047
43134
  params,
@@ -43050,6 +43137,7 @@ function generalizeFromAstUncached(fnName, source, opts = {}) {
43050
43137
  instantiate: (args, phi2) => run(args, phi2 ?? pTrue),
43051
43138
  display: formatPoly(
43052
43139
  fnName,
43140
+ renderNames,
43053
43141
  params,
43054
43142
  typeParams,
43055
43143
  symbolic,
@@ -43064,12 +43152,13 @@ function generalizeFromAstUncached(fnName, source, opts = {}) {
43064
43152
  ...hofSites ? { hofSites } : {}
43065
43153
  };
43066
43154
  }
43067
- function formatPoly(name, params, typeParams, symbolic, entryReqs, entryShapes, fnRels) {
43155
+ function formatPoly(name, renderNames, params, typeParams, symbolic, entryReqs, entryShapes, fnRels) {
43068
43156
  const reqByParam = new Map((entryReqs ?? []).map((r) => [r.param, r.pred]));
43069
- const ps = params.map((p, i) => {
43157
+ const ps = renderNames.map((p, i) => {
43158
+ const key = params[i] ?? p;
43070
43159
  const id = typeParams[i]?.id ?? "unknown";
43071
- const pred = reqByParam.get(p);
43072
- const promoted = entryShapes?.get(p)?.abs ?? fnRels?.get(p)?.abs;
43160
+ const pred = reqByParam.get(key);
43161
+ const promoted = entryShapes?.get(key)?.abs ?? fnRels?.get(key)?.abs;
43073
43162
  if (promoted) {
43074
43163
  const slot = formatShapeSlot(promoted);
43075
43164
  if (pred && pred.op !== "true") {
@@ -44313,13 +44402,17 @@ function scanLiteralCalls(source, knownFns, phi2, opts) {
44313
44402
  eiCache.set(key, r);
44314
44403
  return r;
44315
44404
  };
44316
- const projectArgField = (arg, field) => {
44317
- if (!arg) return void 0;
44318
- if (arg.shape.k === "brand") {
44319
- return projectArgField(arg.shape.shape, field);
44405
+ const projectArgPath = (arg, segments) => {
44406
+ let cur = arg;
44407
+ for (const seg of segments) {
44408
+ if (!cur) return void 0;
44409
+ if (cur.shape.k === "brand") {
44410
+ cur = cur.shape.shape;
44411
+ }
44412
+ if (cur.shape.k !== "obj") return void 0;
44413
+ cur = getSlot(cur.shape.slots, seg)?.value;
44320
44414
  }
44321
- if (arg.shape.k !== "obj") return void 0;
44322
- return getSlot(arg.shape.slots, field)?.value;
44415
+ return cur;
44323
44416
  };
44324
44417
  const interfaceToIndexed = (ei, paramNames, formals) => {
44325
44418
  const conflict = new Set(ei.conflict?.params ?? []);
@@ -44341,7 +44434,7 @@ function scanLiteralCalls(source, knownFns, phi2, opts) {
44341
44434
  entries.push([
44342
44435
  hit.index,
44343
44436
  { param, pred: instantiateConstraint(constraint, param), constraint },
44344
- hit.field
44437
+ hit.fieldPath ?? (hit.field !== void 0 ? [hit.field] : void 0)
44345
44438
  ]);
44346
44439
  }
44347
44440
  }
@@ -44377,17 +44470,18 @@ function scanLiteralCalls(source, knownFns, phi2, opts) {
44377
44470
  return lv <= n;
44378
44471
  };
44379
44472
  const checkReqs = (displayName, reqs, paramNames, absArgs, argIndexOf, loc) => {
44380
- for (const [idx, pred, field, contractParam] of reqs) {
44473
+ for (const [idx, pred, fieldPath, contractParam] of reqs) {
44381
44474
  const argIdx = argIndexOf(idx);
44382
44475
  if (argIdx === void 0) continue;
44383
44476
  let arg = absArgs[argIdx];
44384
44477
  if (!arg) continue;
44385
44478
  const paramName2 = contractParam || paramNames[idx] || `arg${idx}`;
44386
- if (field) {
44387
- const projected = projectArgField(arg, field);
44479
+ if (fieldPath) {
44480
+ const projected = projectArgPath(arg, fieldPath);
44388
44481
  if (!projected) {
44389
44482
  const k = arg.shape.k;
44390
44483
  if (k !== "unknown" && k !== "any") {
44484
+ const field = fieldPath.join(".");
44391
44485
  out.push({
44392
44486
  severity: "error",
44393
44487
  code: "nudo:constraint-violated",
@@ -44728,7 +44822,7 @@ function scanLiteralCalls(source, knownFns, phi2, opts) {
44728
44822
  }
44729
44823
  };
44730
44824
  const checkShapeReqs = (displayName, reqs, paramNames, absArgs, argIndexOf, loc) => {
44731
- for (const [idx, entry, field] of reqs) {
44825
+ for (const [idx, entry, fieldPath] of reqs) {
44732
44826
  const c = entry.constraint;
44733
44827
  if (!c.fields && !c.element && !isIntFlag(c) && !c.prim) continue;
44734
44828
  const argIdx = argIndexOf(idx);
@@ -44736,11 +44830,12 @@ function scanLiteralCalls(source, knownFns, phi2, opts) {
44736
44830
  let arg = absArgs[argIdx];
44737
44831
  if (!arg) continue;
44738
44832
  const paramName2 = entry.param || paramNames[idx] || `arg${idx}`;
44739
- if (field) {
44740
- const projected = projectArgField(arg, field);
44833
+ if (fieldPath) {
44834
+ const projected = projectArgPath(arg, fieldPath);
44741
44835
  if (!projected) {
44742
44836
  const k = arg.shape.k;
44743
44837
  if (k !== "unknown" && k !== "any") {
44838
+ const field = fieldPath.join(".");
44744
44839
  out.push({
44745
44840
  severity: "error",
44746
44841
  code: "nudo:constraint-violated",
@@ -46131,13 +46226,17 @@ var init_check_assign = __esm({
46131
46226
  });
46132
46227
 
46133
46228
  // ../core/src/algebra/check-case-scan.ts
46134
- function projectCaseArgField(arg, field) {
46135
- if (!arg) return void 0;
46136
- if (arg.shape.k === "brand") {
46137
- return projectCaseArgField(arg.shape.shape, field);
46229
+ function projectCaseArgField(arg, fieldPath) {
46230
+ let cur = arg;
46231
+ for (const seg of fieldPath) {
46232
+ if (!cur) return void 0;
46233
+ if (cur.shape.k === "brand") {
46234
+ cur = cur.shape.shape;
46235
+ }
46236
+ if (cur.shape.k !== "obj") return void 0;
46237
+ cur = getSlot(cur.shape.slots, seg)?.value;
46138
46238
  }
46139
- if (arg.shape.k !== "obj") return void 0;
46140
- return getSlot(arg.shape.slots, field)?.value;
46239
+ return cur;
46141
46240
  }
46142
46241
  function scanCaseInconsistency(source, knownFns, opts) {
46143
46242
  const out = [];
@@ -46218,12 +46317,12 @@ function scanCaseInconsistency(source, knownFns, opts) {
46218
46317
  for (const p of eff.params) {
46219
46318
  if (conflictParams.has(p.param)) continue;
46220
46319
  let idx = paramNames.indexOf(p.param);
46221
- let field;
46320
+ let fieldPath;
46222
46321
  if (idx < 0 && formals.length > 0) {
46223
46322
  const hit = locateContractParam(formals, p.param);
46224
46323
  if (hit) {
46225
46324
  idx = hit.index;
46226
- field = hit.field;
46325
+ fieldPath = hit.fieldPath ?? (hit.field !== void 0 ? [hit.field] : void 0);
46227
46326
  }
46228
46327
  }
46229
46328
  if (idx < 0) continue;
@@ -46234,7 +46333,7 @@ function scanCaseInconsistency(source, knownFns, opts) {
46234
46333
  pred: instantiateConstraint(p.constraint, p.param),
46235
46334
  constraint: p.constraint
46236
46335
  },
46237
- field
46336
+ fieldPath
46238
46337
  ]);
46239
46338
  }
46240
46339
  if (reqs.length === 0) return;
@@ -46242,16 +46341,17 @@ function scanCaseInconsistency(source, knownFns, opts) {
46242
46341
  for (const req of reqs) {
46243
46342
  const idx = req[0];
46244
46343
  const entry = req[1];
46245
- const field = req[2];
46344
+ const fieldPath = req[2];
46246
46345
  if (entry.constraint.fields) continue;
46247
46346
  let arg = absArgs[idx];
46248
46347
  if (!arg) continue;
46249
- if (field) {
46250
- const projected = projectCaseArgField(arg, field);
46348
+ if (fieldPath) {
46349
+ const projected = projectCaseArgField(arg, fieldPath);
46251
46350
  if (!projected) {
46252
46351
  const k = arg.shape.k;
46253
46352
  if (k !== "unknown" && k !== "any") {
46254
46353
  const paramName2 = entry.param || paramNames[idx] || `arg${idx}`;
46354
+ const field = fieldPath.join(".");
46255
46355
  out.push({
46256
46356
  severity: "error",
46257
46357
  code: "nudo:case-inconsistency",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nudojs",
3
- "version": "1.3.16",
3
+ "version": "1.3.17",
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.9.3",
50
- "@nudojs/env": "0.4.30",
51
- "@nudojs/harvester": "0.3.16",
52
- "@nudojs/parser": "1.4.12",
53
- "@nudojs/service": "1.6.15",
49
+ "@nudojs/core": "1.9.4",
50
+ "@nudojs/env": "0.4.31",
51
+ "@nudojs/harvester": "0.3.17",
52
+ "@nudojs/parser": "1.4.13",
53
+ "@nudojs/service": "1.6.16",
54
54
  "commander": "^15.0.0"
55
55
  },
56
56
  "devDependencies": {