@neocompose/cli 0.89.7 → 0.89.9

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.
@@ -7354,42 +7354,6 @@ function descendantClassIdsInChildIndex(classId, childrenByClassId) {
7354
7354
  }
7355
7355
  return result;
7356
7356
  }
7357
- function addDependentMemberIds(memberIds, members2) {
7358
- const childIdsByParentId = /* @__PURE__ */ new Map();
7359
- const entryIdsByOwnerId = /* @__PURE__ */ new Map();
7360
- const remainingOwnersByEntryId = /* @__PURE__ */ new Map();
7361
- for (const member of members2) {
7362
- if (member.extendsMemberId) {
7363
- const children3 = childIdsByParentId.get(member.extendsMemberId);
7364
- if (children3 === void 0) {
7365
- childIdsByParentId.set(member.extendsMemberId, [member.id]);
7366
- } else children3.push(member.id);
7367
- }
7368
- const entries = member.elementMemberIds ?? (member.entryMemberId ? [member.entryMemberId] : []);
7369
- if (entries.length > 0) {
7370
- entryIdsByOwnerId.set(member.id, entries);
7371
- for (const entryId of entries)
7372
- remainingOwnersByEntryId.set(
7373
- entryId,
7374
- (remainingOwnersByEntryId.get(entryId) ?? 0) + 1
7375
- );
7376
- }
7377
- }
7378
- const pending = [...memberIds];
7379
- function include(memberId) {
7380
- if (memberIds.has(memberId)) return;
7381
- memberIds.add(memberId);
7382
- pending.push(memberId);
7383
- }
7384
- for (let id2 = pending.pop(); id2 !== void 0; id2 = pending.pop()) {
7385
- for (const childId of childIdsByParentId.get(id2) ?? []) include(childId);
7386
- for (const entryId of entryIdsByOwnerId.get(id2) ?? []) {
7387
- const remainingOwners = remainingOwnersByEntryId.get(entryId) - 1;
7388
- remainingOwnersByEntryId.set(entryId, remainingOwners);
7389
- if (remainingOwners === 0) include(entryId);
7390
- }
7391
- }
7392
- }
7393
7357
  var UnresolvedMemberInheritanceError, NO_CLASSES, NO_MEMBERS, resolvedClassSchemas;
7394
7358
  var init_inheritance = __esm({
7395
7359
  "../packages/models/src/classes/inheritance.ts"() {
@@ -19407,7 +19371,7 @@ var init_registry = __esm({
19407
19371
  "../packages/manifest/schema-contract/registry.mjs"() {
19408
19372
  "use strict";
19409
19373
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
19410
- cliVersion: "0.89.7",
19374
+ cliVersion: "0.89.9",
19411
19375
  projectFileUploadBatchSize: 32,
19412
19376
  documentRecords: {
19413
19377
  member: {
@@ -24412,7 +24376,7 @@ function mayUseLocalInitializer(text, names2) {
24412
24376
  }
24413
24377
  return false;
24414
24378
  }
24415
- function localInitializerUses(expression) {
24379
+ function localInitializerUses(expression, options = {}) {
24416
24380
  const uses = [];
24417
24381
  const pending = [
24418
24382
  { node: expression, owned: true, path: { parent: void 0, key: "" } }
@@ -24431,7 +24395,12 @@ function localInitializerUses(expression) {
24431
24395
  const keys = [];
24432
24396
  for (let step = path; step?.parent !== void 0; step = step.parent)
24433
24397
  keys.push(step.key);
24434
- uses.push({ node, owned, path: path === null ? null : keys.reverse() });
24398
+ uses.push({
24399
+ node,
24400
+ owned,
24401
+ path: path === null ? null : keys.reverse(),
24402
+ ...current.reference ? { reference: true } : {}
24403
+ });
24435
24404
  break;
24436
24405
  }
24437
24406
  case "annotated":
@@ -24479,8 +24448,18 @@ function localInitializerUses(expression) {
24479
24448
  }
24480
24449
  break;
24481
24450
  case "call":
24482
- if (node.callee.kind === "ident" && node.callee.name === "Reference")
24451
+ if (node.callee.kind === "ident" && node.callee.name === "Reference") {
24452
+ if (options.includeReferences && node.args.length === 1 && node.args[0]?.kind === "ident" && node.argumentNames?.[0] == null) {
24453
+ pending.push({
24454
+ node: node.args[0],
24455
+ owned: false,
24456
+ path: null,
24457
+ bound,
24458
+ reference: true
24459
+ });
24460
+ }
24483
24461
  break;
24462
+ }
24484
24463
  add([node.callee, ...node.args], false);
24485
24464
  break;
24486
24465
  case "member":
@@ -24525,10 +24504,10 @@ function applyInitializerCodeSplices(code, splices) {
24525
24504
  parts.push(code.slice(offset));
24526
24505
  return parts.join("");
24527
24506
  }
24528
- function rewriteLocalInitializerUses(code, replace) {
24507
+ function rewriteLocalInitializerUses(code, replace, options = {}) {
24529
24508
  const source = new SourceText(code);
24530
24509
  const splices = [];
24531
- for (const use of localInitializerUses(parseExpression(code))) {
24510
+ for (const use of localInitializerUses(parseExpression(code), options)) {
24532
24511
  const text = replace(use);
24533
24512
  if (text === null) continue;
24534
24513
  const start = source.offsetAt({
@@ -24634,10 +24613,27 @@ function validateExecutableLocalUses(documents, localExpressions) {
24634
24613
  }
24635
24614
  }
24636
24615
  if (locals.size === 0) return [];
24637
- const aliases = /* @__PURE__ */ new Map();
24616
+ const terminalNames = /* @__PURE__ */ new Map();
24617
+ const terminalName = (name) => {
24618
+ const chain = /* @__PURE__ */ new Set();
24619
+ let terminal2 = name;
24620
+ while (!chain.has(terminal2)) {
24621
+ const cached = terminalNames.get(terminal2);
24622
+ if (cached !== void 0) {
24623
+ terminal2 = cached;
24624
+ break;
24625
+ }
24626
+ chain.add(terminal2);
24627
+ const expression = localExpressions.get(terminal2);
24628
+ if (expression?.kind !== "ident" || !locals.has(expression.name)) break;
24629
+ terminal2 = expression.name;
24630
+ }
24631
+ for (const alias of chain) terminalNames.set(alias, terminal2);
24632
+ return terminal2;
24633
+ };
24638
24634
  const uses = [];
24639
24635
  const owners = /* @__PURE__ */ new Map();
24640
- const add = (text, uri, origin, parent, staticOwner, template = false, shadowed = /* @__PURE__ */ new Set()) => {
24636
+ const add = (text, uri, origin, parent, template = false, shadowed = /* @__PURE__ */ new Set()) => {
24641
24637
  if (!mayUseLocalInitializer(text, locals)) return;
24642
24638
  let expression;
24643
24639
  try {
@@ -24645,10 +24641,8 @@ function validateExecutableLocalUses(documents, localExpressions) {
24645
24641
  } catch {
24646
24642
  return;
24647
24643
  }
24648
- if (parent !== void 0) {
24649
- if (expression.kind === "ident" && locals.has(expression.name))
24650
- aliases.set(parent, expression.name);
24651
- }
24644
+ if (parent !== void 0 && expression.kind === "ident" && locals.has(expression.name))
24645
+ return;
24652
24646
  for (const { node, owned } of localInitializerUses(expression)) {
24653
24647
  if (!locals.has(node.name) || shadowed.has(node.name)) continue;
24654
24648
  const start = {
@@ -24661,14 +24655,14 @@ function validateExecutableLocalUses(documents, localExpressions) {
24661
24655
  uri,
24662
24656
  start,
24663
24657
  parent,
24664
- staticOwner: expression === node ? staticOwner : void 0,
24665
24658
  template
24666
24659
  };
24667
24660
  uses.push(use);
24668
24661
  if (owned) {
24669
- const entries = owners.get(node.name) ?? [];
24662
+ const terminal2 = terminalName(node.name);
24663
+ const entries = owners.get(terminal2) ?? [];
24670
24664
  entries.push(use);
24671
- owners.set(node.name, entries);
24665
+ owners.set(terminal2, entries);
24672
24666
  }
24673
24667
  }
24674
24668
  };
@@ -24684,7 +24678,6 @@ function validateExecutableLocalUses(documents, localExpressions) {
24684
24678
  uri,
24685
24679
  member.initializer.range.start,
24686
24680
  void 0,
24687
- isStatic ? `${declaration.name}.${member.name}` : void 0,
24688
24681
  !isStatic,
24689
24682
  new Set(
24690
24683
  declaration.headerParameters?.map((parameter4) => parameter4.name)
@@ -24721,23 +24714,20 @@ function validateExecutableLocalUses(documents, localExpressions) {
24721
24714
  const placements = /* @__PURE__ */ new Map();
24722
24715
  const active = /* @__PURE__ */ new Set();
24723
24716
  const placement = (name) => {
24717
+ name = terminalName(name);
24724
24718
  const cached = placements.get(name);
24725
24719
  if (cached !== void 0) return cached;
24726
- if (active.has(name))
24727
- return { count: 0, template: false, staticOwner: void 0 };
24720
+ if (active.has(name)) return { count: 0, template: false };
24728
24721
  active.add(name);
24729
24722
  const result = {
24730
24723
  count: 0,
24731
- template: false,
24732
- staticOwner: void 0
24724
+ template: false
24733
24725
  };
24734
24726
  for (const owner of owners.get(name) ?? []) {
24735
24727
  const parent = owner.parent === void 0 ? void 0 : placement(owner.parent);
24736
24728
  if (parent?.count === 0) continue;
24737
24729
  result.count += parent?.count ?? 1;
24738
24730
  result.template ||= parent?.template ?? owner.template;
24739
- const alias = owner.parent !== void 0 && aliases.get(owner.parent) === name;
24740
- result.staticOwner = alias ? parent?.staticOwner : owner.staticOwner;
24741
24731
  if (result.count > 1) break;
24742
24732
  }
24743
24733
  active.delete(name);
@@ -24763,22 +24753,6 @@ function validateExecutableLocalUses(documents, localExpressions) {
24763
24753
  if (declaration.kind === "enum") scalarTypes.add(declaration.name);
24764
24754
  }
24765
24755
  }
24766
- const identities = /* @__PURE__ */ new Map();
24767
- const resolving = /* @__PURE__ */ new Set();
24768
- const hasIdentity = (name) => {
24769
- const cached = identities.get(name);
24770
- if (cached !== void 0) return cached;
24771
- if (resolving.has(name)) return false;
24772
- resolving.add(name);
24773
- const alias = aliases.get(name);
24774
- const expression = localExpressions.get(name);
24775
- const identified = alias !== void 0 ? hasIdentity(alias) : locals.get(name).annotations.some((annotation2) => annotation2.name === "id") || expression?.kind === "annotated" && expression.annotations.some(
24776
- (annotation2) => annotation2.name === "id"
24777
- );
24778
- resolving.delete(name);
24779
- identities.set(name, identified);
24780
- return identified;
24781
- };
24782
24756
  const reportedOwners = /* @__PURE__ */ new Set();
24783
24757
  for (const use of uses) {
24784
24758
  const declaration = locals.get(use.name);
@@ -24807,13 +24781,6 @@ function validateExecutableLocalUses(documents, localExpressions) {
24807
24781
  );
24808
24782
  continue;
24809
24783
  }
24810
- const hasId = hasIdentity(use.name);
24811
- if (!hasId && owner.staticOwner === void 0) {
24812
- report(
24813
- use,
24814
- `Local initializer ${use.name} has no stable instance identity. Keep an @id on its nested owning value, or place it directly in a static member before referencing it.`
24815
- );
24816
- }
24817
24784
  if (owner.template) {
24818
24785
  report(
24819
24786
  use,
@@ -25265,6 +25232,7 @@ var init_local_values = __esm({
25265
25232
  /** Static members whose initializer is a bare local name, by that name. */
25266
25233
  ownerMembers = /* @__PURE__ */ new Map();
25267
25234
  scalarTypes;
25235
+ pendingReferences = /* @__PURE__ */ new Map();
25268
25236
  resolve(expression, source, valueId) {
25269
25237
  if (expression.kind !== "ident") return { expression, source };
25270
25238
  let text;
@@ -25331,12 +25299,55 @@ var init_local_values = __esm({
25331
25299
  executable(code, runtimeIdentifiers = /* @__PURE__ */ new Set(), materializationRoot, identity3, storedValueAtPath) {
25332
25300
  if (this.definitions.size === 0 || !mayUseLocalInitializer(code, this.definitions))
25333
25301
  return { code, splices: [] };
25302
+ const terminalName = (name) => {
25303
+ this.inline(name);
25304
+ return this.terminalInitializers.get(name)?.global.name ?? name;
25305
+ };
25306
+ const owned = /* @__PURE__ */ new Set();
25307
+ const read = /* @__PURE__ */ new Set();
25308
+ const scanned = /* @__PURE__ */ new Set();
25309
+ const usedNames = new Set(runtimeIdentifiers);
25310
+ const scan = (text, runtimeNames) => {
25311
+ for (const match of text.matchAll(/[A-Za-z_]\w*/g))
25312
+ usedNames.add(match[0]);
25313
+ for (const use of localInitializerUses(
25314
+ parseCachedInitializer(this.syntax?.expressions, text),
25315
+ { includeReferences: true }
25316
+ )) {
25317
+ if (!this.has(use.node.name) || runtimeNames.has(use.node.name))
25318
+ continue;
25319
+ const name = terminalName(use.node.name);
25320
+ if (!use.owned) {
25321
+ read.add(name);
25322
+ continue;
25323
+ }
25324
+ owned.add(name);
25325
+ if (scanned.has(name)) continue;
25326
+ scanned.add(name);
25327
+ scan(this.inline(name).text, /* @__PURE__ */ new Set());
25328
+ }
25329
+ };
25330
+ scan(code, runtimeIdentifiers);
25331
+ const shared = /* @__PURE__ */ new Map();
25332
+ for (const name of owned) {
25333
+ if (!read.has(name) || this.scalarTypes.has(this.definitions.get(name).type.name))
25334
+ continue;
25335
+ let variable2 = `__neo_owned_${shared.size}`;
25336
+ while (usedNames.has(variable2) || this.definitions.has(variable2) || runtimeIdentifiers.has(variable2))
25337
+ variable2 += "_";
25338
+ usedNames.add(variable2);
25339
+ shared.set(name, variable2);
25340
+ }
25341
+ const bindings = /* @__PURE__ */ new Map();
25334
25342
  const active = /* @__PURE__ */ new Set();
25335
25343
  const expand = (text, path, runtimeNames) => rewriteLocalInitializerUses(
25336
25344
  text,
25337
- ({ node, owned, path: relativePath }) => {
25345
+ ({ node, owned: owned2, path: relativePath, reference: reference2 }) => {
25338
25346
  if (!this.has(node.name) || runtimeNames.has(node.name)) return null;
25339
- if (!owned) {
25347
+ if (!owned2) {
25348
+ const variable3 = shared.get(terminalName(node.name));
25349
+ if (variable3 !== void 0) return variable3;
25350
+ if (reference2) return null;
25340
25351
  const definition2 = this.definitions.get(node.name);
25341
25352
  if (this.scalarTypes.has(definition2.type.name)) {
25342
25353
  throw new Error(
@@ -25362,9 +25373,13 @@ var init_local_values = __esm({
25362
25373
  const annotation2 = terminal2.expression.kind === "annotated" ? terminal2.expression.annotations.find(
25363
25374
  (entry) => entry.name === "id"
25364
25375
  )?.args[0] : void 0;
25365
- if (annotation2?.kind === "litString" && storedValueAtPath?.(materializationRoot, placementPath) !== annotation2.value) {
25376
+ const existingId = storedValueAtPath?.(
25377
+ materializationRoot,
25378
+ placementPath
25379
+ );
25380
+ if (annotation2?.kind === "litString" && existingId !== annotation2.value) {
25366
25381
  throw new Error(
25367
- `Local initializer ${terminal2.global.name} has an @id that does not identify its existing row inside this constructor-backed owner. Remove that @id and push its owning tree before referencing the local, or place the value directly in its own static member.`
25382
+ `Local initializer ${terminal2.global.name} has an @id that does not identify its existing row inside this constructor-backed owner. Remove that @id and let preparation assign the owning tree, or place the value directly in its own static member.`
25368
25383
  );
25369
25384
  }
25370
25385
  const source = terminal2.global.source;
@@ -25372,7 +25387,7 @@ var init_local_values = __esm({
25372
25387
  const id2 = annotation2?.kind === "litString" ? annotation2.value : `__pending__:value:${encodeURIComponent(source.uri)}:${source.range.start.line}:${source.range.start.character}:${encodeURIComponent(terminal2.global.name)}${suffix}`;
25373
25388
  for (const { global } of steps) {
25374
25389
  const owners = this.owners.get(global.name) ?? /* @__PURE__ */ new Map();
25375
- owners.set(id2, global.name);
25390
+ owners.set(existingId ?? id2, global.name);
25376
25391
  this.owners.set(global.name, owners);
25377
25392
  }
25378
25393
  identity3?.sites.set(id2, {
@@ -25391,10 +25406,50 @@ var init_local_values = __esm({
25391
25406
  });
25392
25407
  }
25393
25408
  active.delete(node.name);
25409
+ const name = terminalName(node.name);
25410
+ const variable2 = shared.get(name);
25411
+ if (variable2 !== void 0) {
25412
+ bindings.set(variable2, {
25413
+ code: result,
25414
+ type: typeText(this.definitions.get(name).type)
25415
+ });
25416
+ return variable2;
25417
+ }
25394
25418
  return result;
25395
- }
25419
+ },
25420
+ { includeReferences: true }
25396
25421
  );
25397
- return expand(code, [], runtimeIdentifiers);
25422
+ const expanded = expand(code, [], runtimeIdentifiers);
25423
+ if (bindings.size === 0) return expanded;
25424
+ const ordered = [];
25425
+ const visited = /* @__PURE__ */ new Set();
25426
+ const visit = (variable2) => {
25427
+ if (visited.has(variable2)) return;
25428
+ visited.add(variable2);
25429
+ for (const use of localInitializerUses(
25430
+ parseCachedInitializer(
25431
+ this.syntax?.expressions,
25432
+ bindings.get(variable2).code
25433
+ ),
25434
+ { includeReferences: true }
25435
+ )) {
25436
+ if (bindings.has(use.node.name)) visit(use.node.name);
25437
+ }
25438
+ ordered.push(variable2);
25439
+ };
25440
+ for (const variable2 of bindings.keys()) visit(variable2);
25441
+ const declarations = ordered.map((variable2) => {
25442
+ const binding = bindings.get(variable2);
25443
+ return `${binding.type} ${variable2} = ${binding.code};`;
25444
+ });
25445
+ const bound = `(() => {
25446
+ ${declarations.join("\n")}
25447
+ return ${expanded.code};
25448
+ })()`;
25449
+ return {
25450
+ code: bound,
25451
+ splices: [{ start: 0, end: code.length, text: bound }]
25452
+ };
25398
25453
  }
25399
25454
  initializer(global) {
25400
25455
  const cached = this.initializers.get(global.name);
@@ -25439,7 +25494,8 @@ var init_local_values = __esm({
25439
25494
  * lowered, so the answer does not depend on which file lowered first: the
25440
25495
  * `@id` its declaration carries (through any alias chain), else the static
25441
25496
  * member whose initializer is the local, whose row derives from the member.
25442
- * `null` for a local no push has identified yet.
25497
+ * Nested idless locals use a temporary reference resolved after their owners
25498
+ * lower. Constructor-backed owners settle it to the materialized child ID.
25443
25499
  */
25444
25500
  declaredTarget(name) {
25445
25501
  const definition2 = this.definitions.get(name);
@@ -25452,7 +25508,11 @@ var init_local_values = __esm({
25452
25508
  return { id: id2.value, typeName };
25453
25509
  }
25454
25510
  const owners = this.ownerMembers.get(name);
25455
- if (owners === void 0) return null;
25511
+ if (owners === void 0) {
25512
+ const locator = `__pending__:local-reference:${encodeURIComponent(name)}`;
25513
+ this.pendingReferences.set(locator, name);
25514
+ return { id: locator, typeName };
25515
+ }
25456
25516
  if (owners.length !== 1) {
25457
25517
  throw new Error(
25458
25518
  `Reference(${name}) requires exactly one owning assignment.`
@@ -25461,8 +25521,25 @@ var init_local_values = __esm({
25461
25521
  const owner = owners[0];
25462
25522
  return { ownerMemberId: owner.memberId, ownerPath: owner.path, typeName };
25463
25523
  }
25524
+ remapTargets(replacements) {
25525
+ for (const owners of this.owners.values()) {
25526
+ for (const [id2, label] of [...owners]) {
25527
+ const target = replacements.get(id2);
25528
+ if (target === void 0) continue;
25529
+ owners.delete(id2);
25530
+ owners.set(target, label);
25531
+ }
25532
+ }
25533
+ }
25534
+ referenceTargets() {
25535
+ return new Map(
25536
+ [...this.pendingReferences].map(([id2, name]) => [id2, this.target(name)])
25537
+ );
25538
+ }
25464
25539
  target(name) {
25465
- const owners = this.owners.get(name);
25540
+ this.inline(name);
25541
+ const terminal2 = this.terminalInitializers.get(name)?.global.name ?? name;
25542
+ const owners = this.owners.get(terminal2);
25466
25543
  if (owners?.size !== 1)
25467
25544
  throw new Error(
25468
25545
  `Reference(${name}) requires exactly one owning assignment.`
@@ -28481,15 +28558,7 @@ function calculateDeclarationSignature(ctx, projectionClassId, schemaKey, declar
28481
28558
  declarationClassId: declaration.classDef.id,
28482
28559
  memberId: declaration.memberId,
28483
28560
  isAbstract: isAbstractMember(member) === true,
28484
- isVirtual: isVirtualMember(member) !== false,
28485
- // Openness belongs to the DECLARING class, not to whoever is asking: a
28486
- // descendant that closes the param still has to see a declaration it is
28487
- // obliged to implement.
28488
- requiresClosingImplementation: lookupDeclaredTypeInfo(member) === null ? false : lookupNarrowingAwaitsClosingBinding(
28489
- ctx,
28490
- member,
28491
- resolveGenericEnvForEmission(ctx, declaration.classDef.id)
28492
- )
28561
+ isVirtual: isVirtualMember(member) !== false
28493
28562
  };
28494
28563
  if (isCallableMemberForCodegen(member)) {
28495
28564
  const parameterTypes = member.argumentTypes.map(
@@ -28699,7 +28768,7 @@ function generatedInstanceMemberSignaturesEqual(left, right) {
28699
28768
  return false;
28700
28769
  }
28701
28770
  function emitsAbstractDeclaration(signature2) {
28702
- return signature2.isAbstract || signature2.requiresClosingImplementation;
28771
+ return signature2.isAbstract;
28703
28772
  }
28704
28773
  function resolveGeneratedInstanceMemberPlan(ctx, classDef, schemaKey) {
28705
28774
  const declaration = ownInstanceMemberDeclaration(classDef, schemaKey);
@@ -30892,11 +30961,6 @@ function lookupHasRuntimeOwnership(member) {
30892
30961
  function lookupNarrowsThroughGenericParam(member) {
30893
30962
  return lookupDeclaredTypeInfo(member)?.type === 21 /* Generic */;
30894
30963
  }
30895
- function lookupNarrowingAwaitsClosingBinding(ctx, member, env) {
30896
- if (!lookupNarrowsThroughGenericParam(member)) return false;
30897
- if (lookupProjection(ctx, member) !== "class" /* Class */) return false;
30898
- return lookupTargetClassProjection(ctx, member, env) === null;
30899
- }
30900
30964
  function lookupTargetValueType(ctx, member, saved, env) {
30901
30965
  if (!isMemberLookupBase(member)) return "NeoLookupSelection";
30902
30966
  const targetSaved = lookupTargetSaved(ctx, member) ?? saved;
@@ -34611,7 +34675,7 @@ var init_canonical_json = __esm({
34611
34675
  });
34612
34676
 
34613
34677
  // ../packages/neoscript-runtime/src/neoscript/initializer-dependencies.ts
34614
- function materializeInitializerDependencies(pending, materialize) {
34678
+ function materializeInitializerDependencies(pending, materialize, onFailure) {
34615
34679
  const active = /* @__PURE__ */ new Set();
34616
34680
  for (const rootId of pending) {
34617
34681
  const stack = [rootId];
@@ -34624,19 +34688,27 @@ function materializeInitializerDependencies(pending, materialize) {
34624
34688
  active.delete(valueId);
34625
34689
  stack.pop();
34626
34690
  } catch (error) {
34627
- if (!(error instanceof PendingInitializerDependency)) throw error;
34628
- if (!pending.has(error.valueId)) throw error;
34629
- if (active.has(error.valueId)) {
34691
+ if (error instanceof PendingInitializerDependency && pending.has(error.valueId)) {
34692
+ if (!active.has(error.valueId)) {
34693
+ active.add(error.valueId);
34694
+ stack.push(error.valueId);
34695
+ continue;
34696
+ }
34630
34697
  const cycle = new NSGetterRuntimeError(
34631
34698
  `Initializer dependency cycle: ${[...stack, error.valueId].join(" -> ")}. Remove a dependency so these values can be initialized in order.`
34632
34699
  );
34633
34700
  cycle.initializerValueId = valueId;
34634
34701
  cycle.node = error.node;
34635
34702
  cycle.source = error.source;
34636
- throw cycle;
34703
+ error = cycle;
34704
+ }
34705
+ if (onFailure === void 0) throw error;
34706
+ onFailure(stack, error);
34707
+ for (const id2 of stack) {
34708
+ pending.delete(id2);
34709
+ active.delete(id2);
34637
34710
  }
34638
- active.add(error.valueId);
34639
- stack.push(error.valueId);
34711
+ stack.length = 0;
34640
34712
  }
34641
34713
  }
34642
34714
  }
@@ -39374,6 +39446,7 @@ function indexRuntimeCollectionChange(collection, entry, ctx, removedEntries = n
39374
39446
  indexes4.memberByRowId.clear();
39375
39447
  }
39376
39448
  if (Array.isArray(collection)) forgetLocalListIndexes(ctx, collection);
39449
+ else indexes4.declaredListByArray = /* @__PURE__ */ new WeakMap();
39377
39450
  markOverlayMutated(ctx, collection);
39378
39451
  if (ctx.__valueOverlay instanceof LazyValueOverlay)
39379
39452
  indexes4.overlayRevision = ctx.__valueOverlay.revision;
@@ -40831,11 +40904,10 @@ function remapRuntimeReferences(value, overlay2, seen, preservedReferences) {
40831
40904
  const next = {};
40832
40905
  seen.set(value, next);
40833
40906
  for (const [key, entry] of Object.entries(value)) {
40834
- next[key] = remapRuntimeReferences(
40835
- entry,
40836
- overlay2,
40837
- seen,
40838
- preservedReferences
40907
+ setOwnField(
40908
+ next,
40909
+ key,
40910
+ remapRuntimeReferences(entry, overlay2, seen, preservedReferences)
40839
40911
  );
40840
40912
  }
40841
40913
  return next;
@@ -42635,7 +42707,7 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
42635
42707
  if (entryId !== null) {
42636
42708
  const collection = Array.isArray(receiver) ? receiver : objectArg(receiver, "Assignment target");
42637
42709
  const entryKey = typeof key === "number" ? key : String(key);
42638
- Reflect.set(collection, String(entryKey), entryId);
42710
+ setOwnField(collection, String(entryKey), entryId);
42639
42711
  recordWrittenEntry(collection, entryKey, true, ctx);
42640
42712
  if (!indexRuntimeCollectionChange(
42641
42713
  collection,
@@ -42731,7 +42803,7 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
42731
42803
  );
42732
42804
  noteDetachedRow(object2[stringKey], referenceValueId, ctx);
42733
42805
  }
42734
- object2[stringKey] = referenceValueId;
42806
+ setOwnField(object2, stringKey, referenceValueId);
42735
42807
  if (!field) recordWrittenEntry(object2, stringKey, true, ctx);
42736
42808
  if (field || !indexRuntimeCollectionEntryWrite(
42737
42809
  object2,
@@ -42747,7 +42819,7 @@ function applyOverlayAssignment(target, targetTypeInfo, value, scope, ctx, desti
42747
42819
  return;
42748
42820
  if (field && (targetTypeInfo.type === 7 /* Class */ || targetTypeInfo.type === 22 /* Interface */))
42749
42821
  noteDetachedRow(object2[stringKey], value, ctx);
42750
- object2[stringKey] = value;
42822
+ setOwnField(object2, stringKey, value);
42751
42823
  if (!field) recordWrittenEntry(object2, stringKey, false, ctx);
42752
42824
  const scalarField = (previous == null || typeof previous === "number" || typeof previous === "boolean" || typeof previous === "string") && (value == null || typeof value === "number" || typeof value === "boolean" || typeof value === "string");
42753
42825
  if (field && !scalarField || !indexRuntimeCollectionEntryWrite(object2, previous, value, stringKey, ctx))
@@ -42829,7 +42901,7 @@ function copiedCollectionContents(source, entryTypeInfo, slotId, ctx) {
42829
42901
  }
42830
42902
  }
42831
42903
  if (Array.isArray(copy)) copy.push(entry);
42832
- else copy[String(key)] = entry;
42904
+ else setOwnField(copy, String(key), entry);
42833
42905
  return 0 /* Continue */;
42834
42906
  });
42835
42907
  const cache = unorderedListProjectionCache(ctx);
@@ -42898,107 +42970,6 @@ function keepAssignedCollectionValues(value, targetTypeInfo, row, ctx) {
42898
42970
  return 0 /* Continue */;
42899
42971
  });
42900
42972
  }
42901
- function pendingConstructorRootsForRow(valueId, ctx) {
42902
- const roots = /* @__PURE__ */ new Set();
42903
- const open2 = ctx.__executionState?.openConstructions;
42904
- if (open2 === void 0 || open2.size === 0) return roots;
42905
- const visited = /* @__PURE__ */ new Set();
42906
- const pending = [valueId];
42907
- const parentEntries = /* @__PURE__ */ new Map();
42908
- const placingMembers = /* @__PURE__ */ new Map();
42909
- while (pending.length > 0) {
42910
- const id2 = pending.pop();
42911
- if (id2 === void 0 || visited.has(id2)) continue;
42912
- visited.add(id2);
42913
- const row = evalValueById(
42914
- ctx,
42915
- id2,
42916
- ctx.__runtimeSessionValues,
42917
- ctx.__valueOverlay
42918
- );
42919
- if (row === null) continue;
42920
- if (typeof row.value === "object" && row.value !== null && open2.has(row.value))
42921
- roots.add(id2);
42922
- for (const owner of currentOwnedValueAttachments(
42923
- id2,
42924
- ctx,
42925
- parentEntries,
42926
- placingMembers
42927
- )) {
42928
- if (!owner.identity.startsWith("value:")) continue;
42929
- const parent = evalValueById(
42930
- ctx,
42931
- owner.label,
42932
- ctx.__runtimeSessionValues,
42933
- ctx.__valueOverlay
42934
- );
42935
- if (parent === null) continue;
42936
- if (parent.classId === void 0 || parent.classId === null) {
42937
- const raw = placingMember(
42938
- parent,
42939
- ctx,
42940
- void 0,
42941
- 0,
42942
- placingMembers,
42943
- parentEntries
42944
- );
42945
- if (raw === null) continue;
42946
- const member = raw.kind === 21 /* Generic */ ? substituteMember(raw, rowGenericEnv(parent, ctx), ctx.vm.members) : resolveMember(raw, ctx.vm.members);
42947
- if (isMemberWithEntries(member)) {
42948
- const rawEntry = evalMemberById(ctx.vm, member.entryMemberId);
42949
- if (rawEntry === null) continue;
42950
- const entry = rawEntry.kind === 21 /* Generic */ ? substituteMember(
42951
- rawEntry,
42952
- rowGenericEnv(parent, ctx),
42953
- ctx.vm.members
42954
- ) : resolveMember(rawEntry, ctx.vm.members);
42955
- if (entry.kind === 21 /* Generic */ || isMemberLookupBase(entry))
42956
- continue;
42957
- }
42958
- }
42959
- pending.push(owner.label);
42960
- }
42961
- for (const link of evaluatorParentLinks(evaluatorIndexes(ctx), id2)) {
42962
- const parent = evalValueById(
42963
- ctx,
42964
- link.parentId,
42965
- ctx.__runtimeSessionValues,
42966
- ctx.__valueOverlay
42967
- );
42968
- if (parent === null || !Array.isArray(parent.value)) continue;
42969
- const member = placingMember(
42970
- parent,
42971
- ctx,
42972
- void 0,
42973
- 0,
42974
- placingMembers,
42975
- parentEntries
42976
- );
42977
- if (member === null || !isMemberTupleBase(member)) continue;
42978
- const positions = ownershipParentEntryKeys(
42979
- parent.value,
42980
- id2,
42981
- parentEntries
42982
- );
42983
- for (const position of positions ?? []) {
42984
- if (typeof position !== "number") continue;
42985
- const entryId = member.elementMemberIds[position];
42986
- const rawEntry = entryId === void 0 ? null : evalMemberById(ctx.vm, entryId);
42987
- if (rawEntry === null) continue;
42988
- const entry = rawEntry.kind === 21 /* Generic */ ? substituteMember(
42989
- rawEntry,
42990
- rowGenericEnv(parent, ctx),
42991
- ctx.vm.members
42992
- ) : resolveMember(rawEntry, ctx.vm.members);
42993
- if (entry.kind === 21 /* Generic */ || isMemberLookupBase(entry))
42994
- continue;
42995
- pending.push(parent.id);
42996
- break;
42997
- }
42998
- }
42999
- }
43000
- return roots;
43001
- }
43002
42973
  function preflightAssignedCollection(collection, member, row, ctx) {
43003
42974
  if (member === null) return;
43004
42975
  const env = rowGenericEnv(row, ctx);
@@ -43011,8 +42982,6 @@ function preflightAssignedCollection(collection, member, row, ctx) {
43011
42982
  const attached = /* @__PURE__ */ new Set();
43012
42983
  const preflight = {
43013
42984
  parentEntries: /* @__PURE__ */ new Map(),
43014
- constructorRootIds: pendingConstructorRootsForRow(row.id, ctx),
43015
- constructorArgumentTransfers: /* @__PURE__ */ new Map(),
43016
42985
  dependencies: /* @__PURE__ */ new Map()
43017
42986
  };
43018
42987
  forEachRawCollectionEntry(collection, ctx, ({ raw, key, valueId }) => {
@@ -43035,8 +43004,6 @@ function preflightAssignedCollection(collection, member, row, ctx) {
43035
43004
  );
43036
43005
  return 0 /* Continue */;
43037
43006
  });
43038
- for (const [id2, destination] of preflight.constructorArgumentTransfers)
43039
- ctx.__executionState?.ownedValueAttachments.set(id2, destination);
43040
43007
  for (const [id2, destination] of preflight.dependencies)
43041
43008
  recordConstructorGroupDependency(id2, destination, ctx);
43042
43009
  }
@@ -43064,6 +43031,7 @@ function replaceRowValue(row, value, receiver, ctx) {
43064
43031
  unindexEvaluatorRow(indexes4, row, true);
43065
43032
  row.value = value;
43066
43033
  indexEvaluatorRow(indexes4, row, true);
43034
+ indexes4.declaredListByArray = /* @__PURE__ */ new WeakMap();
43067
43035
  markOverlayMutated(ctx, receiver);
43068
43036
  if (ctx.__valueOverlay instanceof LazyValueOverlay)
43069
43037
  indexes4.overlayRevision = ctx.__valueOverlay.revision;
@@ -44874,7 +44842,11 @@ function applyLocalCollectionMutation(targetValue, mutation, args, ctx, unique =
44874
44842
  }
44875
44843
  return null;
44876
44844
  }
44877
- objectArg(targetValue, "Dictionary Add target")[String(args[0])] = args[1];
44845
+ setOwnField(
44846
+ objectArg(targetValue, "Dictionary Add target"),
44847
+ String(args[0]),
44848
+ args[1]
44849
+ );
44878
44850
  return null;
44879
44851
  case "Remove" /* Remove */:
44880
44852
  if (Array.isArray(targetValue)) {
@@ -47298,6 +47270,17 @@ function runtimeTypeCheck(value, checkType, ctx, seenCollections = /* @__PURE__
47298
47270
  case 8 /* Enum */:
47299
47271
  return Array.isArray(value) && value.every((v) => typeof v === "string");
47300
47272
  case 7 /* Class */: {
47273
+ if (isVariantClassId(checkType.classId)) {
47274
+ if (!isVariantRefValue(value)) return false;
47275
+ const targetParameter = evaluatorSchemaIndex(ctx).classesById.get(
47276
+ checkType.classId
47277
+ )?.genericParams?.[0];
47278
+ const target = targetParameter === void 0 ? void 0 : receiverClosedTypeArguments(checkType.typeArguments, ctx)?.[targetParameter.id];
47279
+ return target?.type !== 7 /* Class */ || evaluatorSchemaIndex(ctx).classIsOrExtends(
47280
+ value.classId,
47281
+ target.classId
47282
+ );
47283
+ }
47301
47284
  if (typeof value !== "object") return false;
47302
47285
  const row = trackedRowForValueReference(value, ctx);
47303
47286
  const runtimeClassId = row === null ? void 0 : classIdForValueRow(row, ctx);
@@ -51206,6 +51189,7 @@ function publishConstructedRows(args) {
51206
51189
  if (beforeRetain !== null) {
51207
51190
  for (const rowId of beforeRetain) {
51208
51191
  if (retained.has(rowId)) continue;
51192
+ if (constructorGroupForRow(rowId, ctx) !== null) continue;
51209
51193
  deleteRuntimeSessionValue(ctx, rowId);
51210
51194
  }
51211
51195
  }
@@ -51291,16 +51275,55 @@ function assertImplicitConstructionAllowed(schemaClass2) {
51291
51275
  `Class '${schemaClass2.name}' declares a required constructor, so it cannot be constructed without one.`
51292
51276
  );
51293
51277
  }
51278
+ function constructionReplayContext(descriptor, ctx) {
51279
+ if (ctx.storedConstructionReplay !== true) return ctx;
51280
+ const target = ctx.__storedInitializerReplay;
51281
+ let rowId;
51282
+ let candidate;
51283
+ if (target !== void 0) {
51284
+ const row = storedReplayRowById(target.rowId, ctx);
51285
+ if (row !== null && classIdForValueRow(row, ctx) === descriptor.schemaClass.id) {
51286
+ rowId = target.rowId;
51287
+ candidate = { reattached: false };
51288
+ target.candidates.push(candidate);
51289
+ }
51290
+ } else if (ctx.__executionState?.constructionStack.length === 0 && ctx.__storedConstructionReplaySlot?.classId === descriptor.schemaClass.id) {
51291
+ rowId = ctx.__storedConstructionReplayRowId;
51292
+ }
51293
+ return {
51294
+ ...ctx,
51295
+ __storedInitializerReplay: void 0,
51296
+ __storedReplayCandidate: candidate,
51297
+ __storedConstructionReplayRowId: rowId,
51298
+ __storedConstructionReplayRootId: void 0,
51299
+ __storedConstructionReplaySlot: rowId === void 0 ? ctx.__storedConstructionReplaySlot : {
51300
+ classId: descriptor.schemaClass.id,
51301
+ classArguments: descriptor.classArguments ?? {}
51302
+ }
51303
+ };
51304
+ }
51305
+ function rollbackStoredConstructionReplay(ctx, checkpoint) {
51306
+ if (checkpoint === void 0) return;
51307
+ for (const row of createdSessionValuesSince(ctx, checkpoint))
51308
+ deleteRuntimeSessionValue(ctx, row.id);
51309
+ if (ctx.__storedReplayCandidate !== void 0)
51310
+ ctx.__storedReplayCandidate.reattached = false;
51311
+ }
51294
51312
  function constructClassValue(info, scope, ctx) {
51295
51313
  const descriptor = validateClassConstructorDescriptor(
51296
51314
  info,
51297
51315
  ctx,
51298
51316
  ctx.constructionBaselineReplay !== true
51299
51317
  );
51318
+ ctx = constructionReplayContext(descriptor, ctx);
51300
51319
  assertImplicitConstructionAllowed(descriptor.schemaClass);
51320
+ const replayCheckpoint = ctx.__storedConstructionReplayRowId === void 0 ? void 0 : sessionCreationCheckpoint(ctx);
51301
51321
  const closeFrame = pushConstructionFrame(ctx, descriptor.schemaClass.name);
51302
51322
  try {
51303
51323
  return constructClassValueWithinFrame(descriptor, scope, ctx);
51324
+ } catch (error) {
51325
+ rollbackStoredConstructionReplay(ctx, replayCheckpoint);
51326
+ throw error;
51304
51327
  } finally {
51305
51328
  closeFrame();
51306
51329
  }
@@ -51400,6 +51423,8 @@ function constructClassValueWithinFrame(descriptor, scope, ctx) {
51400
51423
  });
51401
51424
  root.classId = classId;
51402
51425
  stampConstructedRootGenericBindings(root, descriptor);
51426
+ if (ctx.__storedReplayCandidate !== void 0)
51427
+ ctx.__storedReplayCandidate.value = root.value;
51403
51428
  if (typeof root.value !== "object" || root.value === null || Array.isArray(root.value)) {
51404
51429
  throw new Error(
51405
51430
  `Class constructor for '${schemaClass2.name}' produced a non-record root.`
@@ -51829,15 +51854,20 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
51829
51854
  sourceValueId: sourceValueId ?? null,
51830
51855
  compileMemberId: scopeMemberId
51831
51856
  });
51857
+ const childId = storedInitializerChildId(member, ctx);
51858
+ const initializerCtx = childId === void 0 ? ctx : {
51859
+ ...ctx,
51860
+ __storedInitializerReplay: { rowId: childId, candidates: [] }
51861
+ };
51832
51862
  const evaluate = (argumentValues = []) => {
51833
- return withConstructionGenericSlots(
51863
+ const result = withConstructionGenericSlots(
51834
51864
  member,
51835
- ctx,
51865
+ initializerCtx,
51836
51866
  genericEnv,
51837
51867
  () => evaluateInitializerInContext(
51838
51868
  init,
51839
51869
  member,
51840
- ctx,
51870
+ initializerCtx,
51841
51871
  createdValues,
51842
51872
  argumentValues,
51843
51873
  sourceValueId ?? null,
@@ -51845,6 +51875,17 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
51845
51875
  genericEnv
51846
51876
  )
51847
51877
  );
51878
+ for (const candidate of initializerCtx.__storedInitializerReplay?.candidates ?? []) {
51879
+ if (!candidate.reattached) continue;
51880
+ if (candidate.value !== result.value) {
51881
+ throw new NSGetterRuntimeError(
51882
+ `Stored initializer '${member.name}' constructed an already owned value outside its returned child. Call Clone() explicitly.`
51883
+ );
51884
+ }
51885
+ if (ctx.__storedReplayCandidate !== void 0)
51886
+ ctx.__storedReplayCandidate.reattached = true;
51887
+ }
51888
+ return result;
51848
51889
  };
51849
51890
  const ownerClassId = scopeMemberId === null ? null : owningClassId(scopeMemberId);
51850
51891
  const expectedArgumentCount = compiled.parameters.slice(2).length;
@@ -52057,6 +52098,13 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
52057
52098
  (argument2) => trackedRowForValueReference(argument2, ctx)?.id === existingValueRow.id
52058
52099
  )) {
52059
52100
  assertInitializerPlacement(existingValueRow.id, member, ctx);
52101
+ if (storedInitializerChildId(member, ctx) === existingValueRow.id) {
52102
+ return {
52103
+ value: result.value,
52104
+ classId: existingRuntimeClassId,
52105
+ existingValueRow
52106
+ };
52107
+ }
52060
52108
  }
52061
52109
  if (existingValueRow !== null && existingRuntimeClassId !== null && isClassSlotMember(member)) {
52062
52110
  const storage = constructorArgumentStorage(existingValueRow.id, ctx);
@@ -52260,18 +52308,14 @@ function encodeRequiredConstructorArgument(args) {
52260
52308
  args.ctx.__valueOverlay
52261
52309
  ) !== null ? args.value : null;
52262
52310
  const adoptTracked = (id2, suffix) => {
52263
- if (constructorGroupForRow(id2, args.ctx) !== null) {
52264
- assertOwnedValueAttachable(
52265
- id2,
52266
- {
52267
- identity: `value:${args.ownerRootId}:constructorArg:${args.parameterId}:${suffix}`,
52268
- label: args.ownerRootId
52269
- },
52270
- `constructor argument '${args.parameterId}'`,
52271
- args.ctx,
52272
- true
52273
- );
52274
- }
52311
+ recordConstructorGroupDependency(
52312
+ id2,
52313
+ {
52314
+ identity: `value:${args.ownerRootId}:constructorArg:${args.parameterId}:${suffix}`,
52315
+ label: args.ownerRootId
52316
+ },
52317
+ args.ctx
52318
+ );
52275
52319
  return id2;
52276
52320
  };
52277
52321
  if (args.typeInfo.type === 21 /* Generic */) {
@@ -52279,6 +52323,21 @@ function encodeRequiredConstructorArgument(args) {
52279
52323
  `Constructor argument '${args.parameterId}' has an unresolved generic type.`
52280
52324
  );
52281
52325
  }
52326
+ if (args.typeInfo.type === 7 /* Class */ && isVariantClassId(args.typeInfo.classId)) {
52327
+ if (args.value === null || args.value === void 0) return null;
52328
+ const selection2 = readVariantSelection(
52329
+ args.value,
52330
+ `Constructor argument '${args.parameterId}'`
52331
+ );
52332
+ if (selection2.rowValueId !== null) {
52333
+ adoptTracked(selection2.rowValueId, "variant-row");
52334
+ }
52335
+ return {
52336
+ classId: selection2.classId,
52337
+ variantId: selection2.variantId,
52338
+ ...selection2.rowValueId === null ? {} : { rowValueId: selection2.rowValueId }
52339
+ };
52340
+ }
52282
52341
  if (args.typeInfo.type === 7 /* Class */ || args.typeInfo.type === 22 /* Interface */) {
52283
52342
  if (args.value === null || args.value === void 0) return null;
52284
52343
  const aggregateId2 = trackedId ?? replayedAggregateId;
@@ -53192,7 +53251,8 @@ function constructDeclaredClassValue(info, scope, ctx) {
53192
53251
  const descriptor = validateClassConstructorDescriptor(info, ctx, false);
53193
53252
  const schemaClass2 = descriptor.schemaClass;
53194
53253
  const record7 = resolveDeclaredConstructorRecord(info, schemaClass2, ctx);
53195
- const replayCheckpoint = ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === schemaClass2.id && ctx.__executionState?.constructionStack.length === 0 ? sessionCreationCheckpoint(ctx) : void 0;
53254
+ ctx = constructionReplayContext(descriptor, ctx);
53255
+ const replayCheckpoint = ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === schemaClass2.id ? sessionCreationCheckpoint(ctx) : void 0;
53196
53256
  const closeFrame = pushConstructionFrame(ctx, schemaClass2.name);
53197
53257
  try {
53198
53258
  return constructDeclaredClassValueWithinFrame(
@@ -53203,11 +53263,7 @@ function constructDeclaredClassValue(info, scope, ctx) {
53203
53263
  ctx
53204
53264
  );
53205
53265
  } catch (error) {
53206
- if (replayCheckpoint !== void 0) {
53207
- for (const row of createdSessionValuesSince(ctx, replayCheckpoint)) {
53208
- deleteRuntimeSessionValue(ctx, row.id);
53209
- }
53210
- }
53266
+ rollbackStoredConstructionReplay(ctx, replayCheckpoint);
53211
53267
  throw error;
53212
53268
  } finally {
53213
53269
  closeFrame();
@@ -53268,6 +53324,8 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
53268
53324
  });
53269
53325
  root.classId = classId;
53270
53326
  stampConstructedRootGenericBindings(root, descriptor);
53327
+ if (ctx.__storedReplayCandidate !== void 0)
53328
+ ctx.__storedReplayCandidate.value = root.value;
53271
53329
  } catch (error) {
53272
53330
  if (error instanceof NSGetterRuntimeError) {
53273
53331
  positionAtPassingArgument(error, info, record7, argumentValues, ctx);
@@ -53280,7 +53338,7 @@ function constructDeclaredClassValueWithinFrame(descriptor, record7, info, scope
53280
53338
  `Declared constructor for '${schemaClass2.name}' produced a non-record root.`
53281
53339
  );
53282
53340
  }
53283
- if (ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === classId && ctx.__executionState?.constructionStack.length === 1) {
53341
+ if (ctx.storedConstructionReplay === true && ctx.__storedConstructionReplayRowId !== void 0 && ctx.__storedConstructionReplaySlot?.classId === classId) {
53284
53342
  ctx = { ...ctx, __storedConstructionReplayRootId: root.id };
53285
53343
  }
53286
53344
  const rootRecord = root.value;
@@ -53444,8 +53502,13 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
53444
53502
  ctx,
53445
53503
  preflight?.parentEntries
53446
53504
  )) {
53447
- if (mode === "assign" && ownedAttachmentIdentity(owner, ctx) === ownedAttachmentIdentity(destination, ctx))
53505
+ if (mode === "assign" && ownedAttachmentIdentity(owner, ctx) === ownedAttachmentIdentity(destination, ctx)) {
53506
+ if (ctx.__storedReplayCandidate !== void 0 && ctx.__storedConstructionReplayRowId !== void 0 && owner.identity.startsWith(
53507
+ `value:${ctx.__storedConstructionReplayRowId}:slot:`
53508
+ ))
53509
+ ctx.__storedReplayCandidate.reattached = true;
53448
53510
  continue;
53511
+ }
53449
53512
  const error = new NSGetterRuntimeError(
53450
53513
  `Aggregate value '${valueId}' is already owned by parent value '${owner.label}' and cannot be attached to '${destinationName2}'. Call Clone() explicitly.`
53451
53514
  );
@@ -53454,23 +53517,6 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
53454
53517
  }
53455
53518
  const reserved = ctx.__executionState?.ownedValueAttachments.get(valueId);
53456
53519
  if (reserved !== void 0 && (mode === "insert" || reserved.identity !== destination.identity)) {
53457
- const constructorArgumentReservation = reserved.identity.startsWith(
53458
- `value:${reserved.label}:constructorArg:`
53459
- );
53460
- const destinationConstructorGroup = constructorGroupForRow(
53461
- destination.label,
53462
- ctx
53463
- );
53464
- if (constructorArgumentReservation && (destination.label === reserved.label || destinationConstructorGroup === reserved.label || preflight?.constructorRootIds.has(reserved.label) === true)) {
53465
- if (preflight === void 0) {
53466
- ctx.__executionState?.ownedValueAttachments.set(valueId, destination);
53467
- recordConstructorGroupDependency(valueId, destination, ctx);
53468
- } else {
53469
- preflight.constructorArgumentTransfers.set(valueId, destination);
53470
- preflight.dependencies.set(valueId, destination);
53471
- }
53472
- return;
53473
- }
53474
53520
  throw new NSGetterRuntimeError(
53475
53521
  `Aggregate value '${valueId}' is already owned by parent value '${reserved.label}' and cannot be attached to '${destinationName2}'. Call Clone() explicitly.`
53476
53522
  );
@@ -53482,6 +53528,29 @@ function assertOwnedValueAttachable(valueId, destination, destinationName2, ctx,
53482
53528
  recordConstructorGroupDependency(valueId, destination, ctx);
53483
53529
  else preflight.dependencies.set(valueId, destination);
53484
53530
  }
53531
+ function storedReplayRowById(id2, ctx) {
53532
+ ctx.valueDependencies?.add(id2);
53533
+ ctx.__getterReads?.add(id2);
53534
+ const database = ctx.vm.databaseVM;
53535
+ if (database?.storedValueById !== void 0)
53536
+ return database.storedValueById(id2);
53537
+ if (database?.evaluatorIndexes !== void 0)
53538
+ return database.evaluatorIndexes.valueById.get(id2) ?? null;
53539
+ return ctx.vm.values.find((row) => row.id === id2) ?? null;
53540
+ }
53541
+ function storedInitializerChildId(member, ctx) {
53542
+ if (ctx.storedConstructionReplay !== true) return void 0;
53543
+ const parentId = ctx.__storedConstructionReplayRowId;
53544
+ const memberId = Reflect.get(member, "id");
53545
+ if (parentId === void 0 || typeof memberId !== "string") return void 0;
53546
+ const parent = storedReplayRowById(parentId, ctx);
53547
+ if (parent?.value === null || typeof parent?.value !== "object")
53548
+ return void 0;
53549
+ const schemaKey = cachedSchemaKeyForMember(memberId, ctx);
53550
+ if (schemaKey === null) return void 0;
53551
+ const childId = Reflect.get(parent.value, schemaKey);
53552
+ return typeof childId === "string" ? childId : void 0;
53553
+ }
53485
53554
  function assertInitializerPlacement(valueId, member, ctx) {
53486
53555
  const replayRowId = ctx.__storedConstructionReplayRowId;
53487
53556
  const memberId = Reflect.get(member, "id");
@@ -53518,7 +53587,7 @@ function ownershipParentEntryKeys(value, valueId, cache) {
53518
53587
  }
53519
53588
  return entries.get(valueId) ?? [];
53520
53589
  }
53521
- function currentOwnedValueAttachments(valueId, ctx, parentEntries, placingMembers) {
53590
+ function currentOwnedValueAttachments(valueId, ctx, parentEntries) {
53522
53591
  const indexes4 = evaluatorIndexes(ctx);
53523
53592
  const cached = indexes4.ownedValueAttachmentsByValueId.get(valueId);
53524
53593
  if (cached !== void 0) return [...cached];
@@ -53581,14 +53650,7 @@ function currentOwnedValueAttachments(valueId, ctx, parentEntries, placingMember
53581
53650
  let member = null;
53582
53651
  let classId = parent.classId;
53583
53652
  if (classId === void 0 || classId === null) {
53584
- member = activeStaticBindingRoot(parent.id, ctx)?.member ?? (placingMembers === void 0 ? memberForValueRow(parent, ctx) : placingMember(
53585
- parent,
53586
- ctx,
53587
- void 0,
53588
- 0,
53589
- placingMembers,
53590
- parentEntries
53591
- ));
53653
+ member = activeStaticBindingRoot(parent.id, ctx)?.member ?? memberForValueRow(parent, ctx);
53592
53654
  if (member !== null) {
53593
53655
  try {
53594
53656
  member = resolveMember(member, ctx.vm.members);
@@ -57052,22 +57114,29 @@ var init_lookup_declared_type = __esm({
57052
57114
  });
57053
57115
 
57054
57116
  // ../packages/neoscript-runtime/src/values/member-declared-type-info.ts
57055
- function resolveMemberDeclaredTypeInfo(member, members2, ownerClass = null, env) {
57117
+ function resolveMemberDeclaredTypeInfo(member, members2, classes, ownerClass = null, env) {
57056
57118
  return resolveMemberDeclaredTypeInfoInternal(
57057
57119
  member,
57058
57120
  members2,
57121
+ classes,
57059
57122
  /* @__PURE__ */ new Set(),
57060
57123
  ownerClass,
57061
57124
  env,
57062
57125
  ownerClass === null ? void 0 : classConstrainedGenerics([ownerClass])
57063
57126
  );
57064
57127
  }
57065
- function resolveMemberDeclaredTypeInfoInternal(member, members2, seen, ownerClass, env, isClassConstrained) {
57128
+ function resolveMemberDeclaredTypeInfoInternal(member, members2, classes, seen, ownerClass, env, isClassConstrained) {
57066
57129
  const resolved = env === void 0 ? resolveMember(member, members2) : substituteMember(member, env, members2);
57067
57130
  const memberId = getField(resolved, "id");
57068
57131
  if (typeof memberId === "string" && seen.has(memberId)) return null;
57069
57132
  const nextSeen = typeof memberId === "string" ? /* @__PURE__ */ new Set([...seen, memberId]) : new Set(seen);
57070
57133
  if (isMemberNSPropertyBase(resolved)) return resolved.returnTypeInfo;
57134
+ if (isMemberVariantBase(resolved)) {
57135
+ return variantMemberDeclaredTypeInfo(
57136
+ resolved,
57137
+ neoVariantSystemClass(classes, resolved.valueTypeInfo != null)
57138
+ );
57139
+ }
57071
57140
  if (isClassSlotMember(resolved)) {
57072
57141
  const typeArguments = Object.fromEntries(
57073
57142
  Object.entries(declaredSlotArguments(resolved) ?? {}).flatMap(
@@ -57087,6 +57156,7 @@ function resolveMemberDeclaredTypeInfoInternal(member, members2, seen, ownerClas
57087
57156
  const argumentType2 = resolveMemberDeclaredTypeInfoInternal(
57088
57157
  argumentMember,
57089
57158
  members2,
57159
+ classes,
57090
57160
  nextSeen,
57091
57161
  ownerClass,
57092
57162
  env,
@@ -57157,6 +57227,7 @@ function resolveMemberDeclaredTypeInfoInternal(member, members2, seen, ownerClas
57157
57227
  const typeInfo = resolveMemberDeclaredTypeInfoInternal(
57158
57228
  descriptor,
57159
57229
  members2,
57230
+ classes,
57160
57231
  nextSeen,
57161
57232
  ownerClass,
57162
57233
  env,
@@ -57185,6 +57256,7 @@ function resolveMemberDeclaredTypeInfoInternal(member, members2, seen, ownerClas
57185
57256
  const entryTypeInfo = resolveMemberDeclaredTypeInfoInternal(
57186
57257
  entry,
57187
57258
  members2,
57259
+ classes,
57188
57260
  nextSeen,
57189
57261
  ownerClass,
57190
57262
  env,
@@ -57209,6 +57281,7 @@ function resolveMemberDeclaredTypeInfoInternal(member, members2, seen, ownerClas
57209
57281
  return resolveMemberDeclaredTypeInfoInternal(
57210
57282
  collection,
57211
57283
  members2,
57284
+ classes,
57212
57285
  nextSeen,
57213
57286
  ownerClass,
57214
57287
  env,
@@ -57257,6 +57330,7 @@ var init_member_declared_type_info = __esm({
57257
57330
  init_inheritance();
57258
57331
  init_parameter_defaults();
57259
57332
  init_core();
57333
+ init_variant_member();
57260
57334
  }
57261
57335
  });
57262
57336
 
@@ -57265,6 +57339,15 @@ function recordEntries(value) {
57265
57339
  if (typeof value !== "object" || value === null) return [];
57266
57340
  return Object.values(value);
57267
57341
  }
57342
+ function isVariantArgument(value, typeInfo) {
57343
+ return typeInfo?.type === 7 /* Class */ && isVariantClassId(typeInfo.classId) && isVariantRefValue(value);
57344
+ }
57345
+ function remapVariantArgument(value, typeInfo, remap) {
57346
+ if (!isVariantArgument(value, typeInfo)) return value;
57347
+ if (typeof value.rowValueId !== "string") return value;
57348
+ const rowValueId = remap(value.rowValueId);
57349
+ return rowValueId === value.rowValueId ? value : { ...value, rowValueId };
57350
+ }
57268
57351
  function resolveSemanticOwnerMembersForValues(document, targetValueIds, additionalRoots, rootOwners, rootKinds, graphOf = () => new MaterializedValueGraphContext(
57269
57352
  document,
57270
57353
  void 0,
@@ -57576,7 +57659,11 @@ function tryResolveTypeInfo(document, rawTypeInfo, env) {
57576
57659
  function tryMemberTypeInfo(document, rawMember, env) {
57577
57660
  try {
57578
57661
  const member = substituteMember(rawMember, env, document.members);
57579
- const typeInfo = resolveMemberDeclaredTypeInfo(member, document.members);
57662
+ const typeInfo = resolveMemberDeclaredTypeInfo(
57663
+ member,
57664
+ document.members,
57665
+ document.classes
57666
+ );
57580
57667
  if (typeInfo === null) return null;
57581
57668
  return tryResolveTypeInfo(document, typeInfo, env);
57582
57669
  } catch {
@@ -57616,6 +57703,7 @@ var init_constructor_argument_ownership = __esm({
57616
57703
  init_core();
57617
57704
  init_interface_implementers();
57618
57705
  init_members();
57706
+ init_reference_category();
57619
57707
  init_neoscript();
57620
57708
  init_project_schema_index();
57621
57709
  init_member_declared_type_info();
@@ -57856,7 +57944,7 @@ var init_constructor_argument_ownership = __esm({
57856
57944
  const typeInfo = parameterTypes.get(parameterId);
57857
57945
  return [
57858
57946
  parameterId,
57859
- typeInfo !== void 0 && (isAggregateTypeInfo(typeInfo) || typeInfo.type === 29 /* Reference */) && typeof argument2 === "string" ? rewriteId(argument2) : argument2
57947
+ typeInfo !== void 0 && (isAggregateTypeInfo(typeInfo) || typeInfo.type === 29 /* Reference */) && typeof argument2 === "string" ? rewriteId(argument2) : remapVariantArgument(argument2, typeInfo, rewriteId)
57860
57948
  ];
57861
57949
  }
57862
57950
  )
@@ -57892,15 +57980,18 @@ var init_constructor_argument_ownership = __esm({
57892
57980
  ids.push(edge.targetValueId);
57893
57981
  return ids;
57894
57982
  }
57895
- /** The targets a row's Reference creation data names (P112 §1.1). */
57983
+ /** Reference targets and bound lookup rows retained by creation data. */
57896
57984
  referenceArgumentIds(row) {
57897
57985
  if (!isLiteralValueContent(row)) return [];
57898
57986
  const args = row.constructorArgs;
57899
57987
  if (args === void 0 || args === null) return [];
57900
57988
  const ids = [];
57901
- for (const parameterId of this.referenceParameterIds(row)) {
57989
+ for (const [parameterId, typeInfo] of this.constructorParameterTypes(row)) {
57902
57990
  const argument2 = args[parameterId];
57903
- if (typeof argument2 === "string") ids.push(argument2);
57991
+ if (typeInfo.type === 29 /* Reference */ && typeof argument2 === "string")
57992
+ ids.push(argument2);
57993
+ else if (isVariantArgument(argument2, typeInfo) && typeof argument2.rowValueId === "string")
57994
+ ids.push(argument2.rowValueId);
57904
57995
  }
57905
57996
  return ids;
57906
57997
  }
@@ -57909,23 +58000,23 @@ var init_constructor_argument_ownership = __esm({
57909
58000
  const args = row.constructorArgs;
57910
58001
  if (args === void 0 || args === null) return args;
57911
58002
  let remapped;
57912
- for (const parameterId of this.referenceParameterIds(
58003
+ for (const [parameterId, typeInfo] of this.constructorParameterTypes(
57913
58004
  row,
57914
58005
  contextualMember
57915
58006
  )) {
57916
58007
  const argument2 = args[parameterId];
57917
- if (typeof argument2 !== "string") continue;
57918
- const target = remap(argument2);
58008
+ const target = typeInfo.type === 29 /* Reference */ && typeof argument2 === "string" ? remap(argument2) : remapVariantArgument(argument2, typeInfo, remap);
57919
58009
  if (target !== argument2) (remapped ??= { ...args })[parameterId] = target;
57920
58010
  }
57921
58011
  return remapped ?? args;
57922
58012
  }
57923
- *referenceParameterIds(row, contextualMember) {
57924
- for (const [parameterId, typeInfo] of this.constructorParameterTypes(
57925
- row,
57926
- contextualMember
57927
- ))
57928
- if (typeInfo.type === 29 /* Reference */) yield parameterId;
58013
+ *variantArgumentSelections(row) {
58014
+ if (!isLiteralValueContent(row)) return;
58015
+ if (row.constructorArgs == null) return;
58016
+ for (const [parameterId, typeInfo] of this.constructorParameterTypes(row)) {
58017
+ const argument2 = row.constructorArgs[parameterId];
58018
+ if (isVariantArgument(argument2, typeInfo)) yield argument2;
58019
+ }
57929
58020
  }
57930
58021
  slotEntries(row) {
57931
58022
  const value = row.value;
@@ -58026,6 +58117,17 @@ var init_constructor_argument_ownership = __esm({
58026
58117
  if (member === void 0) return null;
58027
58118
  return this.memberTypeInfo(member, env);
58028
58119
  }
58120
+ if ((rawTypeInfo.type === 7 /* Class */ || rawTypeInfo.type === 22 /* Interface */) && rawTypeInfo.typeArguments !== void 0) {
58121
+ const typeArguments = {};
58122
+ for (const [parameterId, argument2] of Object.entries(
58123
+ rawTypeInfo.typeArguments
58124
+ )) {
58125
+ const resolved = this.resolveTypeInfo(argument2, env);
58126
+ if (resolved === null) return null;
58127
+ typeArguments[parameterId] = resolved;
58128
+ }
58129
+ return { ...rawTypeInfo, typeArguments };
58130
+ }
58029
58131
  if (rawTypeInfo.type === 30 /* Tuple */) {
58030
58132
  const elements = [];
58031
58133
  for (const element of rawTypeInfo.elements) {
@@ -58057,7 +58159,8 @@ var init_constructor_argument_ownership = __esm({
58057
58159
  const member = substituteMember(rawMember, env, this.document.members);
58058
58160
  const typeInfo = resolveMemberDeclaredTypeInfo(
58059
58161
  member,
58060
- this.document.members
58162
+ this.document.members,
58163
+ this.document.classes
58061
58164
  );
58062
58165
  return typeInfo === null ? null : this.resolveTypeInfo(typeInfo, env);
58063
58166
  } catch {
@@ -63152,7 +63255,7 @@ function indexedInitializerEvaluatorLookups(document, key, revision) {
63152
63255
  });
63153
63256
  return lookups;
63154
63257
  }
63155
- function createInitializerMaterializationBatch(authoredDocument, pendingInitializerIds) {
63258
+ function createInitializerMaterializationBatch(authoredDocument, pendingInitializerIds, referenceOwners) {
63156
63259
  const indexed = createInitializerBatchLookups(authoredDocument);
63157
63260
  let hasListenerMetadata;
63158
63261
  const unorderedListEntryIds2 = indexed.snapshot().unorderedListEntryIds;
@@ -63302,7 +63405,12 @@ function createInitializerMaterializationBatch(authoredDocument, pendingInitiali
63302
63405
  base.valueById(id2),
63303
63406
  (id3) => virtual().declarationDefaultGraph(id3, member)
63304
63407
  ),
63305
- valueById: (id2) => base.valueById(id2) ?? expandedById.get(id2) ?? virtual().valueById(id2),
63408
+ valueById: (id2) => {
63409
+ const owner = referenceOwners?.get(id2);
63410
+ if (owner !== void 0 && pendingInitializerIds?.has(owner))
63411
+ throw new PendingInitializerDependency(owner);
63412
+ return base.valueById(id2) ?? expandedById.get(id2) ?? virtual().valueById(id2);
63413
+ },
63306
63414
  rowForValueReference: (value) => base.rowForValueReference(value) ?? expandedByReference.get(value) ?? virtual().rowForValueReference(value),
63307
63415
  virtualInstanceRowsForValue: (id2) => {
63308
63416
  const cached = cachedById.get(id2);
@@ -63682,13 +63790,37 @@ function derivedGenericArgumentMemberId(parentRecordId, genericParamId) {
63682
63790
  )
63683
63791
  );
63684
63792
  }
63685
- var NEO_GENERIC_ARGUMENT_MEMBER_NAMESPACE;
63793
+ function pendingGenericArgumentMemberId(parentRecordId, genericParamId) {
63794
+ return `${PENDING_GENERIC_ARGUMENT_PREFIX}${encodeURIComponent(parentRecordId)}:${encodeURIComponent(genericParamId)}`;
63795
+ }
63796
+ function pendingGenericArgumentIdentity(token) {
63797
+ if (!token.startsWith(PENDING_GENERIC_ARGUMENT_PREFIX)) return null;
63798
+ const parts = token.slice(PENDING_GENERIC_ARGUMENT_PREFIX.length).split(":");
63799
+ if (parts.length !== 2)
63800
+ throw new Error(
63801
+ `Pending generic argument identity must have two components: ${token}.`
63802
+ );
63803
+ if (!parts[0])
63804
+ throw new Error(
63805
+ `Pending generic argument identity has no parent: ${token}.`
63806
+ );
63807
+ if (!parts[1])
63808
+ throw new Error(
63809
+ `Pending generic argument identity has no parameter: ${token}.`
63810
+ );
63811
+ return {
63812
+ parentRecordId: decodeURIComponent(parts[0]),
63813
+ genericParamId: decodeURIComponent(parts[1])
63814
+ };
63815
+ }
63816
+ var NEO_GENERIC_ARGUMENT_MEMBER_NAMESPACE, PENDING_GENERIC_ARGUMENT_PREFIX;
63686
63817
  var init_generic_argument_member_id = __esm({
63687
63818
  "../src/models/members/generic-argument-member-id.ts"() {
63688
63819
  "use strict";
63689
63820
  init_dist_node();
63690
63821
  init_system_record_id();
63691
63822
  NEO_GENERIC_ARGUMENT_MEMBER_NAMESPACE = "6a4e1d38-9b52-5c0f-8d71-3e2a7f4b6c19";
63823
+ PENDING_GENERIC_ARGUMENT_PREFIX = "__pending__:generic-argument-member:";
63692
63824
  }
63693
63825
  });
63694
63826
 
@@ -69866,8 +69998,8 @@ var init_strict_resolver = __esm({
69866
69998
  this.persistingMethodGroup = false;
69867
69999
  }
69868
70000
  }
69869
- /** P112 §2.2. Checks a stored default's `Reference(place)` the push can't settle. */
69870
- resolvePersistedReference(expression, expected) {
70001
+ /** Check an initializer with its expected type, including contextual expressions. */
70002
+ validateInitializerExpression(expression, expected) {
69871
70003
  const resolved = this.resolveExpression(
69872
70004
  expression,
69873
70005
  this.initialScope(),
@@ -74969,11 +75101,97 @@ var init_strict_resolver = __esm({
74969
75101
  if (callee.kind !== "member") return null;
74970
75102
  const isInitialize = callee.name === VARIANT_INITIALIZE_NAME;
74971
75103
  const isApply = callee.name === VARIANT_APPLY_NAME;
74972
- if (!isInitialize && !isApply) return null;
75104
+ const isBind = callee.name === "Bind";
75105
+ if (!isInitialize && !isApply && !isBind) return null;
74973
75106
  if (callee.receiver.kind === "ident" && !this.hasValueReceiver(callee.receiver.name, scope) && this.project.typeByName.has(callee.receiver.name)) {
74974
75107
  return null;
74975
75108
  }
74976
75109
  const receiver = receiverValue ? receiverValue() : this.resolveExpression(callee.receiver, scope);
75110
+ if (isBind) {
75111
+ const variantInfo2 = this.variantTypeInfo(receiver.type);
75112
+ if (variantInfo2 === null) return null;
75113
+ if (variantInfo2.valueType === null) {
75114
+ throw new CompileError("Only a lookup variant can bind a row.", pos);
75115
+ }
75116
+ if (callee.optional === true) {
75117
+ throw new CompileError("Bind requires a non-null lookup variant.", pos);
75118
+ }
75119
+ if (receiver.pointer.type !== "variant" /* Variant */) {
75120
+ throw new CompileError(
75121
+ "Bind requires a declared lookup variant path.",
75122
+ pos
75123
+ );
75124
+ }
75125
+ requireArgCount("NeoLookupVariant.Bind", argumentsList2, 1, pos);
75126
+ const row2 = argumentsList2[0];
75127
+ if (row2.kind !== "call") {
75128
+ throw new CompileError(
75129
+ 'Bind requires Reference(id: "value-id").',
75130
+ row2.pos
75131
+ );
75132
+ }
75133
+ if (row2.callee.kind !== "ident" || row2.callee.name !== "Reference") {
75134
+ throw new CompileError(
75135
+ "Bind requires a Reference row argument.",
75136
+ row2.pos
75137
+ );
75138
+ }
75139
+ requireArgCount("Bind Reference", row2.args, 1, row2.pos);
75140
+ if (row2.argumentNames?.[0] !== "id") {
75141
+ throw new CompileError(
75142
+ 'Bind requires Reference(id: "value-id").',
75143
+ row2.pos
75144
+ );
75145
+ }
75146
+ const id2 = row2.args[0];
75147
+ if (id2.kind !== "litString") {
75148
+ throw new CompileError(
75149
+ "Bound row id must be a string literal.",
75150
+ id2.pos
75151
+ );
75152
+ }
75153
+ if (id2.value.length === 0) {
75154
+ throw new CompileError("Bound row id must not be empty.", id2.pos);
75155
+ }
75156
+ if (row2.typeArguments !== void 0) {
75157
+ if (row2.typeArguments.length !== 1) {
75158
+ throw new CompileError(
75159
+ "Reference requires exactly one generic target type.",
75160
+ row2.pos
75161
+ );
75162
+ }
75163
+ this.requireAssignable(
75164
+ this.resolveType(row2.typeArguments[0]),
75165
+ variantInfo2.valueType,
75166
+ row2.pos,
75167
+ "Lookup variant row"
75168
+ );
75169
+ }
75170
+ const rowType = this.context.persistedReferenceTypes?.get(id2.value);
75171
+ if (rowType !== void 0) {
75172
+ this.requireAssignable(
75173
+ neoScriptReadType(rowType),
75174
+ variantInfo2.valueType,
75175
+ row2.pos,
75176
+ "Lookup variant row"
75177
+ );
75178
+ }
75179
+ const bound = this.project.typeByName.get(NEO_VARIANT_TYPE_NAME);
75180
+ if (bound === void 0) {
75181
+ throw new CompileError(
75182
+ `The seeded '${NEO_VARIANT_TYPE_NAME}' class is missing.`,
75183
+ pos
75184
+ );
75185
+ }
75186
+ return {
75187
+ pointer: { ...receiver.pointer, rowValueId: id2.value },
75188
+ type: {
75189
+ kind: "named",
75190
+ typeId: bound.id,
75191
+ typeArguments: receiver.type.kind === "named" ? receiver.type.typeArguments?.slice(0, 1) ?? [] : []
75192
+ }
75193
+ };
75194
+ }
74977
75195
  if (isInitialize) {
74978
75196
  const variantInfo2 = this.variantTypeInfo(receiver.type);
74979
75197
  if (variantInfo2 === null) return null;
@@ -75641,6 +75859,8 @@ var init_strict_resolver = __esm({
75641
75859
  }
75642
75860
  const staticType = this.project.typeByName.get(receiverAst.name);
75643
75861
  if (staticType && staticType.kind !== "enum") {
75862
+ if (receiverAst.typeQualifier)
75863
+ this.resolveType(receiverAst.typeQualifier);
75644
75864
  this.assertUserSafe(
75645
75865
  { kind: "named", typeId: staticType.id },
75646
75866
  "a static receiver",
@@ -75780,6 +76000,9 @@ var init_strict_resolver = __esm({
75780
76000
  pointer: listIndexPointer(receiver.pointer, index),
75781
76001
  type: viewType,
75782
76002
  writability: "readOnly" /* ReadOnly */,
76003
+ ...receiver.entryWritability !== void 0 ? { entryWritability: receiver.entryWritability } : {},
76004
+ entryUserData: receiver.entryUserData === true,
76005
+ ...receiver.writeRoot !== void 0 ? { writeRoot: receiver.writeRoot } : {},
75783
76006
  indexDefinition: index,
75784
76007
  indexCollectionPointer: receiver.pointer
75785
76008
  };
@@ -75788,7 +76011,10 @@ var init_strict_resolver = __esm({
75788
76011
  return {
75789
76012
  pointer: receiver.pointer,
75790
76013
  type: { kind: "primitive", name: "unknown" },
75791
- indexSurface: receiver.type
76014
+ indexSurface: receiver.type,
76015
+ entryWritability: receiver.entryWritability ?? receiver.writability ?? "runtime" /* Runtime */,
76016
+ entryUserData: receiver.entryWritability === void 0 ? receiver.userData === true : receiver.entryUserData === true,
76017
+ writeRoot: this.expressionWriteRoot(receiver, scope)
75792
76018
  };
75793
76019
  }
75794
76020
  if ((name === "Keys" || name === "Values") && receiver.type.kind === "dictionary") {
@@ -76063,7 +76289,7 @@ var init_strict_resolver = __esm({
76063
76289
  pos
76064
76290
  );
76065
76291
  }
76066
- if (entry.id.startsWith(NEOSCRIPT_PENDING_SYMBOL_ID_PREFIX)) {
76292
+ if (entry.id.startsWith(NEOSCRIPT_PENDING_SYMBOL_ID_PREFIX) && !this.options.allowPendingRegistryEntries) {
76067
76293
  throw new CompileError(
76068
76294
  `${registry.entryType} '${name}' has no @id, so it has never been pushed and has no project file to reference. Push the file before referencing it.`,
76069
76295
  pos
@@ -76191,7 +76417,10 @@ var init_strict_resolver = __esm({
76191
76417
  key.pointer
76192
76418
  ),
76193
76419
  type: resultType,
76194
- writability: "readOnly" /* ReadOnly */
76420
+ writability: "readOnly" /* ReadOnly */,
76421
+ ...receiver.entryWritability !== void 0 ? { entryWritability: receiver.entryWritability } : {},
76422
+ entryUserData: receiver.entryUserData === true,
76423
+ ...receiver.writeRoot !== void 0 ? { writeRoot: receiver.writeRoot } : {}
76195
76424
  };
76196
76425
  }
76197
76426
  const readonlyCollection = receiver.symbol?.readonlyDeclaration === true && receiver.initWritability !== void 0 ? {
@@ -76864,6 +77093,33 @@ var init_strict_resolver = __esm({
76864
77093
  typeArguments
76865
77094
  );
76866
77095
  }
77096
+ if (callee.kind === "lambda" && expected !== void 0) {
77097
+ rejectTypeArguments();
77098
+ const parameterTypes = callee.params.map((parameter4) => {
77099
+ if (parameter4.type === null) {
77100
+ throw new CompileError(
77101
+ "An immediately invoked lambda requires explicit parameter types.",
77102
+ parameter4.pos
77103
+ );
77104
+ }
77105
+ return this.resolveType(parameter4.type);
77106
+ });
77107
+ return this.resolveDelegateCall(
77108
+ this.resolveDelegateLambda(
77109
+ callee,
77110
+ {
77111
+ kind: "delegate",
77112
+ parameterTypes,
77113
+ returnType: expected
77114
+ },
77115
+ scope
77116
+ ),
77117
+ argumentsList2,
77118
+ scope,
77119
+ pos,
77120
+ false
77121
+ );
77122
+ }
76867
77123
  const variantCall = this.resolveVariantCall(
76868
77124
  callee,
76869
77125
  argumentsList2,
@@ -77027,6 +77283,8 @@ var init_strict_resolver = __esm({
77027
77283
  }
77028
77284
  const staticType = this.project.typeByName.get(callee.receiver.name);
77029
77285
  if (staticType && staticType.kind !== "enum") {
77286
+ if (callee.receiver.typeQualifier)
77287
+ this.resolveType(callee.receiver.typeQualifier);
77030
77288
  this.assertUserSafe(
77031
77289
  { kind: "named", typeId: staticType.id },
77032
77290
  "a static receiver",
@@ -85628,7 +85886,10 @@ function formatNeoScript(text, options = {}) {
85628
85886
  const literalNewlines = /* @__PURE__ */ new Set();
85629
85887
  const delimiterTokensByLine = /* @__PURE__ */ new Map();
85630
85888
  const tokensByLine = /* @__PURE__ */ new Map();
85631
- const lambdaBraceOffsets = /* @__PURE__ */ new Set();
85889
+ const braceHeaderLines = /* @__PURE__ */ new Map();
85890
+ const parenthesisLines = [];
85891
+ const genericLines = [];
85892
+ let previousHeaderLine = 0;
85632
85893
  const genericOffsets = genericAngleOffsets(syntax.lexed.tokens);
85633
85894
  const continuationOperator = (token) => !genericOffsets.has(token.start) && isContinuationOperator(token);
85634
85895
  let annotationState = "none";
@@ -85664,9 +85925,22 @@ function formatNeoScript(text, options = {}) {
85664
85925
  tripleString = { token, previous: previousSignificantToken };
85665
85926
  }
85666
85927
  if (token.kind !== "comment" && token.kind !== "eof") {
85667
- if (token.kind === "punctuation" && token.text === "{" && previousSignificantToken?.kind === "operator" && previousSignificantToken.text === "=>") {
85668
- lambdaBraceOffsets.add(token.start);
85669
- }
85928
+ let headerLine = token.range.start.line;
85929
+ const followsTypeOrName = previousSignificantToken?.kind === "identifier" || previousSignificantToken?.text === "new" || previousSignificantToken?.text === ">" && genericOffsets.has(previousSignificantToken.start);
85930
+ if (token.kind === "identifier" && previousSignificantToken?.text === "new" || token.text === "(" && followsTypeOrName)
85931
+ headerLine = previousHeaderLine;
85932
+ if (genericOffsets.has(token.start)) {
85933
+ if (token.text === "<") genericLines.push(previousHeaderLine);
85934
+ if (token.text === ">") headerLine = genericLines.pop() ?? headerLine;
85935
+ }
85936
+ if (token.text === "(") parenthesisLines.push(headerLine);
85937
+ if (token.text === ")") headerLine = parenthesisLines.pop() ?? headerLine;
85938
+ if (token.text === "{")
85939
+ braceHeaderLines.set(
85940
+ token.start,
85941
+ previousSignificantToken?.text === ")" || previousSignificantToken?.text === "=>" || previousSignificantToken?.kind === "identifier" || previousSignificantToken?.text === ">" && genericOffsets.has(previousSignificantToken.start) ? previousHeaderLine : headerLine
85942
+ );
85943
+ previousHeaderLine = headerLine;
85670
85944
  let annotationEnd = false;
85671
85945
  if (token.kind === "punctuation" && token.text === "@" && annotationDepth === 0)
85672
85946
  annotationState = "name";
@@ -85695,6 +85969,8 @@ function formatNeoScript(text, options = {}) {
85695
85969
  }
85696
85970
  const formatted = [];
85697
85971
  const delimiters = [];
85972
+ const lineDepths = /* @__PURE__ */ new Map();
85973
+ const braceHeaderDepth = (token) => lineDepths.get(braceHeaderLines.get(token.start) ?? -1);
85698
85974
  const continuations = /* @__PURE__ */ new Set();
85699
85975
  let preceding;
85700
85976
  let aligning;
@@ -85728,14 +86004,21 @@ function formatNeoScript(text, options = {}) {
85728
86004
  const sectionDepth = switchSectionIndentDepth(syntax.parsed, contentOffset);
85729
86005
  const leadingState = cloneDelimiterStack(delimiters);
85730
86006
  for (const token of leadingClosers) {
85731
- applyDelimiterToken(leadingState, token, lambdaBraceOffsets);
86007
+ applyDelimiterToken(leadingState, token);
85732
86008
  }
85733
- const depth = delimiterDepth(leadingState);
86009
+ let depth = delimiterDepth(leadingState);
85734
86010
  const significant = tokensByLine.get(lineIndex) ?? [];
85735
- pruneContinuations(continuations, leadingState);
86011
+ lineDepths.set(lineIndex, depth);
85736
86012
  const first = significant[0];
86013
+ const continuationScope = leadingState.at(-1)?.openingOffset ?? -1;
86014
+ if (first?.text === "{") {
86015
+ applyDelimiterToken(leadingState, first, braceHeaderDepth(first));
86016
+ depth = delimiterDepth(leadingState) - 1;
86017
+ lineDepths.set(lineIndex, depth);
86018
+ }
86019
+ pruneContinuations(continuations, leadingState);
85737
86020
  if (leadingClosers.length === 0 && (first !== void 0 && continuationOperator(first) && preceding !== void 0 && canEndExpression(preceding) || preceding !== void 0 && continuationOperator(preceding)))
85738
- continuations.add(leadingState.at(-1)?.openingOffset ?? -1);
86021
+ continuations.add(continuationScope);
85739
86022
  const lineDepth = depth + sectionDepth + continuations.size;
85740
86023
  const normalized = first?.range.start.character === firstContentCharacter ? normalizeControlHeaderSpacing(content) : content;
85741
86024
  const indent2 = indentUnit.repeat(lineDepth);
@@ -85746,7 +86029,7 @@ function formatNeoScript(text, options = {}) {
85746
86029
  if (standalone !== void 0 && standalone.closingIndent !== indent2)
85747
86030
  aligning = { ...standalone, indent: indent2 };
85748
86031
  for (const token of lineTokens) {
85749
- applyDelimiterToken(delimiters, token, lambdaBraceOffsets);
86032
+ applyDelimiterToken(delimiters, token, braceHeaderDepth(token));
85750
86033
  }
85751
86034
  pruneContinuations(continuations, delimiters);
85752
86035
  const last = significant.at(-1);
@@ -85887,25 +86170,26 @@ function leadingClosingTokens(lineTokens, firstContentCharacter) {
85887
86170
  }
85888
86171
  return result;
85889
86172
  }
85890
- function applyDelimiterToken(stack, token, lambdaBraceOffsets) {
86173
+ function applyDelimiterToken(stack, token, headerDepth) {
85891
86174
  if (isOpeningDelimiter(token.text)) {
85892
- let restores;
85893
- if (token.text === "{" && lambdaBraceOffsets.has(token.start)) {
85894
- for (let index = stack.length - 1; index >= 0; index--) {
86175
+ const restores = [];
86176
+ if (token.text === "{" && headerDepth !== void 0) {
86177
+ let depth = delimiterDepth(stack);
86178
+ for (let index = stack.length - 1; index >= 0 && depth > headerDepth; index--) {
85895
86179
  const candidate = stack[index];
85896
- if (candidate?.text === "(" && candidate.contributes && candidate.openingLine === token.range.start.line) {
85897
- restores = candidate;
85898
- break;
86180
+ if (candidate?.text === "{") break;
86181
+ if (candidate?.text === "(" && candidate.contributes) {
86182
+ restores.push(candidate);
86183
+ candidate.contributes = false;
86184
+ depth--;
85899
86185
  }
85900
86186
  }
85901
- if (restores) restores.contributes = false;
85902
86187
  }
85903
86188
  stack.push({
85904
86189
  text: token.text,
85905
- openingLine: token.range.start.line,
85906
86190
  openingOffset: token.start,
85907
86191
  contributes: true,
85908
- ...restores ? { restores } : {}
86192
+ ...restores.length > 0 ? { restores } : {}
85909
86193
  });
85910
86194
  return;
85911
86195
  }
@@ -85919,7 +86203,7 @@ function applyDelimiterToken(stack, token, lambdaBraceOffsets) {
85919
86203
  }
85920
86204
  if (frameIndex < 0) return;
85921
86205
  const [frame] = stack.splice(frameIndex, 1);
85922
- if (frame?.restores) frame.restores.contributes = true;
86206
+ for (const restored of frame?.restores ?? []) restored.contributes = true;
85923
86207
  }
85924
86208
  function pruneContinuations(continuations, stack) {
85925
86209
  const scopes = /* @__PURE__ */ new Set([-1, ...stack.map((frame) => frame.openingOffset)]);
@@ -85930,20 +86214,11 @@ function delimiterDepth(stack) {
85930
86214
  return stack.filter((frame) => frame.contributes).length;
85931
86215
  }
85932
86216
  function cloneDelimiterStack(stack) {
85933
- const clones = stack.map((frame) => ({
86217
+ return stack.map((frame) => ({
85934
86218
  text: frame.text,
85935
- openingLine: frame.openingLine,
85936
86219
  openingOffset: frame.openingOffset,
85937
86220
  contributes: frame.contributes
85938
86221
  }));
85939
- for (let index = 0; index < stack.length; index++) {
85940
- const restores = stack[index]?.restores;
85941
- if (!restores) continue;
85942
- const restoreIndex = stack.indexOf(restores);
85943
- if (restoreIndex < 0) continue;
85944
- clones[index] = { ...clones[index], restores: clones[restoreIndex] };
85945
- }
85946
- return clones;
85947
86222
  }
85948
86223
  function matchingOpeningDelimiter(value) {
85949
86224
  switch (value) {
@@ -90590,7 +90865,7 @@ var init_neoscript_language_context_adapter = __esm({
90590
90865
  init_dialogue_types();
90591
90866
  init_dialogue_group_language();
90592
90867
  init_analyzer_types();
90593
- NEOSCRIPT_COMPILER_ADAPTER_REVISION = 6;
90868
+ NEOSCRIPT_COMPILER_ADAPTER_REVISION = 7;
90594
90869
  UNKNOWN_TYPE2 = {
90595
90870
  kind: "primitive",
90596
90871
  name: "unknown"
@@ -91227,6 +91502,7 @@ function compileMemberInitializerBody(args) {
91227
91502
  const returnTypeInfo = resolveMemberDeclaredTypeInfo(
91228
91503
  args.member,
91229
91504
  members2,
91505
+ args.classes,
91230
91506
  args.thisClass
91231
91507
  );
91232
91508
  if (returnTypeInfo === null) {
@@ -91274,7 +91550,8 @@ function compileValueRowInitializerBody(args) {
91274
91550
  }
91275
91551
  const returnTypeInfo = resolveMemberDeclaredTypeInfo(
91276
91552
  args.member,
91277
- args.members
91553
+ args.members,
91554
+ args.classes
91278
91555
  );
91279
91556
  if (returnTypeInfo === null) {
91280
91557
  throw new Error(
@@ -91457,6 +91734,7 @@ function compileConstructorBaseInitializerFields(args, owner) {
91457
91734
  const declaredTypeInfo = resolveMemberDeclaredTypeInfo(
91458
91735
  member,
91459
91736
  args.members,
91737
+ args.classes,
91460
91738
  args.classes.find(
91461
91739
  (schemaClass2) => schemaClass2.id === entry.ownerClassId
91462
91740
  ) ?? null
@@ -97695,7 +97973,11 @@ function validateMember(uri, member, ownerName, documentKind, ownerScope, enviro
97695
97973
  member.initializer.text,
97696
97974
  memberType2,
97697
97975
  scope,
97698
- member.modifiers.includes("static") ? { ...environment, staticMember: true } : environment,
97976
+ {
97977
+ ...environment,
97978
+ staticMember: member.modifiers.includes("static"),
97979
+ checkComputedInitializers: true
97980
+ },
97699
97981
  member.initializer.range,
97700
97982
  diagnostics,
97701
97983
  anchorOf(member.initializer),
@@ -98619,6 +98901,80 @@ function knownGeneratorExpression(expression, scope, environment) {
98619
98901
  return candidates !== void 0 && candidates.length > 0 && candidates.every((member) => member.generator === true);
98620
98902
  }
98621
98903
  function validateExpression(expression, expected, scope, environment, uri, range2, diagnostics, anchor, storedValue = true) {
98904
+ const sourceOnly = expected !== void 0 && (isNeoVariantTypeName(expected.name) || expected.name === "NeoAction" || expected.name === "ImageRef");
98905
+ let receiver = expression;
98906
+ if (environment.checkComputedInitializers) {
98907
+ while (receiver.kind === "member") receiver = receiver.receiver;
98908
+ }
98909
+ const computed = environment.checkComputedInitializers && !sourceOnly && (expression.kind === "member" && (receiver.kind !== "ident" || receiver.typeQualifier !== void 0) || [
98910
+ "binary",
98911
+ "unary",
98912
+ "force",
98913
+ "coalesce",
98914
+ "conditional",
98915
+ "switchExpression",
98916
+ "is",
98917
+ "lambda",
98918
+ "index",
98919
+ "litInterp",
98920
+ "litTripleString",
98921
+ "call"
98922
+ ].includes(expression.kind)) && !isReferenceCall(expression);
98923
+ const count = diagnostics.length;
98924
+ validateStoredExpression(
98925
+ expression,
98926
+ expected,
98927
+ scope,
98928
+ computed || sourceOnly || expression.kind === "member" ? { ...environment, checkComputedInitializers: false } : environment,
98929
+ uri,
98930
+ range2,
98931
+ diagnostics,
98932
+ anchor,
98933
+ storedValue
98934
+ );
98935
+ if (!computed || diagnostics.length !== count) return;
98936
+ const { context, resolver, parameterNames, parameterTypes } = initializerResolver(
98937
+ environment,
98938
+ scope.get("this")?.name ?? "",
98939
+ environment.staticMember,
98940
+ "initializer"
98941
+ );
98942
+ try {
98943
+ const reads = new Set(
98944
+ collectIdentifierReads(expression, parameterNames).map(
98945
+ (read) => read.name
98946
+ )
98947
+ );
98948
+ const parameters = [...reads].map((name) => ({
98949
+ name,
98950
+ type: parameterTypes.get(name)
98951
+ }));
98952
+ const scopedResolver = parameters.length === 0 ? resolver : new StrictNeoScriptResolver(
98953
+ { ...context, parameters },
98954
+ environment.projectIndex,
98955
+ void 0,
98956
+ { allowPendingRegistryEntries: true }
98957
+ );
98958
+ scopedResolver.validateInitializerExpression(
98959
+ expression,
98960
+ expected === void 0 ? void 0 : resolveNeoScriptType(
98961
+ semanticAst(expected, expression.pos),
98962
+ context,
98963
+ environment.projectIndex
98964
+ )
98965
+ );
98966
+ } catch (error) {
98967
+ if (!(error instanceof CompileError)) throw error;
98968
+ pushDiagnostic(
98969
+ diagnostics,
98970
+ uri,
98971
+ anchor ? anchorSpan(anchor, error, 1) : range2,
98972
+ "invalid-computed-initializer",
98973
+ error.message.replace(/^\d+:\d+: /, "")
98974
+ );
98975
+ }
98976
+ }
98977
+ function validateStoredExpression(expression, expected, scope, environment, uri, range2, diagnostics, anchor, storedValue = true) {
98622
98978
  if (anchor !== void 0 && expression.kind === "call") {
98623
98979
  const error = sourceCallBinding(expression, scope, environment)?.error;
98624
98980
  if (error?.message.includes(
@@ -98843,7 +99199,7 @@ function validateExpression(expression, expected, scope, environment, uri, range
98843
99199
  // Enum dictionaries also preserve quoted option IDs, including orphaned IDs.
98844
99200
  entry.key.kind === "litString" ? void 0 : key,
98845
99201
  scope,
98846
- environment,
99202
+ { ...environment, checkComputedInitializers: false },
98847
99203
  uri,
98848
99204
  range2,
98849
99205
  diagnostics,
@@ -99025,6 +99381,17 @@ function validateExpression(expression, expected, scope, environment, uri, range
99025
99381
  }
99026
99382
  if (expression.kind === "new") {
99027
99383
  const typeName = expression.className ?? expected?.name;
99384
+ if (typeName === "List" || typeName === "Set" || typeName === "Dictionary") {
99385
+ const literal3 = typeName === "Dictionary" ? "{}" : "[]";
99386
+ pushDiagnostic(
99387
+ diagnostics,
99388
+ uri,
99389
+ anchor ? anchorSpan(anchor, expression.pos, 3) : range2,
99390
+ "collection-construction",
99391
+ `${typeName} has no constructor. Use ${literal3} for an empty collection.`
99392
+ );
99393
+ return;
99394
+ }
99028
99395
  const declaration = typeName ? environment.types.get(typeName) : void 0;
99029
99396
  for (const entry of expression.initializer ?? []) {
99030
99397
  if (entry.name !== "layerClassId") continue;
@@ -99958,24 +100325,49 @@ function wrappedTypeParameterConstruction(declaration, typeArguments, scope, env
99958
100325
  }
99959
100326
  return target.kind === "named" ? wrappedTypeParameterMessage(target, environment.projectIndex) : null;
99960
100327
  }
99961
- function initializerResolver(environment, thisName, staticMember) {
100328
+ function initializerResolver(environment, thisName, staticMember, kind = "initializerExpression") {
99962
100329
  const declaring = environment.projectIndex.typeByName.get(thisName);
99963
- const key = `${declaring?.id ?? ""}:${staticMember}`;
100330
+ const key = `${declaring?.id ?? ""}:${staticMember}:${kind}`;
99964
100331
  let entry = environment.initializerResolvers.get(key);
99965
100332
  if (entry === void 0) {
99966
100333
  const declaringType = declaring ? { kind: "named", typeId: declaring.id } : void 0;
99967
100334
  const context = {
99968
100335
  project: environment.project,
99969
- kind: "initializerExpression",
100336
+ kind,
99970
100337
  ...declaringType ? {
99971
100338
  declaringType,
99972
100339
  implicitMemberAccess: true,
99973
100340
  ...staticMember ? { staticMember } : { thisClass: declaringType }
99974
100341
  } : {}
99975
100342
  };
100343
+ const parameterTypes = /* @__PURE__ */ new Map();
100344
+ if (kind === "initializer" && !staticMember) {
100345
+ const owner = environment.types.get(thisName);
100346
+ for (const parameter4 of owner?.headerParameters ?? []) {
100347
+ try {
100348
+ parameterTypes.set(
100349
+ parameter4.name,
100350
+ resolveNeoScriptType(
100351
+ semanticAst(semanticType(parameter4.type), { line: 1, column: 1 }),
100352
+ context,
100353
+ environment.projectIndex
100354
+ )
100355
+ );
100356
+ } catch (error) {
100357
+ if (!(error instanceof CompileError)) throw error;
100358
+ }
100359
+ }
100360
+ }
99976
100361
  entry = {
99977
100362
  context,
99978
- resolver: new StrictNeoScriptResolver(context, environment.projectIndex)
100363
+ parameterNames: new Set(parameterTypes.keys()),
100364
+ parameterTypes,
100365
+ resolver: new StrictNeoScriptResolver(
100366
+ context,
100367
+ environment.projectIndex,
100368
+ void 0,
100369
+ { allowPendingRegistryEntries: true }
100370
+ )
99979
100371
  };
99980
100372
  environment.initializerResolvers.set(key, entry);
99981
100373
  }
@@ -100525,7 +100917,7 @@ function validatePlaceReference(expression, expected, thisName, environment, rep
100525
100917
  environment.staticMember
100526
100918
  );
100527
100919
  try {
100528
- resolver.resolvePersistedReference(
100920
+ resolver.validateInitializerExpression(
100529
100921
  expression,
100530
100922
  expected === void 0 ? void 0 : resolveNeoScriptType(
100531
100923
  semanticAst(expected, expression.pos),
@@ -101817,6 +102209,29 @@ function buildProjectGraph(documents) {
101817
102209
  rootType
101818
102210
  ];
101819
102211
  const globals = [];
102212
+ const variants = [];
102213
+ for (const entries of buildNeoVariantScopeIndex(
102214
+ documents
102215
+ ).variantsByScope.values()) {
102216
+ for (const entry of entries) {
102217
+ const classId = graph.typeIdsByName.byName.get(entry.className);
102218
+ if (classId === void 0) continue;
102219
+ const folder = entry.scope.slice(`${entry.className}.${NEO_VARIANT_SCOPE_NAME}`.length + 1).split(".").join("/");
102220
+ const valueType = entry.declaration.type.typeArguments[1];
102221
+ const valueTypeId = valueType === void 0 ? void 0 : graph.typeIdsByName.byName.get(valueType.name);
102222
+ variants.push({
102223
+ id: sourceIdentity2(
102224
+ entry.declaration.annotations,
102225
+ `variant:${entry.uri}:${entry.className}:${entry.scope}:${entry.name}`
102226
+ ),
102227
+ classId,
102228
+ name: entry.name,
102229
+ folder: folder.length === 0 ? null : folder,
102230
+ ...valueTypeId === void 0 ? {} : { valueTypeId },
102231
+ location: location(entry.uri, entry.declaration.nameRange)
102232
+ });
102233
+ }
102234
+ }
101820
102235
  const extensions = [];
101821
102236
  const memberInfo = new Map(graph.memberInfo);
101822
102237
  const roots = [];
@@ -101870,7 +102285,7 @@ function buildProjectGraph(documents) {
101870
102285
  return {
101871
102286
  ...graph,
101872
102287
  memberInfo,
101873
- project: { ...graph.project, types, globals, roots, extensions }
102288
+ project: { ...graph.project, types, globals, roots, extensions, variants }
101874
102289
  };
101875
102290
  }
101876
102291
  function buildDeclarationGraph(documents) {
@@ -102859,6 +103274,7 @@ var init_project_source_script_compiler = __esm({
102859
103274
  init_project_root();
102860
103275
  init_function_overload_identity();
102861
103276
  init_project_source_registry();
103277
+ init_project_source_variants();
102862
103278
  init_compilation_product();
102863
103279
  init_runtime_source();
102864
103280
  init_lexer();
@@ -123898,6 +124314,14 @@ function isNamePath(expression) {
123898
124314
  return expression.kind === "member" && isNamePath(expression.receiver);
123899
124315
  }
123900
124316
  function isLiteralCall(expression) {
124317
+ if (expression.callee.kind === "member" && expression.callee.name === "Bind") {
124318
+ let receiver = expression.callee.receiver;
124319
+ while (receiver.kind === "member") {
124320
+ if (receiver.name === "Variants" && isNamePath(receiver.receiver))
124321
+ return true;
124322
+ receiver = receiver.receiver;
124323
+ }
124324
+ }
123901
124325
  if (expression.callee.kind === "ident" && expression.callee.name === "Reference") {
123902
124326
  if (expression.argumentNames?.some((name) => name !== null)) return true;
123903
124327
  const [place] = expression.args;
@@ -128101,7 +128525,8 @@ function lowerBindings(context, ownerClass, ownerParameters, ownerRecordId, para
128101
128525
  continue;
128102
128526
  }
128103
128527
  const baseBinding = baseArguments?.[parameterId];
128104
- const memberId = baseBinding?.kind === "member" ? baseBinding.memberId : derivedGenericArgumentMemberId(ownerRecordId, parameterId);
128528
+ const derive = isPendingId(ownerRecordId) || isPendingId(parameterId) ? pendingGenericArgumentMemberId : derivedGenericArgumentMemberId;
128529
+ const memberId = baseBinding?.kind === "member" ? baseBinding.memberId : derive(ownerRecordId, parameterId);
128105
128530
  result[parameterId] = { kind: "member", memberId };
128106
128531
  lowerGenericArgument(
128107
128532
  context,
@@ -128755,6 +129180,7 @@ var init_lower_members = __esm({
128755
129180
  init_ui_action_source();
128756
129181
  init_entry_member_id();
128757
129182
  init_generic_argument_member_id();
129183
+ init_pending_id();
128758
129184
  init_structured_leaf_source();
128759
129185
  init_member_kind_type_names();
128760
129186
  init_set_literal_duplicates();
@@ -135236,6 +135662,59 @@ var init_dialogue_lower = __esm({
135236
135662
  }
135237
135663
  });
135238
135664
 
135665
+ // src/project-source/identity-rewriter.ts
135666
+ function createIdentityRewriter(assignments, onReplace) {
135667
+ if (assignments.size === 0) return (value) => value;
135668
+ const root = { children: /* @__PURE__ */ new Map() };
135669
+ for (const [source, replacement] of assignments) {
135670
+ let prefix = root;
135671
+ for (let index = 0; index < source.length; index += 1) {
135672
+ const character = source[index];
135673
+ let child2 = prefix.children.get(character);
135674
+ if (child2 === void 0) {
135675
+ child2 = { children: /* @__PURE__ */ new Map() };
135676
+ prefix.children.set(character, child2);
135677
+ }
135678
+ prefix = child2;
135679
+ }
135680
+ prefix.replacement = replacement;
135681
+ }
135682
+ return (value) => {
135683
+ const exact = assignments.get(value);
135684
+ if (exact !== void 0) {
135685
+ onReplace?.(value);
135686
+ return exact;
135687
+ }
135688
+ const parts = [];
135689
+ let copiedThrough = 0;
135690
+ for (let start = 0; start < value.length; start += 1) {
135691
+ let prefix = root.children.get(value[start]);
135692
+ let replacement;
135693
+ let end = start;
135694
+ for (let index = start; prefix !== void 0; index += 1) {
135695
+ if (prefix.replacement !== void 0) {
135696
+ replacement = prefix.replacement;
135697
+ end = index + 1;
135698
+ }
135699
+ prefix = prefix.children.get(value[index + 1]);
135700
+ }
135701
+ if (replacement === void 0) continue;
135702
+ onReplace?.(value.slice(start, end));
135703
+ parts.push(value.slice(copiedThrough, start), replacement);
135704
+ copiedThrough = end;
135705
+ start = end - 1;
135706
+ }
135707
+ if (copiedThrough === 0) return value;
135708
+ parts.push(value.slice(copiedThrough));
135709
+ return parts.join("");
135710
+ };
135711
+ }
135712
+ var init_identity_rewriter = __esm({
135713
+ "src/project-source/identity-rewriter.ts"() {
135714
+ "use strict";
135715
+ }
135716
+ });
135717
+
135239
135718
  // ../src/database/document-initializer-compiler.ts
135240
135719
  function initializerCompilerState(document, compilationProject) {
135241
135720
  const existing = documentInitializerCompilerStates.get(document);
@@ -135260,7 +135739,9 @@ function compilationProjectForDocument(document, state) {
135260
135739
  classes: document.classes,
135261
135740
  enums: document.enums,
135262
135741
  interfaces: document.interfaces,
135263
- constructors: document.constructors ?? []
135742
+ constructors: document.constructors ?? [],
135743
+ variants: document.variants ?? [],
135744
+ variantFolders: document.variantFolders ?? []
135264
135745
  });
135265
135746
  return state.compilationProject;
135266
135747
  }
@@ -135359,6 +135840,8 @@ function compileValueInitializerDependency(document, valueId, compilationProject
135359
135840
  enums: document.enums,
135360
135841
  interfaces: document.interfaces,
135361
135842
  constructors: document.constructors ?? [],
135843
+ variants: document.variants ?? [],
135844
+ variantFolders: document.variantFolders ?? [],
135362
135845
  member: site.member,
135363
135846
  valueRow: { ...site.row },
135364
135847
  valueId: site.row.id,
@@ -135377,7 +135860,9 @@ function compileMemberInitializerDependency(document, memberId, compilationProje
135377
135860
  classes: document.classes,
135378
135861
  enums: document.enums,
135379
135862
  interfaces: document.interfaces,
135380
- constructors: document.constructors ?? []
135863
+ constructors: document.constructors ?? [],
135864
+ variants: document.variants ?? [],
135865
+ variantFolders: document.variantFolders ?? []
135381
135866
  };
135382
135867
  const memberIndex = documentMemberCompilationIndex(document);
135383
135868
  const member = memberIndex.membersById.get(memberId);
@@ -145933,6 +146418,7 @@ function appendAuthoredOwnedValueCascadeDeletes(args) {
145933
146418
  while (parentId != null && !visited.has(parentId)) {
145934
146419
  visited.add(parentId);
145935
146420
  const parent = postValuesById.get(parentId);
146421
+ if (isInitValueContent(parent)) break;
145936
146422
  if (parent !== void 0 && isLiteralValueContent(parent) && isVirtualInstanceRootShape(parent) && postPlacements.has(parentId)) {
145937
146423
  survivingConstructionIds.add(parentId);
145938
146424
  break;
@@ -146643,6 +147129,7 @@ function* prepareServerOwnedSchemaCommitPasses(args) {
146643
147129
  appendConstructionTypes
146644
147130
  });
146645
147131
  materializePreparedInstanceInitializers({
147132
+ referenceOwners: args.initializerReferenceOwners,
146646
147133
  document: args.document,
146647
147134
  physicalValues: args.document.physicalValues,
146648
147135
  prepared,
@@ -146994,7 +147481,8 @@ function materializePreparedInstanceInitializers(args) {
146994
147481
  if (pendingInitializerIds.size === 0) return;
146995
147482
  const batch = createInitializerMaterializationBatch(
146996
147483
  materializationScope.document,
146997
- pendingInitializerIds
147484
+ pendingInitializerIds,
147485
+ args.referenceOwners
146998
147486
  );
146999
147487
  materializeInitializerDependencies(pendingInitializerIds, (valueId) => {
147000
147488
  const site = pendingSites.get(valueId);
@@ -149178,6 +149666,8 @@ function compileOwnedValueRowInitializer(args) {
149178
149666
  enums: document.enums,
149179
149667
  interfaces: document.interfaces,
149180
149668
  constructors: document.constructors ?? [],
149669
+ variants: document.variants ?? [],
149670
+ variantFolders: document.variantFolders ?? [],
149181
149671
  compilationProject: args.compilationProject,
149182
149672
  member,
149183
149673
  valueRow: row,
@@ -149243,7 +149733,9 @@ function prepareServerOwnedValueInitializerBodies(args) {
149243
149733
  classes: document.classes,
149244
149734
  enums: document.enums,
149245
149735
  interfaces: document.interfaces,
149246
- constructors: document.constructors ?? []
149736
+ constructors: document.constructors ?? [],
149737
+ variants: document.variants ?? [],
149738
+ variantFolders: document.variantFolders ?? []
149247
149739
  });
149248
149740
  compilationProjects.set(document, compilationProject);
149249
149741
  return compilationProject;
@@ -152904,12 +153396,12 @@ function assertNoVariantTypePositions(args) {
152904
153396
  for (const declaredConstructor of args.constructors ?? []) {
152905
153397
  const ids = [];
152906
153398
  for (const argument2 of declaredConstructor.argumentTypes ?? []) {
152907
- typeInfoClassIds(argument2, ids, args.classesById);
153399
+ typeInfoClassIds(argument2, ids, args.classesById, true);
152908
153400
  }
152909
153401
  for (const classId of ids) {
152910
153402
  if (!isVariantFamilyClassId(classId, args.classesById)) continue;
152911
153403
  throw new Error(
152912
- `Constructor "${declaredConstructor.id}" declares a parameter of ${variantFamilyLabel(classId, args.classesById)}, which is reference-only: a variant is named by a Variant member, never passed as a value.`
153404
+ `Constructor "${declaredConstructor.id}" declares a parameter of ${variantFamilyLabel(classId, args.classesById)}, which cannot be used as a constructor argument type.`
152913
153405
  );
152914
153406
  }
152915
153407
  }
@@ -158262,7 +158754,10 @@ function assertStagedVariantMemberValuesValid(projected, changes) {
158262
158754
  const variantMembers = projected.members.filter(
158263
158755
  (member) => member.kind === 27 /* Variant */
158264
158756
  );
158265
- if (variantMembers.length === 0) return;
158757
+ if (variantMembers.length === 0 && !projected.values.some(
158758
+ (row) => isLiteralValueContent(row) && row.constructorArgs != null
158759
+ ))
158760
+ return;
158266
158761
  const classesById = new Map(
158267
158762
  projected.classes.map((schemaClass2) => [schemaClass2.id, schemaClass2])
158268
158763
  );
@@ -158340,6 +158835,46 @@ function assertStagedVariantMemberValuesValid(projected, changes) {
158340
158835
  });
158341
158836
  }
158342
158837
  }
158838
+ let constructorGraph;
158839
+ for (const row of projected.values) {
158840
+ if (!isLiteralValueContent(row) || row.constructorArgs == null) continue;
158841
+ constructorGraph ??= new MaterializedValueGraphContext(
158842
+ projected,
158843
+ valuesById
158844
+ );
158845
+ for (const [
158846
+ parameterId,
158847
+ typeInfo
158848
+ ] of constructorGraph.constructorParameterTypes(row)) {
158849
+ if (typeInfo.type !== 7 /* Class */) continue;
158850
+ const systemClass = classesById.get(typeInfo.classId);
158851
+ const worldKind = systemClass?.system?.worldKind;
158852
+ if (worldKind !== NeoWorldSystemClassKind.Variant && worldKind !== NeoWorldSystemClassKind.LookupVariant)
158853
+ continue;
158854
+ const label = `Constructor argument "${parameterId}" of row "${row.id}"`;
158855
+ const targetParamId = systemClass?.genericParams?.[0]?.id;
158856
+ const targetTypeInfo = targetParamId === void 0 ? void 0 : typeInfo.typeArguments?.[targetParamId];
158857
+ if (targetTypeInfo === void 0)
158858
+ throw new Error(`${label} declares no variant target type.`);
158859
+ const valueParamId = systemClass?.genericParams?.[1]?.id;
158860
+ const valueTypeInfo = valueParamId === void 0 ? void 0 : typeInfo.typeArguments?.[valueParamId];
158861
+ if (worldKind === NeoWorldSystemClassKind.LookupVariant && valueTypeInfo === void 0)
158862
+ throw new Error(`${label} declares no lookup value type.`);
158863
+ const declaration = {
158864
+ kind: 27 /* Variant */,
158865
+ name: parameterId,
158866
+ targetTypeInfo,
158867
+ ...valueTypeInfo === void 0 ? {} : { valueTypeInfo },
158868
+ ...typeInfo.required ? { requirement: 1 /* Required */ } : {}
158869
+ };
158870
+ assertVariantMemberTargetValid({ declaration, label, classesById });
158871
+ graded.push({
158872
+ value: row.constructorArgs[parameterId],
158873
+ declaration,
158874
+ label
158875
+ });
158876
+ }
158877
+ }
158343
158878
  for (const entry of graded) {
158344
158879
  assertVariantReferenceValid({
158345
158880
  value: entry.value,
@@ -158640,7 +159175,14 @@ var init_project_version_whole_graph_validation = __esm({
158640
159175
  25 /* NSDelegate */,
158641
159176
  26 /* NSAction */
158642
159177
  ]);
158643
- VARIANT_MEMBER_TRIGGER_RECORD_KINDS = /* @__PURE__ */ new Set(["member", "class", "value", "variant"]);
159178
+ VARIANT_MEMBER_TRIGGER_RECORD_KINDS = /* @__PURE__ */ new Set([
159179
+ "member",
159180
+ "class",
159181
+ "constructor",
159182
+ "value",
159183
+ "variant",
159184
+ "variant-folder"
159185
+ ]);
158644
159186
  }
158645
159187
  });
158646
159188
 
@@ -158720,6 +159262,7 @@ function preparationArgs(context) {
158720
159262
  const { args } = context;
158721
159263
  return {
158722
159264
  document: context.document,
159265
+ initializerReferenceOwners: args.initializerReferenceOwners,
158723
159266
  contentHashHeads: context.contentHashHeads,
158724
159267
  changes: args.changes,
158725
159268
  authoredValueSeeds: args.authoredValueSeeds,
@@ -159215,59 +159758,6 @@ var init_client_commit_preparation = __esm({
159215
159758
  }
159216
159759
  });
159217
159760
 
159218
- // src/project-source/identity-rewriter.ts
159219
- function createIdentityRewriter(assignments, onReplace) {
159220
- if (assignments.size === 0) return (value) => value;
159221
- const root = { children: /* @__PURE__ */ new Map() };
159222
- for (const [source, replacement] of assignments) {
159223
- let prefix = root;
159224
- for (let index = 0; index < source.length; index += 1) {
159225
- const character = source[index];
159226
- let child2 = prefix.children.get(character);
159227
- if (child2 === void 0) {
159228
- child2 = { children: /* @__PURE__ */ new Map() };
159229
- prefix.children.set(character, child2);
159230
- }
159231
- prefix = child2;
159232
- }
159233
- prefix.replacement = replacement;
159234
- }
159235
- return (value) => {
159236
- const exact = assignments.get(value);
159237
- if (exact !== void 0) {
159238
- onReplace?.(value);
159239
- return exact;
159240
- }
159241
- const parts = [];
159242
- let copiedThrough = 0;
159243
- for (let start = 0; start < value.length; start += 1) {
159244
- let prefix = root.children.get(value[start]);
159245
- let replacement;
159246
- let end = start;
159247
- for (let index = start; prefix !== void 0; index += 1) {
159248
- if (prefix.replacement !== void 0) {
159249
- replacement = prefix.replacement;
159250
- end = index + 1;
159251
- }
159252
- prefix = prefix.children.get(value[index + 1]);
159253
- }
159254
- if (replacement === void 0) continue;
159255
- onReplace?.(value.slice(start, end));
159256
- parts.push(value.slice(copiedThrough, start), replacement);
159257
- copiedThrough = end;
159258
- start = end - 1;
159259
- }
159260
- if (copiedThrough === 0) return value;
159261
- parts.push(value.slice(copiedThrough));
159262
- return parts.join("");
159263
- };
159264
- }
159265
- var init_identity_rewriter = __esm({
159266
- "src/project-source/identity-rewriter.ts"() {
159267
- "use strict";
159268
- }
159269
- });
159270
-
159271
159761
  // src/project-source/trusted-commit-verification.ts
159272
159762
  function verifyProjectSourceCommitAgainstStateV4(args) {
159273
159763
  const root = "/neo-source-verify-virtual";
@@ -159466,6 +159956,21 @@ function validateAssignments(value) {
159466
159956
  return assignments;
159467
159957
  }
159468
159958
  function derivedAssignment(pendingId2) {
159959
+ const genericArgument = pendingGenericArgumentIdentity(pendingId2);
159960
+ if (genericArgument !== null)
159961
+ return {
159962
+ ownerLocator: genericArgument.parentRecordId,
159963
+ derive: (parent, assignments) => {
159964
+ const parameter4 = isPendingId(genericArgument.genericParamId) ? assignments.get(genericArgument.genericParamId) : genericArgument.genericParamId;
159965
+ if (parameter4 === void 0)
159966
+ throw new ProjectSourceCommitVerificationError(
159967
+ `Generic argument assignment ${pendingId2} names parameter ${genericArgument.genericParamId}, which has no pending id assignment.`
159968
+ );
159969
+ return derivedGenericArgumentMemberId(parent, parameter4);
159970
+ },
159971
+ label: "Generic argument assignment",
159972
+ ownerNoun: "binding owner"
159973
+ };
159469
159974
  const tupleElement = pendingTupleElementIdentity(pendingId2);
159470
159975
  if (tupleElement !== null)
159471
159976
  return {
@@ -159564,6 +160069,15 @@ function relocatedAssignment(pendingId2, assignments, byPosition, used) {
159564
160069
  const key = positionIndependentPendingKey(pendingId2);
159565
160070
  const relocated = key === null ? void 0 : byPosition.get(key);
159566
160071
  if (relocated !== void 0) return relocated;
160072
+ const genericArgument = pendingGenericArgumentIdentity(pendingId2);
160073
+ if (genericArgument !== null) {
160074
+ const relocate = (id2) => !isPendingId(id2) || assignments.has(id2) ? id2 : relocatedAssignment(id2, assignments, byPosition, used);
160075
+ const parent = relocate(genericArgument.parentRecordId);
160076
+ const parameter4 = relocate(genericArgument.genericParamId);
160077
+ if (parent === null || parameter4 === null) return null;
160078
+ const rebuilt = pendingGenericArgumentMemberId(parent, parameter4);
160079
+ return assignments.has(rebuilt) ? rebuilt : null;
160080
+ }
159567
160081
  for (const [owner, rebuild] of [
159568
160082
  [pendingMemberValueMemberId(pendingId2), pendingMemberValueId],
159569
160083
  [pendingEntryMemberDeclaringId(pendingId2), pendingEntryMemberId],
@@ -159896,6 +160410,7 @@ var init_trusted_commit_verification = __esm({
159896
160410
  "use strict";
159897
160411
  init_tuple_element_member_id();
159898
160412
  init_identity_rewriter();
160413
+ init_generic_argument_member_id();
159899
160414
  init_lower_support();
159900
160415
  init_schema_source_validation();
159901
160416
  init_projectRecordBuckets();
@@ -159969,6 +160484,7 @@ function sourceCommitPreparation(args) {
159969
160484
  timestamp: args.serverTimestamp
159970
160485
  }),
159971
160486
  authoredValueSeeds: args.authoredValueSeeds,
160487
+ initializerReferenceOwners: args.initializerReferenceOwners,
159972
160488
  forceRecompile: args.forceRecompile,
159973
160489
  scriptSources: args.scriptSources,
159974
160490
  serverTimestamp: args.serverTimestamp
@@ -160156,7 +160672,9 @@ function replayStoredConstructionV4(args) {
160156
160672
  classes: document.classes,
160157
160673
  enums: document.enums,
160158
160674
  interfaces: document.interfaces,
160159
- constructors: document.constructors ?? []
160675
+ constructors: document.constructors ?? [],
160676
+ variants: document.variants ?? [],
160677
+ variantFolders: document.variantFolders ?? []
160160
160678
  }) : void 0);
160161
160679
  if (args.compileDocumentBodies === true) {
160162
160680
  if (compilationProject === void 0) {
@@ -160205,6 +160723,8 @@ function replayStoredConstructionV4(args) {
160205
160723
  enums: document.enums,
160206
160724
  interfaces: document.interfaces,
160207
160725
  constructors: document.constructors,
160726
+ variants: document.variants ?? [],
160727
+ variantFolders: document.variantFolders ?? [],
160208
160728
  member: compileMember,
160209
160729
  valueRow: candidate,
160210
160730
  valueId: args.valueId,
@@ -160276,7 +160796,9 @@ function compilePulledUncompiledConstructorsV4(document, compilationProject, rep
160276
160796
  classes: document.classes,
160277
160797
  enums: document.enums,
160278
160798
  interfaces: document.interfaces,
160279
- constructors: document.constructors ?? []
160799
+ constructors: document.constructors ?? [],
160800
+ variants: document.variants ?? [],
160801
+ variantFolders: document.variantFolders ?? []
160280
160802
  });
160281
160803
  const compileArgs = {
160282
160804
  project: document.project,
@@ -160287,6 +160809,8 @@ function compilePulledUncompiledConstructorsV4(document, compilationProject, rep
160287
160809
  enums: document.enums,
160288
160810
  interfaces: document.interfaces,
160289
160811
  constructors: document.constructors ?? [],
160812
+ variants: document.variants ?? [],
160813
+ variantFolders: document.variantFolders ?? [],
160290
160814
  compilationProject: project
160291
160815
  };
160292
160816
  for (const constructor2 of uncompiled) {
@@ -160310,7 +160834,9 @@ function compilePulledProjectDocumentForEvaluationV4(document, compilationProjec
160310
160834
  classes: document.classes,
160311
160835
  enums: document.enums,
160312
160836
  interfaces: document.interfaces,
160313
- constructors: document.constructors ?? []
160837
+ constructors: document.constructors ?? [],
160838
+ variants: document.variants ?? [],
160839
+ variantFolders: document.variantFolders ?? []
160314
160840
  });
160315
160841
  documentInitializerCompiler(document, sharedCompilationProject);
160316
160842
  const compileArgs = {
@@ -160322,6 +160848,8 @@ function compilePulledProjectDocumentForEvaluationV4(document, compilationProjec
160322
160848
  enums: document.enums,
160323
160849
  interfaces: document.interfaces,
160324
160850
  constructors: document.constructors ?? [],
160851
+ variants: document.variants ?? [],
160852
+ variantFolders: document.variantFolders ?? [],
160325
160853
  compilationProject: sharedCompilationProject
160326
160854
  };
160327
160855
  const constructors = document.constructors ?? [];
@@ -161477,6 +162005,9 @@ function buildValueEmitContext(records3, manifest, options = {}) {
161477
162005
  dictionaryKeyOptions: /* @__PURE__ */ new Map(),
161478
162006
  localizedTextIds: /* @__PURE__ */ new Set(),
161479
162007
  constructionReplays: /* @__PURE__ */ new Map(),
162008
+ constructorOwnedArguments: /* @__PURE__ */ new Map(),
162009
+ constructorArgumentGraph: {},
162010
+ constructorRelations: /* @__PURE__ */ new WeakMap(),
161480
162011
  constructorBodySchemaKeys: /* @__PURE__ */ new WeakMap(),
161481
162012
  activeStoredConstructorArguments: /* @__PURE__ */ new Set(),
161482
162013
  materializedConstructors: /* @__PURE__ */ new Map(),
@@ -162154,6 +162685,7 @@ function emitStoredConstructorExpression(context, member, valueId, visited = /*
162154
162685
  context,
162155
162686
  schemaClass2,
162156
162687
  value,
162688
+ resolvedMember,
162157
162689
  className,
162158
162690
  environment,
162159
162691
  visited,
@@ -163347,7 +163879,7 @@ function drainValueReferenceObligationsV4(state, manifest, options) {
163347
163879
  ...composeReferenceSitePosition(move.site, options.sourceTextByUri)
163348
163880
  });
163349
163881
  }
163350
- for (const obligation of [
163882
+ for (const obligation of options.obligations ?? [
163351
163883
  ...collectionValueObligations(manifest),
163352
163884
  ...options.registry.referenceObligations
163353
163885
  ]) {
@@ -163367,11 +163899,29 @@ function drainValueReferenceObligationsV4(state, manifest, options) {
163367
163899
  targetId = obligation.target.id;
163368
163900
  else if (obligation.target.spelling === "symbol")
163369
163901
  targetId = obligation.target.resolved.id;
163902
+ else if (obligation.target.spelling === "local")
163903
+ targetId = context.localValues.target(obligation.target.name);
163370
163904
  break;
163371
163905
  }
163372
163906
  if (targetId !== void 0 && (options.unavailableValueIds?.has(targetId) === true || options.registry.refusedValueIds.has(targetId)))
163373
163907
  continue;
163374
163908
  }
163909
+ if (options.deferredReferences !== void 0 && obligation.kind === "reference") {
163910
+ const target = obligation.target;
163911
+ if (target.spelling === "local") {
163912
+ const id2 = context.localValues.target(target.name);
163913
+ if (context.pendingValueIdentitySites.get(id2)?.materializedLocation !== void 0) {
163914
+ target.patch.ids[target.patch.index] = id2;
163915
+ options.deferredReferences.push(obligation);
163916
+ continue;
163917
+ }
163918
+ } else if (target.spelling === "id") {
163919
+ if (referenceTargetById(context, target.id, target.typeName) === null) {
163920
+ options.deferredReferences.push(obligation);
163921
+ continue;
163922
+ }
163923
+ }
163924
+ }
163375
163925
  const failure = settleReferenceObligation(
163376
163926
  context,
163377
163927
  obligation,
@@ -166332,10 +166882,24 @@ function lowerAuthoredValueRow(context, member, sourceExpression, expectedValueI
166332
166882
  );
166333
166883
  const checksCanonicalConstruction = requiresCanonicalConstruction && !projectedConstructionEditable;
166334
166884
  if (source.purpose === "stored" && storedConstructorArgs !== null || checksCanonicalConstruction) {
166885
+ const constructionCode = settleInitializerReferenceSpellings(
166886
+ context.localValues.executable(
166887
+ authoredConstruction2,
166888
+ bindingRuntimeIdentifiers(context, source)
166889
+ ).code,
166890
+ (call, site) => settledReferenceTarget(context, call, site, {
166891
+ member: resolvedMember,
166892
+ valueId: expectedValueId,
166893
+ source,
166894
+ expression
166895
+ }),
166896
+ context.syntax
166897
+ ).code;
166335
166898
  const construction = {
166336
166899
  valueId: expectedValueId,
166337
166900
  code: compiledCode,
166338
166901
  construction: authoredConstruction2,
166902
+ constructionCode,
166339
166903
  site: initializerSite
166340
166904
  };
166341
166905
  context.initializerReconciliations.set(
@@ -167221,13 +167785,16 @@ function requiredConstructorProjectionMap(classes, constructors, members2, class
167221
167785
  const required2 = requiredId === void 0 ? void 0 : constructors.get(requiredId);
167222
167786
  if (schemaClass2 === void 0 || required2 === void 0) return /* @__PURE__ */ new Map();
167223
167787
  const result = /* @__PURE__ */ new Map();
167788
+ const parameterNames = new Set(
167789
+ required2.arguments.map((parameter4) => parameter4.name)
167790
+ );
167224
167791
  for (const memberId of Object.values(schemaClass2.schema)) {
167225
167792
  const initializer = members2.get(memberId)?.defaultValue;
167226
167793
  if (initializer === null || initializer === void 0 || !("init" in initializer)) {
167227
167794
  continue;
167228
167795
  }
167229
167796
  const parameterName = initializer.init.code.trim();
167230
- if (required2.arguments.some((parameter4) => parameter4.name === parameterName)) {
167797
+ if (parameterNames.has(parameterName)) {
167231
167798
  result.set(parameterName, memberId);
167232
167799
  }
167233
167800
  }
@@ -167242,7 +167809,7 @@ function requiredConstructorProjectionMap(classes, constructors, members2, class
167242
167809
  );
167243
167810
  for (const forwarded of required2.baseArguments ?? []) {
167244
167811
  const sourceName = forwarded.code.trim();
167245
- if (!required2.arguments.some((parameter4) => parameter4.name === sourceName)) {
167812
+ if (!parameterNames.has(sourceName)) {
167246
167813
  continue;
167247
167814
  }
167248
167815
  const memberId = base.get(forwarded.name);
@@ -170052,6 +170619,7 @@ function classValueBody(context, member, value, visited, targetTyped, outerEnvir
170052
170619
  context,
170053
170620
  schemaClass2,
170054
170621
  value,
170622
+ member,
170055
170623
  name,
170056
170624
  environment,
170057
170625
  visited,
@@ -170073,6 +170641,7 @@ function classValueBody(context, member, value, visited, targetTyped, outerEnvir
170073
170641
  context,
170074
170642
  schemaClass2,
170075
170643
  value,
170644
+ member,
170076
170645
  name,
170077
170646
  environment,
170078
170647
  visited,
@@ -170154,7 +170723,7 @@ function classValueBody(context, member, value, visited, targetTyped, outerEnvir
170154
170723
  context,
170155
170724
  childMemberId,
170156
170725
  projection.memberIds
170157
- )) {
170726
+ ) && context.localValues?.byValueId.has(childId) !== true) {
170158
170727
  continue;
170159
170728
  }
170160
170729
  const childMember = context.members.get(childMemberId);
@@ -170251,7 +170820,20 @@ ${fields.map((field) => indentNeoSource(field, 2)).join(",\n")}
170251
170820
  projection.arguments
170252
170821
  ) : targetTyped ? "new()" : `new ${name}()`;
170253
170822
  if (typeof value.id === "string" && (storedConstruction !== null || projection.arguments.length > 0 || schemaClass2.requiredConstructorId !== void 0)) {
170254
- context.materializedConstructors.set(value.id, constructor2);
170823
+ const usesLocalArguments = storedArgumentEntries.some(
170824
+ ([, id2]) => context.localValues?.byValueId.has(id2)
170825
+ );
170826
+ const canonical = usesLocalArguments ? storedConstructorCallSource(
170827
+ { ...context, localValues: void 0 },
170828
+ schemaClass2,
170829
+ value,
170830
+ member,
170831
+ name,
170832
+ environment,
170833
+ /* @__PURE__ */ new Set(),
170834
+ targetTyped
170835
+ ) : null;
170836
+ context.materializedConstructors.set(value.id, canonical ?? constructor2);
170255
170837
  }
170256
170838
  if (typeof value.id === "string")
170257
170839
  context.materializedConstructorOverrideKeys.set(value.id, overrideKeys);
@@ -170522,6 +171104,7 @@ function materializedValueSubgraphsEqual(context, currentGraph, replayGraph, cur
170522
171104
  const typeInfo = resolveMemberDeclaredTypeInfo(
170523
171105
  resolvedMember,
170524
171106
  document.members,
171107
+ document.classes,
170525
171108
  null,
170526
171109
  genericEnv
170527
171110
  );
@@ -170587,7 +171170,95 @@ function genericSlotIsRequired(context, member, environment) {
170587
171170
  const binding = bindingId === void 0 ? void 0 : context.members.get(bindingId);
170588
171171
  return binding === void 0 || isRequiredMember(binding);
170589
171172
  }
170590
- function storedConstructorCallSource(context, schemaClass2, value, className, environment, visited, targetTyped, cloneAggregateArguments = false) {
171173
+ function constructorArgumentGraph(context) {
171174
+ const cached = context.constructorArgumentGraph.value;
171175
+ if (cached !== void 0) return cached;
171176
+ const parents = /* @__PURE__ */ new Map();
171177
+ const graph = context.readMaterializedGraph();
171178
+ for (const [id2, placement] of context.storedPlacements.placementByChildValueId) {
171179
+ const parent = context.values.get(placement.parentValueId);
171180
+ let segment;
171181
+ if (typeof parent?.classId === "string")
171182
+ segment = `!.${placement.schemaKey}`;
171183
+ else {
171184
+ const owner = graph.ownerForValue(placement.parentValueId);
171185
+ const keyEnumId = owner !== void 0 && isMemberDictionaryBase(owner) ? owner.keyEnumId ?? null : null;
171186
+ segment = `![${emitDictionaryKey(placement.schemaKey, dictionaryOptions2(context, keyEnumId))}]`;
171187
+ }
171188
+ parents.set(id2, { parentId: placement.parentValueId, segment });
171189
+ }
171190
+ for (const [id2, row] of context.values) {
171191
+ const children4 = graph.childrenByContainerId.get(id2);
171192
+ if (!Array.isArray(row.value) && children4 === void 0) continue;
171193
+ if (graph.ownerForValue(id2)?.kind !== 6 /* List */) continue;
171194
+ const ids = Array.isArray(row.value) ? row.value : children4?.map((child2) => child2.id) ?? [];
171195
+ for (const [index, childId] of ids.entries())
171196
+ if (typeof childId === "string")
171197
+ parents.set(childId, { parentId: id2, segment: `![${index}]` });
171198
+ }
171199
+ const children3 = /* @__PURE__ */ new Map();
171200
+ for (const [id2, parent] of parents) {
171201
+ const siblings = children3.get(parent.parentId);
171202
+ if (siblings === void 0) children3.set(parent.parentId, [id2]);
171203
+ else siblings.push(id2);
171204
+ }
171205
+ const intervals = /* @__PURE__ */ new Map();
171206
+ let next = 0;
171207
+ const stack = [];
171208
+ for (const id2 of context.values.keys())
171209
+ if (!parents.has(id2)) stack.push({ id: id2, exit: false });
171210
+ while (stack.length > 0) {
171211
+ const frame = stack.pop();
171212
+ if (frame.exit) {
171213
+ intervals.get(frame.id).end = next;
171214
+ continue;
171215
+ }
171216
+ if (intervals.has(frame.id))
171217
+ throw new Error(
171218
+ `Constructor argument ownership cycle reaches ${frame.id}.`
171219
+ );
171220
+ intervals.set(frame.id, { start: next++, end: 0 });
171221
+ stack.push({ id: frame.id, exit: true });
171222
+ for (const child2 of children3.get(frame.id) ?? [])
171223
+ stack.push({ id: child2, exit: false });
171224
+ }
171225
+ return context.constructorArgumentGraph.value = { parents, intervals };
171226
+ }
171227
+ function constructorArgumentRelations(context, value, argumentIds) {
171228
+ const cached = context.constructorRelations.get(value);
171229
+ if (cached !== void 0) return cached;
171230
+ const graph = constructorArgumentGraph(context);
171231
+ const ordered = [...argumentIds].flatMap((id2) => {
171232
+ const interval = graph.intervals.get(id2);
171233
+ return interval === void 0 ? [] : [{ id: id2, ...interval }];
171234
+ }).sort((left, right) => left.start - right.start);
171235
+ const stack = [];
171236
+ const result = /* @__PURE__ */ new Map();
171237
+ for (const current of ordered) {
171238
+ while (stack.length > 0 && stack[stack.length - 1].end <= current.start)
171239
+ stack.pop();
171240
+ const parent = stack[stack.length - 1];
171241
+ if (parent !== void 0) result.set(current.id, { parentId: parent.id });
171242
+ stack.push(current);
171243
+ }
171244
+ context.constructorRelations.set(value, result);
171245
+ return result;
171246
+ }
171247
+ function concreteArgumentTypeName(context, type2, valueId, environment) {
171248
+ const row = context.values.get(valueId);
171249
+ if (typeof row?.classId !== "string")
171250
+ return storedSchemaTypeName(context, type2, environment, valueId);
171251
+ const settled = type2.kind === "generic" ? storedGenericArgumentType(context, type2, environment) : type2;
171252
+ if (settled.kind === "class" && settled.classId === row.classId)
171253
+ return storedSchemaTypeName(context, settled, environment, valueId);
171254
+ return classValueTypeName(
171255
+ context,
171256
+ row.classId,
171257
+ row,
171258
+ valueGenericEnvironment(row, environment)
171259
+ );
171260
+ }
171261
+ function storedConstructorCallSource(context, schemaClass2, value, member, className, environment, visited, targetTyped, cloneAggregateArguments = false, ownedArguments) {
170591
171262
  const constructorArgs2 = value.constructorArgs;
170592
171263
  if (!isObjectRecord(constructorArgs2)) return null;
170593
171264
  const manifestClass = context.manifestClasses.get(
@@ -170618,7 +171289,103 @@ function storedConstructorCallSource(context, schemaClass2, value, className, en
170618
171289
  manifestClass,
170619
171290
  recordedConstructorId
170620
171291
  );
170621
- const argumentsValue = constructor2.arguments.flatMap((argument2, index) => {
171292
+ const projectedMembers = requiredConstructorProjectionMap(
171293
+ context.manifestClasses,
171294
+ context.manifestConstructors,
171295
+ context.manifestMembers,
171296
+ stringField2(schemaClass2, "id"),
171297
+ /* @__PURE__ */ new Set()
171298
+ );
171299
+ const aggregateTypes = /* @__PURE__ */ new Map();
171300
+ for (const [index, argument2] of constructor2.arguments.entries()) {
171301
+ const id2 = constructorArgs2[`__arg_${index}__`];
171302
+ const type2 = argument2.type.kind === "generic" ? storedGenericArgumentType(context, argument2.type, environment) : argument2.type;
171303
+ if (typeof id2 === "string" && ["class", "interface", "list", "set", "dictionary"].includes(type2.kind))
171304
+ aggregateTypes.set(id2, type2);
171305
+ }
171306
+ const needsGraphReplay = aggregateTypes.size > 1 && [...aggregateTypes.keys()].some(
171307
+ (id2) => constructorArgumentBodySchemaKey(context, value, id2) !== void 0 || !isSharedConstructorArgument(context, id2, false)
171308
+ );
171309
+ const relations = needsGraphReplay ? constructorArgumentRelations(
171310
+ context,
171311
+ value,
171312
+ new Set(aggregateTypes.keys())
171313
+ ) : /* @__PURE__ */ new Map();
171314
+ const relatedArguments = new Set(relations.keys());
171315
+ for (const relation of relations.values())
171316
+ relatedArguments.add(relation.parentId);
171317
+ const readOwnedArguments = () => {
171318
+ const valueId = stringField2(value, "id");
171319
+ const cached = context.constructorOwnedArguments.get(valueId);
171320
+ if (cached !== void 0) return cached;
171321
+ const code = storedConstructorCallSource(
171322
+ context,
171323
+ schemaClass2,
171324
+ value,
171325
+ member,
171326
+ className,
171327
+ environment,
171328
+ /* @__PURE__ */ new Set(),
171329
+ targetTyped,
171330
+ true,
171331
+ new Set(
171332
+ Object.values(constructorArgs2).filter(
171333
+ (argument2) => typeof argument2 === "string"
171334
+ )
171335
+ )
171336
+ );
171337
+ if (code === null)
171338
+ throw new Error(`Stored construction ${valueId} has no replay call.`);
171339
+ if (context.storedValueBase === void 0)
171340
+ context.constructorOwnershipReplayContext ??= context.readReplayContext();
171341
+ if (context.constructorOwnershipReplayContext === void 0) {
171342
+ const document = context.readDocument();
171343
+ let changed = false;
171344
+ const values = document.values.map((row) => {
171345
+ if (!isInitValueContent(row)) return row;
171346
+ const stored = context.storedValueBase?.get(row.id);
171347
+ if (!isMemberValue(stored) || !isLiteralValueContent(stored))
171348
+ return row;
171349
+ changed = true;
171350
+ return stored;
171351
+ });
171352
+ context.constructorOwnershipReplayContext = changed ? createPulledConstructionReplayContext({
171353
+ document: { ...document, values }
171354
+ }) : context.readReplayContext();
171355
+ }
171356
+ const replayContext = context.constructorOwnershipReplayContext;
171357
+ const rows = replayStoredConstructionV4({
171358
+ records: context.records,
171359
+ document: replayContext.document,
171360
+ valueId,
171361
+ code,
171362
+ member: concreteClassMemberForReplay(context, member, environment),
171363
+ compilationProject: context.readCompilationProject(),
171364
+ replayContext
171365
+ });
171366
+ const root = rows.get(valueId);
171367
+ const bodyIds = new Set(
171368
+ isObjectRecord(root?.value) ? Object.values(root.value) : []
171369
+ );
171370
+ const replayArguments2 = isObjectRecord(root?.constructorArgs) ? root.constructorArgs : {};
171371
+ const owned = /* @__PURE__ */ new Set();
171372
+ for (const [key, argument2] of Object.entries(constructorArgs2)) {
171373
+ if (typeof argument2 === "string" && bodyIds.has(replayArguments2[key]))
171374
+ owned.add(argument2);
171375
+ }
171376
+ context.constructorOwnedArguments.set(valueId, owned);
171377
+ const allBodyArgumentsOwned = Object.values(constructorArgs2).every(
171378
+ (argument2) => constructorArgumentBodySchemaKey(context, value, argument2) === void 0 || typeof argument2 === "string" && owned.has(argument2)
171379
+ );
171380
+ if (allBodyArgumentsOwned && replayContext.document === context.readDocument())
171381
+ context.constructionReplays.set(valueId, rows);
171382
+ return owned;
171383
+ };
171384
+ const argumentUses = /* @__PURE__ */ new Map();
171385
+ for (const argument2 of Object.values(constructorArgs2))
171386
+ if (typeof argument2 === "string")
171387
+ argumentUses.set(argument2, (argumentUses.get(argument2) ?? 0) + 1);
171388
+ const preparedArguments = constructor2.arguments.flatMap((argument2, index) => {
170622
171389
  const key = `__arg_${index}__`;
170623
171390
  if (!(key in constructorArgs2)) {
170624
171391
  if (argument2.default !== null || argument2.type.nullable) return [];
@@ -170631,42 +171398,132 @@ function storedConstructorCallSource(context, schemaClass2, value, className, en
170631
171398
  schemaClass2,
170632
171399
  value,
170633
171400
  constructorArgs2[key],
170634
- argument2.name
171401
+ argument2.name,
171402
+ projectedMembers
170635
171403
  );
170636
- return [
170637
- `${argument2.name}: ${storedConstructorArgumentSource(
171404
+ const bodySchemaKey = constructorArgumentBodySchemaKey(
171405
+ context,
171406
+ value,
171407
+ constructorArgs2[key]
171408
+ );
171409
+ let constructorOwnsGraph = bodySchemaKey !== void 0;
171410
+ const argumentValue = constructorArgs2[key];
171411
+ if (constructorOwnsGraph && typeof argumentValue === "string") {
171412
+ if (ownedArguments !== void 0)
171413
+ constructorOwnsGraph = ownedArguments.has(argumentValue);
171414
+ else if (projectedMembers.has(argument2.name) && argumentUses.get(argumentValue) === 1 && !relatedArguments.has(argumentValue))
171415
+ constructorOwnsGraph = settledMember?.kind !== 9 /* Lookup */;
171416
+ else constructorOwnsGraph = readOwnedArguments().has(argumentValue);
171417
+ }
171418
+ return [{ argument: argument2, argumentValue, settledMember, constructorOwnsGraph }];
171419
+ });
171420
+ const replayArguments = new Map(
171421
+ preparedArguments.flatMap(
171422
+ (entry) => typeof entry.argumentValue === "string" && aggregateTypes.has(entry.argumentValue) ? [[entry.argumentValue, entry]] : []
171423
+ )
171424
+ );
171425
+ const ownedReplayArguments = new Set(
171426
+ preparedArguments.flatMap(
171427
+ (entry) => entry.constructorOwnsGraph && typeof entry.argumentValue === "string" ? [entry.argumentValue] : []
171428
+ )
171429
+ );
171430
+ const bindings = /* @__PURE__ */ new Map();
171431
+ const declarations = [];
171432
+ const bindArgument = (id2) => {
171433
+ const bound = bindings.get(id2);
171434
+ if (bound !== void 0) return bound;
171435
+ const entry = replayArguments.get(id2);
171436
+ if (entry === void 0)
171437
+ throw new Error(
171438
+ `Constructor replay argument ${id2} has no typed parameter.`
171439
+ );
171440
+ const relation = relations.get(id2);
171441
+ const parent = relation === void 0 ? void 0 : bindArgument(relation.parentId);
171442
+ const name = `__neo_argument_${bindings.size}`;
171443
+ const typeName = concreteArgumentTypeName(
171444
+ context,
171445
+ entry.argument.type,
171446
+ id2,
171447
+ environment
171448
+ );
171449
+ if (relation !== void 0 && parent !== void 0) {
171450
+ const graph = constructorArgumentGraph(context);
171451
+ const path = [];
171452
+ let cursor = id2;
171453
+ while (!bindings.has(cursor)) {
171454
+ const edge = graph.parents.get(cursor);
171455
+ if (edge === void 0)
171456
+ throw new Error(
171457
+ `Constructor argument ${cursor} has no owning path to ${relation.parentId}.`
171458
+ );
171459
+ path.push({ id: cursor, segment: edge.segment });
171460
+ cursor = edge.parentId;
171461
+ }
171462
+ let receiver = bindings.get(cursor);
171463
+ for (const step of path.reverse()) {
171464
+ const stepName = `__neo_argument_${bindings.size}`;
171465
+ const source = `${receiver}${step.segment}`;
171466
+ const row = context.values.get(step.id);
171467
+ if (typeof row?.classId === "string") {
171468
+ const concreteType = step.id === id2 ? typeName : classValueTypeName(
171469
+ context,
171470
+ row.classId,
171471
+ row,
171472
+ valueGenericEnvironment(row, environment)
171473
+ );
171474
+ declarations.push(
171475
+ `if (${source} is not ${concreteType} ${stepName}) throw ${quote3(`Constructor argument path ${step.id} no longer has type ${concreteType}.`)};`
171476
+ );
171477
+ } else declarations.push(`var ${stepName} = ${source}!;`);
171478
+ bindings.set(step.id, stepName);
171479
+ receiver = stepName;
171480
+ }
171481
+ return receiver;
171482
+ } else {
171483
+ const owns = ownedArguments?.has(id2) ?? ownedReplayArguments.has(id2);
171484
+ const source = storedConstructorArgumentSource(
170638
171485
  context,
170639
- argument2.type,
170640
- constructorArgs2[key],
171486
+ entry.argument.type,
171487
+ id2,
170641
171488
  environment,
170642
171489
  visited,
170643
- cloneAggregateArguments,
170644
- settledMember?.payload === 1 /* Partial */,
170645
- // Emit the argument's graph INLINE only when this row's own body names
170646
- // it. A P75-sparse root settles a member through the declared
170647
- // projection instead (see `settledMemberForConstructorArgument`), and
170648
- // that answer is a spelling fact, not an ownership fact: a shared
170649
- // collection row passed as `new Placed(item)` settles `Item` while
170650
- // staying owned by `root.Assets.Items`. Reading it as ownership
170651
- // re-declared that external graph under the construction, and the
170652
- // emitter then refused the whole pull with a containment cycle on the
170653
- // re-declared row's own children.
170654
- constructorArgumentBodySchemaKey(
170655
- context,
170656
- value,
170657
- constructorArgs2[key]
170658
- ) !== void 0
170659
- )}`
170660
- ];
171490
+ true,
171491
+ entry.settledMember?.payload === 1 /* Partial */,
171492
+ owns
171493
+ );
171494
+ declarations.push(`${typeName} ${name} = ${source};`);
171495
+ }
171496
+ bindings.set(id2, name);
171497
+ return name;
171498
+ };
171499
+ const argumentsValue = preparedArguments.map((entry) => {
171500
+ const { argument: argument2, argumentValue, settledMember, constructorOwnsGraph } = entry;
171501
+ if (cloneAggregateArguments && typeof argumentValue === "string" && aggregateTypes.has(argumentValue) && ((argumentUses.get(argumentValue) ?? 0) > 1 || relatedArguments.has(argumentValue)))
171502
+ return `${argument2.name}: ${bindArgument(argumentValue)}`;
171503
+ return `${argument2.name}: ${storedConstructorArgumentSource(
171504
+ context,
171505
+ argument2.type,
171506
+ argumentValue,
171507
+ environment,
171508
+ visited,
171509
+ cloneAggregateArguments,
171510
+ settledMember?.payload === 1 /* Partial */,
171511
+ constructorOwnsGraph
171512
+ )}`;
170661
171513
  });
170662
- return constructorCallSource(
171514
+ const call = constructorCallSource(
170663
171515
  targetTyped ? "new" : `new ${className}`,
170664
171516
  argumentsValue
170665
171517
  );
171518
+ return declarations.length === 0 ? call : `(() => { ${declarations.join(" ")} return ${call}; })()`;
170666
171519
  }
170667
- function settledMemberForConstructorArgument(context, schemaClass2, value, argument2, argumentName) {
171520
+ function settledMemberForConstructorArgument(context, schemaClass2, value, argument2, argumentName, projectedMembers) {
170668
171521
  if (typeof argument2 !== "string") return void 0;
170669
171522
  const schema = isObjectRecord(schemaClass2.schema) ? schemaClass2.schema : {};
171523
+ const projectedMemberId = projectedMembers.get(argumentName);
171524
+ if (projectedMemberId !== void 0) {
171525
+ return context.members.get(projectedMemberId);
171526
+ }
170670
171527
  const bodySchemaKey = constructorArgumentBodySchemaKey(
170671
171528
  context,
170672
171529
  value,
@@ -170675,16 +171532,6 @@ function settledMemberForConstructorArgument(context, schemaClass2, value, argum
170675
171532
  if (bodySchemaKey !== void 0) {
170676
171533
  return memberForSchemaKey(context, schema, bodySchemaKey);
170677
171534
  }
170678
- const projectedMemberId = requiredConstructorProjectionMap(
170679
- context.manifestClasses,
170680
- context.manifestConstructors,
170681
- context.manifestMembers,
170682
- stringField2(schemaClass2, "id"),
170683
- /* @__PURE__ */ new Set()
170684
- ).get(argumentName);
170685
- if (projectedMemberId !== void 0) {
170686
- return context.members.get(projectedMemberId);
170687
- }
170688
171535
  const namedSchemaKey = schemaKeyForParameterName(schema, argumentName);
170689
171536
  return namedSchemaKey === void 0 ? void 0 : memberForSchemaKey(context, schema, namedSchemaKey);
170690
171537
  }
@@ -171187,7 +172034,12 @@ function storedAggregateReplaySource(context, type2, valueId, environment, const
171187
172034
  `Stored ${type2.kind} constructor argument references missing value row ${valueId}.`
171188
172035
  );
171189
172036
  }
171190
- const typeName = storedSchemaTypeName(context, type2, environment, valueId);
172037
+ const typeName = concreteArgumentTypeName(
172038
+ context,
172039
+ type2,
172040
+ valueId,
172041
+ environment
172042
+ );
171191
172043
  const reference2 = `Reference<${typeName}>(id: ${quote3(valueId)})`;
171192
172044
  return isSharedConstructorArgument(context, valueId, constructorOwnsGraph) ? reference2 : `${reference2}.Clone()`;
171193
172045
  }
@@ -171358,8 +172210,10 @@ function storedTypedRowSource(context, type2, valueId, environment, visited, wri
171358
172210
  );
171359
172211
  }
171360
172212
  }
171361
- if (isSharedConstructorArgument(context, valueId, constructorOwnsGraph)) {
171362
- return `Reference<${storedSchemaTypeName(context, type2, environment, valueId)}>(id: ${quote3(valueId)})`;
172213
+ if (context.localValues?.byValueId.has(valueId) || isSharedConstructorArgument(context, valueId, constructorOwnsGraph)) {
172214
+ const local = context.localValues?.byValueId.get(valueId);
172215
+ const target = local === void 0 ? `id: ${quote3(valueId)}` : local.name;
172216
+ return `Reference<${storedSchemaTypeName(context, type2, environment, valueId)}>(${target})`;
171363
172217
  }
171364
172218
  if (context.activeStoredConstructorArguments.has(valueId)) {
171365
172219
  throw new Error(
@@ -171923,7 +172777,7 @@ function referenceValue(context, member, body, dialogue, slotTypeName = null) {
171923
172777
  return `Reference<${dialogueSymbol}>(${dialogueSymbol})`;
171924
172778
  }
171925
172779
  }
171926
- const symbol = context.localValues?.byValueId.get(id2)?.name ?? context.symbolsByValueId.get(id2);
172780
+ const symbol = (context.values.has(id2) ? context.localValues?.byValueId.get(id2)?.name : void 0) ?? context.symbolsByValueId.get(id2);
171927
172781
  if (symbol !== void 0) return `Reference(${symbol})`;
171928
172782
  if (slotTypeName !== null) {
171929
172783
  const path = slotRootPath(context, id2);
@@ -173197,7 +174051,9 @@ function buildNeoScriptProject(document) {
173197
174051
  classes: document.classes,
173198
174052
  enums: document.enums,
173199
174053
  interfaces: document.interfaces,
173200
- constructors: document.constructors ?? []
174054
+ constructors: document.constructors ?? [],
174055
+ variants: document.variants,
174056
+ variantFolders: document.variantFolders
173201
174057
  });
173202
174058
  }
173203
174059
  function neoScriptProjectFingerprint(document) {
@@ -173413,9 +174269,7 @@ function reconcileMaterializedInitializersV4(args) {
173413
174269
  member: owner,
173414
174270
  compilationProject: project
173415
174271
  });
173416
- const authored = compiled(
173417
- constructorExpressionSlice(reconciliation.code)
173418
- );
174272
+ const authored = compiled(reconciliation.constructionCode);
173419
174273
  if (authored === null || !sameCompiledProgram(authored, compiled(canonicalExpression))) {
173420
174274
  replayableValueIds.add(valueId);
173421
174275
  }
@@ -173847,6 +174701,13 @@ function materializeInitializersLocallyV4(args) {
173847
174701
  },
173848
174702
  valueIds: compiledBodyIds
173849
174703
  });
174704
+ const failures = [];
174705
+ const unavailableRootIds = /* @__PURE__ */ new Set();
174706
+ const onFailure = args.collectErrors === true ? (ids, error) => {
174707
+ const dependent = error instanceof PendingInitializerDependency && unavailableRootIds.has(error.valueId);
174708
+ for (const id2 of ids) unavailableRootIds.add(id2);
174709
+ if (!dependent) failures.push(error);
174710
+ } : void 0;
173850
174711
  const compiledInitializers = /* @__PURE__ */ new Map();
173851
174712
  const templateContext = createPulledConstructionReplayContext({
173852
174713
  document: authoredDocument,
@@ -173859,19 +174720,25 @@ function materializeInitializersLocallyV4(args) {
173859
174720
  walkedRootOwners,
173860
174721
  batch.valuesById
173861
174722
  );
173862
- replayStoredConstructionV4({
173863
- records: records3,
173864
- document: authoredDocument,
173865
- valueId: id2,
173866
- code: initializerCode(records3, id2),
173867
- compilationProject,
173868
- replayContext: templateContext,
173869
- member: rootOwners.get(id2),
173870
- initializerOwnerClass: ownerContext.declaringClass,
173871
- lexicalThisClass: ownerContext.lexicalThisClass,
173872
- evaluate: false,
173873
- onCompiledInitializer: (init) => compiledInitializers.set(id2, init)
173874
- });
174723
+ try {
174724
+ replayStoredConstructionV4({
174725
+ records: records3,
174726
+ document: authoredDocument,
174727
+ valueId: id2,
174728
+ code: initializerCode(records3, id2),
174729
+ compilationProject,
174730
+ replayContext: templateContext,
174731
+ member: rootOwners.get(id2),
174732
+ initializerOwnerClass: ownerContext.declaringClass,
174733
+ lexicalThisClass: ownerContext.lexicalThisClass,
174734
+ evaluate: false,
174735
+ onCompiledInitializer: (init) => compiledInitializers.set(id2, init)
174736
+ });
174737
+ } catch (error) {
174738
+ if (onFailure === void 0) throw error;
174739
+ onFailure([id2], error);
174740
+ pendingRoots.delete(id2);
174741
+ }
173875
174742
  }
173876
174743
  const typeMembers = compiledConstructionTypeMembers(
173877
174744
  authoredDocument.members,
@@ -173886,135 +174753,169 @@ function materializeInitializersLocallyV4(args) {
173886
174753
  batch = createInitializerMaterializationBatch(replayDocument, pendingRoots);
173887
174754
  }
173888
174755
  batch.upsert(compiledClosures);
173889
- materializeInitializerDependencies(pendingRoots, (sourceValueId) => {
173890
- const batchDocument = batch.document();
173891
- const document = {
173892
- ...replayDocument,
173893
- values: batchDocument.values,
173894
- databaseVM: batchDocument.databaseVM
173895
- };
173896
- const rootOwner = rootOwners.get(sourceValueId);
173897
- if (rootOwner === void 0) {
173898
- throw new Error(
173899
- `CLI initializer materialization cannot resolve the owning member for root "${sourceValueId}".`
173900
- );
173901
- }
173902
- const replayContext = createPulledConstructionReplayContext({
173903
- document,
173904
- valuesById: batch.valuesById
173905
- });
173906
- const code = initializerCode(records3, sourceValueId);
173907
- let compiledInitializer;
173908
- let pinned = {
173909
- pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
173910
- pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
173911
- };
173912
- const evaluated = replayStoredConstructionV4({
173913
- records: records3,
173914
- document,
173915
- valueId: sourceValueId,
173916
- code,
173917
- compilationProject,
173918
- replayContext,
173919
- member: rootOwner,
173920
- compiledInitializer: compiledInitializers.get(sourceValueId),
173921
- onCompiledInitializer: (init) => {
173922
- compiledInitializer = init;
173923
- compiledInitializers.set(sourceValueId, init);
173924
- },
173925
- onConstructionPreservation: (keys) => {
173926
- pinned = keys;
174756
+ const resolvedLocalIds = /* @__PURE__ */ new Map();
174757
+ materializeInitializerDependencies(
174758
+ pendingRoots,
174759
+ (sourceValueId) => {
174760
+ const batchDocument = batch.document();
174761
+ const database = batchDocument.databaseVM;
174762
+ if (database !== void 0) {
174763
+ batchDocument.databaseVM = {
174764
+ ...database,
174765
+ valueById: (id2) => {
174766
+ if (unavailableRootIds.has(id2))
174767
+ throw new PendingInitializerDependency(id2);
174768
+ const location3 = args.localReferenceLocations?.get(id2);
174769
+ if (location3 === void 0) return database.valueById(id2);
174770
+ if (unavailableRootIds.has(location3.rootId))
174771
+ throw new PendingInitializerDependency(location3.rootId);
174772
+ if (pendingRoots.has(location3.rootId))
174773
+ throw new PendingInitializerDependency(location3.rootId);
174774
+ const target = resolvedLocalIds.get(id2) ?? storedValueAtPathV4(
174775
+ batch.valuesById,
174776
+ location3.rootId,
174777
+ location3.path
174778
+ );
174779
+ if (target === null)
174780
+ throw new Error(
174781
+ `Local value ${id2} has no row at its owning path.`
174782
+ );
174783
+ resolvedLocalIds.set(id2, target);
174784
+ return database.valueById(target);
174785
+ }
174786
+ };
173927
174787
  }
173928
- });
173929
- const evaluatedRoot = evaluated.get(sourceValueId);
173930
- if (evaluatedRoot === void 0 || !isMemberValue(evaluatedRoot)) {
173931
- throw new Error(
173932
- `CLI initializer materialization produced no root row for value "${sourceValueId}".`
173933
- );
173934
- }
173935
- if (compiledInitializer === void 0) {
173936
- throw new Error(
173937
- `CLI initializer materialization did not compile root "${sourceValueId}".`
173938
- );
173939
- }
173940
- const evaluatedChildren = [...evaluated.entries()].flatMap(([id2, row]) => {
173941
- if (id2 === sourceValueId) return [];
173942
- if (!isMemberValue(row)) {
174788
+ const document = {
174789
+ ...replayDocument,
174790
+ values: batchDocument.values,
174791
+ databaseVM: batchDocument.databaseVM
174792
+ };
174793
+ const rootOwner = rootOwners.get(sourceValueId);
174794
+ if (rootOwner === void 0) {
173943
174795
  throw new Error(
173944
- `CLI initializer materialization for "${sourceValueId}" produced an invalid value row.`
174796
+ `CLI initializer materialization cannot resolve the owning member for root "${sourceValueId}".`
173945
174797
  );
173946
174798
  }
173947
- return [row];
173948
- });
173949
- const baseline = replayStoredConstructionV4({
173950
- records: records3,
173951
- document,
173952
- valueId: sourceValueId,
173953
- code,
173954
- compilationProject,
173955
- replayContext,
173956
- member: rootOwner,
173957
- compiledInitializer,
173958
- omitConstructionFields: true
173959
- });
173960
- const baselineRoot = baseline.get(sourceValueId);
173961
- if (baselineRoot === void 0 || !isMemberValue(baselineRoot)) {
173962
- throw new Error(
173963
- `CLI initializer baseline produced no root row for value "${sourceValueId}".`
174799
+ const replayContext = createPulledConstructionReplayContext({
174800
+ document,
174801
+ valuesById: batch.valuesById
174802
+ });
174803
+ const code = initializerCode(records3, sourceValueId);
174804
+ let compiledInitializer;
174805
+ let pinned = {
174806
+ pinnedRootSchemaKeys: /* @__PURE__ */ new Set(),
174807
+ pinnedSchemaKeysByValueId: /* @__PURE__ */ new Map()
174808
+ };
174809
+ const evaluated = replayStoredConstructionV4({
174810
+ records: records3,
174811
+ document,
174812
+ valueId: sourceValueId,
174813
+ code,
174814
+ compilationProject,
174815
+ replayContext,
174816
+ member: rootOwner,
174817
+ compiledInitializer: compiledInitializers.get(sourceValueId),
174818
+ onCompiledInitializer: (init) => {
174819
+ compiledInitializer = init;
174820
+ compiledInitializers.set(sourceValueId, init);
174821
+ },
174822
+ onConstructionPreservation: (keys) => {
174823
+ pinned = keys;
174824
+ }
174825
+ });
174826
+ const evaluatedRoot = evaluated.get(sourceValueId);
174827
+ if (evaluatedRoot === void 0 || !isMemberValue(evaluatedRoot)) {
174828
+ throw new Error(
174829
+ `CLI initializer materialization produced no root row for value "${sourceValueId}".`
174830
+ );
174831
+ }
174832
+ if (compiledInitializer === void 0) {
174833
+ throw new Error(
174834
+ `CLI initializer materialization did not compile root "${sourceValueId}".`
174835
+ );
174836
+ }
174837
+ const evaluatedChildren = [...evaluated.entries()].flatMap(
174838
+ ([id2, row]) => {
174839
+ if (id2 === sourceValueId) return [];
174840
+ if (!isMemberValue(row)) {
174841
+ throw new Error(
174842
+ `CLI initializer materialization for "${sourceValueId}" produced an invalid value row.`
174843
+ );
174844
+ }
174845
+ return [row];
174846
+ }
173964
174847
  );
173965
- }
173966
- const baselineChildren = [...baseline.entries()].flatMap(([id2, row]) => {
173967
- if (id2 === sourceValueId) return [];
173968
- if (!isMemberValue(row)) {
174848
+ const baseline = replayStoredConstructionV4({
174849
+ records: records3,
174850
+ document,
174851
+ valueId: sourceValueId,
174852
+ code,
174853
+ compilationProject,
174854
+ replayContext,
174855
+ member: rootOwner,
174856
+ compiledInitializer,
174857
+ omitConstructionFields: true
174858
+ });
174859
+ const baselineRoot = baseline.get(sourceValueId);
174860
+ if (baselineRoot === void 0 || !isMemberValue(baselineRoot)) {
173969
174861
  throw new Error(
173970
- `CLI initializer baseline for "${sourceValueId}" produced an invalid value row.`
174862
+ `CLI initializer baseline produced no root row for value "${sourceValueId}".`
173971
174863
  );
173972
174864
  }
173973
- return [row];
173974
- });
173975
- const sparse2 = sparsifyConstructedInstance({
173976
- localizedTextIds,
173977
- document,
173978
- rootMember: rootOwner,
173979
- constructed: {
173980
- root: evaluatedRoot,
173981
- createdChildren: evaluatedChildren
173982
- },
173983
- baseline: {
173984
- root: baselineRoot,
173985
- createdChildren: baselineChildren
173986
- },
173987
- // §4: a call-site field is an explicit override even when it equals the
173988
- // class default, so the evaluated construction's own field list is what
173989
- // pins rows against collapse. Push preparation pins the same set.
173990
- snapshot: pinned.snapshot,
173991
- pinnedRootSchemaKeys: pinned.pinnedRootSchemaKeys,
173992
- pinnedSchemaKeysByValueId: pinned.pinnedSchemaKeysByValueId,
173993
- bindingTargets,
173994
- virtualValueIdForSource: (instanceRootId, sourceIdentity3) => isPendingId(instanceRootId) || hasPendingVirtualSourceIdentity(sourceIdentity3) ? pendingVirtualValueId(instanceRootId, sourceIdentity3) : virtualValueId(instanceRootId, sourceIdentity3)
173995
- });
173996
- const evaluatedRows = [sparse2.root, ...sparse2.createdChildren];
173997
- assertStoredClosuresKeepNoCaptures({
173998
- sourceValueId,
173999
- rows: evaluatedRows,
174000
- constructors: document.constructors ?? []
174001
- });
174002
- roots.push({
174003
- sourceValueId,
174004
- rows: evaluatedRows.map((row) => ({ ...row }))
174005
- });
174006
- for (const row of evaluatedRows) {
174007
- records3.set(`value:${row.id}`, {
174008
- recordKind: "value",
174009
- recordId: row.id,
174010
- contentHash: "local-materialization",
174011
- deleted: false,
174012
- data: row
174865
+ const baselineChildren = [...baseline.entries()].flatMap(([id2, row]) => {
174866
+ if (id2 === sourceValueId) return [];
174867
+ if (!isMemberValue(row)) {
174868
+ throw new Error(
174869
+ `CLI initializer baseline for "${sourceValueId}" produced an invalid value row.`
174870
+ );
174871
+ }
174872
+ return [row];
174013
174873
  });
174014
- }
174015
- batch.upsert(evaluatedRows);
174016
- });
174017
- if (validatesTouched) {
174874
+ const sparse2 = sparsifyConstructedInstance({
174875
+ localizedTextIds,
174876
+ document,
174877
+ rootMember: rootOwner,
174878
+ constructed: {
174879
+ root: evaluatedRoot,
174880
+ createdChildren: evaluatedChildren
174881
+ },
174882
+ baseline: {
174883
+ root: baselineRoot,
174884
+ createdChildren: baselineChildren
174885
+ },
174886
+ // §4: a call-site field is an explicit override even when it equals the
174887
+ // class default, so the evaluated construction's own field list is what
174888
+ // pins rows against collapse. Push preparation pins the same set.
174889
+ snapshot: pinned.snapshot,
174890
+ pinnedRootSchemaKeys: pinned.pinnedRootSchemaKeys,
174891
+ pinnedSchemaKeysByValueId: pinned.pinnedSchemaKeysByValueId,
174892
+ bindingTargets,
174893
+ virtualValueIdForSource: (instanceRootId, sourceIdentity3) => isPendingId(instanceRootId) || hasPendingVirtualSourceIdentity(sourceIdentity3) ? pendingVirtualValueId(instanceRootId, sourceIdentity3) : virtualValueId(instanceRootId, sourceIdentity3)
174894
+ });
174895
+ const evaluatedRows = [sparse2.root, ...sparse2.createdChildren];
174896
+ assertStoredClosuresKeepNoCaptures({
174897
+ sourceValueId,
174898
+ rows: evaluatedRows,
174899
+ constructors: document.constructors ?? []
174900
+ });
174901
+ roots.push({
174902
+ sourceValueId,
174903
+ rows: evaluatedRows.map((row) => ({ ...row }))
174904
+ });
174905
+ for (const row of evaluatedRows) {
174906
+ records3.set(`value:${row.id}`, {
174907
+ recordKind: "value",
174908
+ recordId: row.id,
174909
+ contentHash: "local-materialization",
174910
+ deleted: false,
174911
+ data: row
174912
+ });
174913
+ }
174914
+ batch.upsert(evaluatedRows);
174915
+ },
174916
+ onFailure
174917
+ );
174918
+ if (validatesTouched && failures.length === 0) {
174018
174919
  assertPulledConstructorsCompiled(pulledDocument);
174019
174920
  const batchDocument = batch.document();
174020
174921
  const document = {
@@ -174023,19 +174924,34 @@ function materializeInitializersLocallyV4(args) {
174023
174924
  values: batchDocument.values,
174024
174925
  databaseVM: batchDocument.databaseVM
174025
174926
  };
174026
- assertTouchedInitializersConstruct({
174027
- document: {
174028
- ...document,
174029
- initializerCompiler: documentInitializerCompiler(
174030
- document,
174031
- compilationProject
174032
- )
174033
- },
174034
- prepared: written,
174035
- replayedValueIds: replayedRoots
174036
- });
174927
+ try {
174928
+ assertTouchedInitializersConstruct({
174929
+ document: {
174930
+ ...document,
174931
+ initializerCompiler: documentInitializerCompiler(
174932
+ document,
174933
+ compilationProject
174934
+ )
174935
+ },
174936
+ prepared: written,
174937
+ replayedValueIds: replayedRoots
174938
+ });
174939
+ } catch (error) {
174940
+ if (onFailure === void 0) throw error;
174941
+ onFailure([], error);
174942
+ }
174037
174943
  }
174038
- return { roots };
174944
+ for (const [id2, location3] of args.localReferenceLocations ?? []) {
174945
+ if (resolvedLocalIds.has(id2)) continue;
174946
+ if (unavailableRootIds.has(location3.rootId)) continue;
174947
+ const target = storedValueAtPathV4(
174948
+ batch.valuesById,
174949
+ location3.rootId,
174950
+ location3.path
174951
+ );
174952
+ if (target !== null) resolvedLocalIds.set(id2, target);
174953
+ }
174954
+ return { roots, resolvedLocalIds, failures, unavailableRootIds };
174039
174955
  }
174040
174956
  function prospectiveInitializerRecordsV4(args) {
174041
174957
  const records3 = /* @__PURE__ */ new Map();
@@ -174165,10 +175081,10 @@ var cleanRetainedCode, pulledStateDocuments;
174165
175081
  var init_local_initializer_materialization = __esm({
174166
175082
  "src/project-source/local-initializer-materialization.ts"() {
174167
175083
  "use strict";
175084
+ init_stored_value_placements();
174168
175085
  init_local_project_file_storage();
174169
175086
  init_immutable_json3();
174170
175087
  init_lexer();
174171
- init_init_source();
174172
175088
  init_NSGetterRuntimeError();
174173
175089
  init_runtime_diagnostic();
174174
175090
  init_evaluateInitializer();
@@ -176862,6 +177778,7 @@ function lowerProjectSchemaV4(base, analysis, options = {}) {
176862
177778
  );
176863
177779
  for (const extension of analysis.schema.extensions ?? [])
176864
177780
  lowerExtension(context, extension);
177781
+ retainStoredMemberDependencies(context);
176865
177782
  normalizeLookupDeclaredTypes(context);
176866
177783
  for (const [memberId, placements] of context.placements) {
176867
177784
  const member = context.loweredMembers.get(memberId);
@@ -176870,9 +177787,6 @@ function lowerProjectSchemaV4(base, analysis, options = {}) {
176870
177787
  context.loweredMembers.set(memberId, { ...member, owner });
176871
177788
  }
176872
177789
  const protectedRootMembers = lowerProtectedRootMembers(base, analysis);
176873
- const structuralMembers = base.members.filter(
176874
- (member) => (member.owner.kind === "genericArgument" || member.owner.kind === "sharedGenericArgument") && !context.loweredMembers.has(member.id)
176875
- );
176876
177790
  return {
176877
177791
  ...base,
176878
177792
  classes,
@@ -176881,8 +177795,7 @@ function lowerProjectSchemaV4(base, analysis, options = {}) {
176881
177795
  ...context.loweredMembers.values(),
176882
177796
  ...protectedRootMembers.filter(
176883
177797
  (member) => !context.loweredMembers.has(member.id)
176884
- ),
176885
- ...structuralMembers
177798
+ )
176886
177799
  ],
176887
177800
  interfaces,
176888
177801
  enums: analysis.schema.enums.map(
@@ -176893,6 +177806,43 @@ function lowerProjectSchemaV4(base, analysis, options = {}) {
176893
177806
  internalRecordRelations: lowerRelations(context, analysis)
176894
177807
  };
176895
177808
  }
177809
+ function retainStoredMemberDependencies(context) {
177810
+ const retain = (memberId) => {
177811
+ if (context.loweredMembers.has(memberId)) return;
177812
+ const member = context.baseMembers.get(memberId);
177813
+ if (member === void 0)
177814
+ throw new Error(
177815
+ `Stored generic or collection descriptor ${memberId} is missing.`
177816
+ );
177817
+ context.loweredMembers.set(memberId, member);
177818
+ };
177819
+ const retainDependencies = (member) => {
177820
+ switch (member.kind) {
177821
+ case "class":
177822
+ for (const binding of Object.values(member.classArguments))
177823
+ if (binding.kind === "member") retain(binding.memberId);
177824
+ break;
177825
+ case "interface":
177826
+ for (const binding of Object.values(member.interfaceArguments))
177827
+ if (binding.kind === "member") retain(binding.memberId);
177828
+ break;
177829
+ case "list":
177830
+ case "set":
177831
+ case "dictionary":
177832
+ retain(member.entryMemberId);
177833
+ break;
177834
+ case "tuple":
177835
+ for (const element of member.elementMemberIds) retain(element);
177836
+ break;
177837
+ }
177838
+ };
177839
+ for (const member of context.baseMembers.values()) {
177840
+ if (member.owner.kind === "loose" && !context.loweredMembers.has(member.id))
177841
+ retainDependencies(member);
177842
+ }
177843
+ for (const member of context.loweredMembers.values())
177844
+ retainDependencies(member);
177845
+ }
176896
177846
  function lowerProtectedRootMembers(base, analysis) {
176897
177847
  const candidates = PROJECT_ROOT_SOURCE_SLOTS.map(
176898
177848
  (slot) => base.members.filter(
@@ -180397,48 +181347,60 @@ function recordDeleteChange(base, file) {
180397
181347
  casBaseHash: base.conflictServerHash ?? base.contentHash
180398
181348
  };
180399
181349
  }
180400
- function appendCollectionEntryDeletes(workspace, reconstructed3, changes) {
180401
- const releasedOwnerIds = /* @__PURE__ */ new Set();
181350
+ function appendOwnedSchemaMemberDeletes(workspace, reconstructed3, changes, baseManifest) {
181351
+ const owners = /* @__PURE__ */ new Set();
181352
+ const deleted = /* @__PURE__ */ new Set();
180402
181353
  for (const change of changes) {
180403
- if (change.recordKind !== "member") continue;
180404
- if (change.kind === "delete") {
180405
- releasedOwnerIds.add(change.recordId);
180406
- continue;
181354
+ if (change.kind === "create") continue;
181355
+ if (!["class", "interface", "member"].includes(change.recordKind)) continue;
181356
+ owners.add(change.recordId);
181357
+ if (change.kind === "delete") deleted.add(change.recordId);
181358
+ const record7 = workspace.state.records[recordStateKey(change.recordKind, change.recordId)];
181359
+ const data = record7 === void 0 ? void 0 : effectiveRecordData(record7);
181360
+ const parameters = isObjectRecord(data) ? data.genericParams : void 0;
181361
+ if (Array.isArray(parameters)) {
181362
+ for (const parameter4 of parameters) {
181363
+ if (isObjectRecord(parameter4) && typeof parameter4.id === "string")
181364
+ owners.add(parameter4.id);
181365
+ }
180407
181366
  }
180408
- const base = workspace.state.records[recordStateKey("member", change.recordId)];
180409
- if (base === void 0) continue;
180410
- const data = effectiveRecordData(base);
180411
- if (isObjectRecord(data) && typeof data.entryMemberId === "string" && data.entryMemberId !== change.nextData?.entryMemberId)
180412
- releasedOwnerIds.add(change.recordId);
180413
181367
  }
180414
- if (releasedOwnerIds.size === 0) return;
180415
- const members2 = /* @__PURE__ */ new Map();
180416
- function setOwnership(id2, data) {
180417
- if (!isObjectRecord(data)) return;
180418
- const entryMemberId = data.entryMemberId;
180419
- members2.set(id2, {
180420
- id: id2,
180421
- // Reconstructed entries survive, including entries moved to a new owner.
180422
- ...typeof entryMemberId === "string" && !reconstructed3.has(recordStateKey("member", entryMemberId)) ? { entryMemberId } : {}
180423
- });
181368
+ if (owners.size === 0) return;
181369
+ const children3 = /* @__PURE__ */ new Map();
181370
+ const add = (parent, child2) => {
181371
+ const entries = children3.get(parent) ?? [];
181372
+ entries.push(child2);
181373
+ children3.set(parent, entries);
181374
+ };
181375
+ for (const member of baseManifest?.members ?? []) {
181376
+ switch (member.owner.kind) {
181377
+ case "genericArgument":
181378
+ add(member.owner.parentRecordId, member.id);
181379
+ break;
181380
+ case "sharedGenericArgument":
181381
+ for (const binding of member.owner.bindings)
181382
+ add(binding.parentRecordId, member.id);
181383
+ break;
181384
+ case "collectionEntry":
181385
+ add(member.owner.parentMemberId, member.id);
181386
+ break;
181387
+ case "sharedCollectionEntry":
181388
+ for (const parent of member.owner.parentMemberIds)
181389
+ add(parent, member.id);
181390
+ break;
181391
+ }
180424
181392
  }
180425
- for (const record7 of Object.values(workspace.state.records)) {
180426
- if (record7.recordKind === "member" && record7.conflictServerHash !== null)
180427
- setOwnership(record7.recordId, effectiveRecordData(record7));
180428
- }
180429
- for (const record7 of reconstructed3.values()) {
180430
- if (record7.recordKind === "member" && !releasedOwnerIds.has(record7.recordId))
180431
- setOwnership(record7.recordId, record7.fullData);
180432
- }
180433
- const dependentIds = new Set(releasedOwnerIds);
180434
- addDependentMemberIds(dependentIds, members2.values());
180435
- for (const id2 of dependentIds) {
180436
- if (releasedOwnerIds.has(id2)) continue;
180437
- const key = recordStateKey("member", id2);
180438
- if (reconstructed3.has(key)) continue;
180439
- const base = workspace.state.records[key];
180440
- if (base === void 0 || base.conflictServerHash === null) continue;
180441
- changes.push(recordDeleteChange(base, base.file ?? null));
181393
+ for (const ownerId of owners) {
181394
+ for (const memberId of children3.get(ownerId) ?? []) {
181395
+ const key = recordStateKey("member", memberId);
181396
+ if (reconstructed3.has(key)) continue;
181397
+ owners.add(memberId);
181398
+ if (deleted.has(memberId)) continue;
181399
+ const base = workspace.state.records[key];
181400
+ if (base === void 0 || base.conflictServerHash === null) continue;
181401
+ deleted.add(memberId);
181402
+ changes.push(recordDeleteChange(base, base.file ?? null));
181403
+ }
180442
181404
  }
180443
181405
  }
180444
181406
  function listVirtualProjectSourceFilesV4(files) {
@@ -180463,10 +181425,16 @@ function compareWorkspacePaths(left, right) {
180463
181425
  if (left > right) return 1;
180464
181426
  return 0;
180465
181427
  }
180466
- function materializeWorkspaceStatusInitializers(workspace, status, forceRecompile) {
181428
+ function materializeWorkspaceStatusInitializers(workspace, status, forceRecompile, collectErrors = false) {
180467
181429
  return materializeInitializersLocallyV4({
180468
181430
  workspace,
180469
181431
  forceRecompile,
181432
+ collectErrors,
181433
+ localReferenceLocations: new Map(
181434
+ [...status.pendingValueIdentitySites ?? []].flatMap(
181435
+ ([id2, site]) => site.materializedLocation === void 0 ? [] : [[id2, site.materializedLocation]]
181436
+ )
181437
+ ),
180470
181438
  changes: status.changes.map((change) => ({
180471
181439
  recordKind: change.recordKind,
180472
181440
  recordId: change.recordId,
@@ -181472,12 +182440,19 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
181472
182440
  }
181473
182441
  changes.push(recordDeleteChange(recordState, recordFile));
181474
182442
  }
181475
- appendCollectionEntryDeletes(workspace, reconstructed3, changes);
182443
+ appendOwnedSchemaMemberDeletes(
182444
+ workspace,
182445
+ reconstructed3,
182446
+ changes,
182447
+ baseManifest
182448
+ );
182449
+ const deferredReferences = [];
181476
182450
  const referenceFailures = drainValueReferenceObligationsV4(
181477
182451
  prospectiveState,
181478
182452
  manifest,
181479
182453
  {
181480
182454
  registry: valueLowerRegistry,
182455
+ deferredReferences,
181481
182456
  analysis: projectAnalysisV4,
181482
182457
  deletedValueIds,
181483
182458
  unavailableReferenceMemberIds,
@@ -181528,6 +182503,17 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
181528
182503
  reconciliations: valueLowerRegistry.initializerReconciliations
181529
182504
  });
181530
182505
  }
182506
+ const localReferenceTargets = valueLowerRegistry.localValues?.referenceTargets();
182507
+ if (localReferenceTargets !== void 0 && localReferenceTargets.size > 0) {
182508
+ const rewrite = createIdentityRewriter(localReferenceTargets);
182509
+ authoredValueSeeds = settleInitializerKeyCode({
182510
+ settle: rewrite,
182511
+ seeds: authoredValueSeeds,
182512
+ reconstructed: reconstructed3,
182513
+ changes,
182514
+ reconciliations: valueLowerRegistry.initializerReconciliations
182515
+ });
182516
+ }
181531
182517
  try {
181532
182518
  const listeners = lowerListenerBindings({
181533
182519
  statements: projectAnalysisV4?.listenerStatements,
@@ -181891,16 +182877,143 @@ function computeStatus(workspace, options, conflictedFiles, parseErrors, parseWa
181891
182877
  )
181892
182878
  );
181893
182879
  }
181894
- if (options.skipInitializerMaterialization !== true && !parseErrors.some(isBlockingSchemaSourceError)) {
181895
- const diagnostic = workspaceStatusInitializerDiagnostic(
181896
- workspace,
181897
- { changes, authoredValueSeeds },
181898
- valueLowerRegistry.initializerSites,
181899
- sourceTextByUri,
181900
- projectAnalysisV4,
181901
- options.forceRecompile
181902
- );
181903
- if (diagnostic !== null) parseErrors.push(diagnostic);
182880
+ const hasUnresolvedLocalReferences = deferredReferences.length > 0 || [...localReferenceTargets?.values() ?? []].some(
182881
+ (id2) => valueLowerRegistry.pendingValueIdentitySites.get(id2)?.materializedLocation !== void 0
182882
+ );
182883
+ if (hasUnresolvedLocalReferences || options.skipInitializerMaterialization !== true && !parseErrors.some(isBlockingSchemaSourceError)) {
182884
+ if (hasUnresolvedLocalReferences) {
182885
+ try {
182886
+ const materialized = materializeWorkspaceStatusInitializers(
182887
+ workspace,
182888
+ {
182889
+ changes,
182890
+ authoredValueSeeds,
182891
+ pendingValueIdentitySites: valueLowerRegistry.pendingValueIdentitySites
182892
+ },
182893
+ options.forceRecompile,
182894
+ true
182895
+ );
182896
+ for (const error of materialized.failures ?? [])
182897
+ parseErrors.push(
182898
+ initializerRuntimeDiagnostic(
182899
+ error,
182900
+ valueLowerRegistry.initializerSites,
182901
+ sourceTextByUri,
182902
+ projectAnalysisV4
182903
+ )
182904
+ );
182905
+ const unavailableValueIds = new Set(rootValues.unavailableValueIds);
182906
+ for (const id2 of materialized.unavailableRootIds ?? [])
182907
+ unavailableValueIds.add(id2);
182908
+ for (const [id2, site] of valueLowerRegistry.pendingValueIdentitySites) {
182909
+ if (site.materializedLocation !== void 0 && materialized.unavailableRootIds?.has(
182910
+ site.materializedLocation.rootId
182911
+ ))
182912
+ unavailableValueIds.add(id2);
182913
+ }
182914
+ for (const [id2, target] of materialized.resolvedLocalIds ?? []) {
182915
+ const site = valueLowerRegistry.pendingValueIdentitySites.get(id2);
182916
+ if (site !== void 0) {
182917
+ valueLowerRegistry.pendingValueIdentitySites.delete(id2);
182918
+ valueLowerRegistry.pendingValueIdentitySites.set(target, {
182919
+ ...site,
182920
+ id: target
182921
+ });
182922
+ }
182923
+ }
182924
+ valueLowerRegistry.localValues?.remapTargets(
182925
+ materialized.resolvedLocalIds ?? /* @__PURE__ */ new Map()
182926
+ );
182927
+ const rewrite = createIdentityRewriter(
182928
+ materialized.resolvedLocalIds ?? /* @__PURE__ */ new Map()
182929
+ );
182930
+ authoredValueSeeds = settleInitializerKeyCode({
182931
+ settle: rewrite,
182932
+ references: materialized.resolvedLocalIds,
182933
+ seeds: authoredValueSeeds,
182934
+ reconstructed: reconstructed3,
182935
+ changes,
182936
+ reconciliations: valueLowerRegistry.initializerReconciliations
182937
+ });
182938
+ if (deferredReferences.length > 0) {
182939
+ const materializedState = { ...prospectiveState };
182940
+ const pendingValues = new Map(valueLowerRegistry.pendingValues);
182941
+ for (const root of materialized.roots) {
182942
+ for (const row of root.rows) {
182943
+ if (typeof row.id !== "string") continue;
182944
+ pendingValues.delete(row.id);
182945
+ materializedState[`value:${row.id}`] = {
182946
+ recordKind: "value",
182947
+ recordId: row.id,
182948
+ contentHash: "",
182949
+ data: row
182950
+ };
182951
+ }
182952
+ }
182953
+ const validationRegistry = { ...valueLowerRegistry, pendingValues };
182954
+ const failures = drainValueReferenceObligationsV4(
182955
+ materializedState,
182956
+ manifest,
182957
+ {
182958
+ registry: validationRegistry,
182959
+ analysis: projectAnalysisV4,
182960
+ obligations: deferredReferences,
182961
+ deletedValueIds,
182962
+ unavailableReferenceMemberIds,
182963
+ unavailableValueIds,
182964
+ sourceTextByUri,
182965
+ resolveRootPath: createRootValuePathResolverV4({
182966
+ manifest,
182967
+ state: materializedState,
182968
+ resolveVirtualPath,
182969
+ unavailableSlots: rootValues.unavailableSlots,
182970
+ registry: validationRegistry,
182971
+ initBuiltSlots: "refuse"
182972
+ })
182973
+ }
182974
+ );
182975
+ for (const failure of failures) {
182976
+ parseErrors.push(
182977
+ failure instanceof SchemaSourceError ? failure : new SchemaSourceError(
182978
+ failure.message,
182979
+ failure.file,
182980
+ failure.line,
182981
+ failure.column,
182982
+ failure.code
182983
+ )
182984
+ );
182985
+ }
182986
+ if (failures.length > 0)
182987
+ return refusedStatus(
182988
+ conflictedFiles,
182989
+ uniqueSourceErrors(parseErrors),
182990
+ parseWarnings
182991
+ );
182992
+ }
182993
+ } catch (error) {
182994
+ const diagnostic = initializerRuntimeDiagnostic(
182995
+ error,
182996
+ valueLowerRegistry.initializerSites,
182997
+ sourceTextByUri,
182998
+ projectAnalysisV4
182999
+ );
183000
+ parseErrors.push(diagnostic);
183001
+ }
183002
+ } else {
183003
+ const diagnostic = workspaceStatusInitializerDiagnostic(
183004
+ workspace,
183005
+ {
183006
+ changes,
183007
+ authoredValueSeeds,
183008
+ pendingValueIdentitySites: valueLowerRegistry.pendingValueIdentitySites
183009
+ },
183010
+ valueLowerRegistry.initializerSites,
183011
+ sourceTextByUri,
183012
+ projectAnalysisV4,
183013
+ options.forceRecompile
183014
+ );
183015
+ if (diagnostic !== null) parseErrors.push(diagnostic);
183016
+ }
181904
183017
  reportPhase("initializer-materialization");
181905
183018
  }
181906
183019
  const dialogueBodyErrors = workspaceStatusDialogueBodyErrors(
@@ -182344,8 +183457,15 @@ function expandProspectiveAnimationInstances(document) {
182344
183457
  }
182345
183458
  function applyConstructionRebuildsV4(args) {
182346
183459
  if (args.rebuilds.length === 0) return;
183460
+ const covered = /* @__PURE__ */ new Set();
183461
+ for (const rebuild of args.rebuilds)
183462
+ for (const id2 of rebuild.ownedValueIds)
183463
+ if (id2 !== rebuild.valueId) covered.add(id2);
183464
+ const roots = args.rebuilds.filter(
183465
+ (rebuild) => !covered.has(rebuild.valueId)
183466
+ );
182347
183467
  const replanned = /* @__PURE__ */ new Set();
182348
- for (const rebuild of args.rebuilds) {
183468
+ for (const rebuild of roots) {
182349
183469
  for (const id2 of rebuild.ownedValueIds) {
182350
183470
  if (id2 === rebuild.valueId) continue;
182351
183471
  const key = recordStateKey("value", id2);
@@ -182370,7 +183490,7 @@ function applyConstructionRebuildsV4(args) {
182370
183490
  const key = recordStateKey(change.recordKind, change.recordId);
182371
183491
  if (!replanned.has(key)) output.set(key, change);
182372
183492
  }
182373
- for (const rebuild of args.rebuilds) {
183493
+ for (const rebuild of roots) {
182374
183494
  const key = recordStateKey("value", rebuild.valueId);
182375
183495
  const base = args.workspace.state.records[key];
182376
183496
  if (base === void 0) {
@@ -183078,7 +184198,18 @@ function manifestRecordSources(manifest) {
183078
184198
  return result;
183079
184199
  }
183080
184200
  function settleInitializerKeyCode(args) {
184201
+ const settleValue = (value) => {
184202
+ if (args.references === void 0) return value;
184203
+ if (typeof value === "string") return args.references.get(value) ?? value;
184204
+ if (Array.isArray(value)) return value.map(settleValue);
184205
+ if (!isObjectRecord(value)) return value;
184206
+ return Object.fromEntries(
184207
+ Object.entries(value).map(([key, entry]) => [key, settleValue(entry)])
184208
+ );
184209
+ };
183081
184210
  const settleInit = (data) => {
184211
+ if ("value" in data && args.references !== void 0)
184212
+ data = { ...data, value: settleValue(data.value) };
183082
184213
  const init = data.init;
183083
184214
  if (!isObjectRecord(init)) return data;
183084
184215
  if (typeof init.code !== "string") return data;
@@ -183096,10 +184227,17 @@ function settleInitializerKeyCode(args) {
183096
184227
  for (const [valueId, reconciliation] of args.reconciliations) {
183097
184228
  args.reconciliations.set(valueId, {
183098
184229
  ...reconciliation,
183099
- code: args.settle(reconciliation.code)
184230
+ code: args.settle(reconciliation.code),
184231
+ ...reconciliation.kind === "retainedLiteral" ? {} : { constructionCode: args.settle(reconciliation.constructionCode) }
183100
184232
  });
183101
184233
  }
183102
- const settleNode = (node) => node.nodeType === "initializer" ? { ...node, code: args.settle(node.code) } : node;
184234
+ const settleNode = (node) => {
184235
+ if (node.nodeType === "initializer")
184236
+ return { ...node, code: args.settle(node.code) };
184237
+ if (node.nodeType === "literal" && args.references !== void 0)
184238
+ return { ...node, value: settleValue(node.value) };
184239
+ return node;
184240
+ };
183103
184241
  return new Map(
183104
184242
  Array.from(args.seeds, ([memberId, seed]) => [
183105
184243
  memberId,
@@ -183184,6 +184322,7 @@ var sourceSchemaValidation, pulledAnimationValues, animationCompilationProject,
183184
184322
  var init_workspace_status_core = __esm({
183185
184323
  "src/project-source/workspace-status-core.ts"() {
183186
184324
  "use strict";
184325
+ init_identity_rewriter();
183187
184326
  init_initializer_replay();
183188
184327
  init_project_version_whole_graph_validation();
183189
184328
  init_record_fields();
@@ -183256,7 +184395,6 @@ var init_workspace_status_core = __esm({
183256
184395
  init_materialized_construction_cache();
183257
184396
  init_project_version_whole_graph_validation();
183258
184397
  init_value_base_desync();
183259
- init_inheritance();
183260
184398
  sourceSchemaValidation = createSchemaDocumentMemo();
183261
184399
  pulledAnimationValues = /* @__PURE__ */ new WeakMap();
183262
184400
  animationCompilationProject = createNeoScriptProjectMemo();
@@ -221675,7 +222813,7 @@ import {
221675
222813
  statSync as statSync7
221676
222814
  } from "node:fs";
221677
222815
  import { join as join22, relative as relative8, sep as sep9 } from "node:path";
221678
- function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousLedger = {}) {
222816
+ function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousLedger = {}, codePendingIdCandidates = []) {
221679
222817
  const assigned = /* @__PURE__ */ new Map();
221680
222818
  const minted = /* @__PURE__ */ new Map();
221681
222819
  let mint = (pendingId2) => {
@@ -221686,6 +222824,14 @@ function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousL
221686
222824
  const assign = (pendingId2) => {
221687
222825
  const existing = assigned.get(pendingId2);
221688
222826
  if (existing !== void 0) return existing;
222827
+ const genericArgument = pendingGenericArgumentIdentity(pendingId2);
222828
+ if (genericArgument !== null) {
222829
+ const parent = isPendingId(genericArgument.parentRecordId) ? assign(genericArgument.parentRecordId) : genericArgument.parentRecordId;
222830
+ const parameter4 = isPendingId(genericArgument.genericParamId) ? assign(genericArgument.genericParamId) : genericArgument.genericParamId;
222831
+ const derived = derivedGenericArgumentMemberId(parent, parameter4);
222832
+ assigned.set(pendingId2, derived);
222833
+ return derived;
222834
+ }
221689
222835
  const pendingVirtual = pendingVirtualValueIdentity(pendingId2);
221690
222836
  if (pendingVirtual !== null) {
221691
222837
  const instanceRootId = isPendingId(pendingVirtual.instanceRootId) ? assign(pendingVirtual.instanceRootId) : pendingVirtual.instanceRootId;
@@ -221787,6 +222933,24 @@ function assignPendingIds(changes, authoredValueSeeds, reconstructed3, previousL
221787
222933
  collect(record7.fullData);
221788
222934
  }
221789
222935
  }
222936
+ const codeCandidates = new Set(codePendingIdCandidates);
222937
+ if (codeCandidates.size > 0) {
222938
+ const seen = /* @__PURE__ */ new WeakSet();
222939
+ const collectCodeIds = (value) => {
222940
+ if (value === null || typeof value !== "object" || seen.has(value))
222941
+ return;
222942
+ seen.add(value);
222943
+ for (const [key, entry] of Object.entries(value)) {
222944
+ if (key === "code" && typeof entry === "string" && entry.includes(PENDING_ID_PREFIX)) {
222945
+ for (const token of lex(entry).tokens)
222946
+ if (token.value !== void 0 && codeCandidates.has(token.value))
222947
+ collect(token.value);
222948
+ } else collectCodeIds(entry);
222949
+ }
222950
+ };
222951
+ for (const change of changes) collectCodeIds(change.nextData);
222952
+ for (const seed of authoredValueSeeds.values()) collectCodeIds(seed);
222953
+ }
221790
222954
  for (const root of roots) assign(root);
221791
222955
  const keys = identityLedgerKeys(minted.keys());
221792
222956
  const ledger = {};
@@ -222716,7 +223880,10 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
222716
223880
  status.changes,
222717
223881
  status.authoredValueSeeds,
222718
223882
  status.reconstructed,
222719
- { ...options.identityLedger, ...latestLedger }
223883
+ { ...options.identityLedger, ...latestLedger },
223884
+ [...status.pendingValueIdentitySites ?? []].flatMap(
223885
+ ([id2, site]) => site.materializedLocation !== void 0 && pendingVirtualValueIdentity(id2) !== null ? [id2] : []
223886
+ )
222720
223887
  );
222721
223888
  if (!mergeReservedIdentities(workspace.root, pendingAssignment.ledger)) {
222722
223889
  throw new Error(
@@ -222774,6 +223941,18 @@ async function prepareLocalPushArtifactsV4(workspace, status, onPhase = () => vo
222774
223941
  let prepared;
222775
223942
  try {
222776
223943
  const preparationArgs2 = {
223944
+ initializerReferenceOwners: new Map(
223945
+ [...status.pendingValueIdentitySites ?? []].flatMap(
223946
+ ([id2, site]) => site.materializedLocation === void 0 ? [] : [
223947
+ [
223948
+ pendingAssignment.assigned.get(id2) ?? id2,
223949
+ pendingAssignment.assigned.get(
223950
+ site.materializedLocation.rootId
223951
+ ) ?? site.materializedLocation.rootId
223952
+ ]
223953
+ ]
223954
+ )
223955
+ ),
222777
223956
  scriptSources: new Map(
222778
223957
  [...status.scriptSources ?? []].map(([key, sources2]) => {
222779
223958
  const colon = key.indexOf(":");
@@ -224829,6 +226008,7 @@ var init_push = __esm({
224829
226008
  "src/commands/push.ts"() {
224830
226009
  "use strict";
224831
226010
  init_local_project_file_storage();
226011
+ init_generic_argument_member_id();
224832
226012
  init_extension_source_preservation();
224833
226013
  init_workspace_lock();
224834
226014
  init_export_state();
@@ -240314,7 +241494,7 @@ var releaseWorkspaceLock = () => void 0;
240314
241494
  async function main() {
240315
241495
  const args = parseArgs(process.argv.slice(2));
240316
241496
  if (args.command === "--version") {
240317
- console.log("0.89.7");
241497
+ console.log("0.89.9");
240318
241498
  return;
240319
241499
  }
240320
241500
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {