@atscript/core 0.1.70 → 0.1.72

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3299,6 +3299,7 @@ var AtscriptDoc = class {
3299
3299
  this.imports.clear();
3300
3300
  this.resolvedImports.clear();
3301
3301
  this._allMessages = undefined;
3302
+ this._annotateNodesByTarget = undefined;
3302
3303
  this.tokensIndex = new TokensIndex();
3303
3304
  this.blocksIndex = new BlocksIndex();
3304
3305
  this.resolvedAnnotations = [];
@@ -3465,9 +3466,16 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3465
3466
  * Returns a map of property path (dot-joined) → annotations array.
3466
3467
  * For entries without a chain (root-level), the key is the entry identifier.
3467
3468
  */ getAnnotateNodesFor(targetName) {
3468
- const result = [];
3469
- for (const node of this.nodes) if (isAnnotate(node) && node.targetName === targetName) result.push(node);
3470
- return result;
3469
+ if (!this._annotateNodesByTarget) {
3470
+ const index = new Map();
3471
+ for (const node of this.nodes) if (isAnnotate(node)) {
3472
+ const existing = index.get(node.targetName);
3473
+ if (existing) existing.push(node);
3474
+ else index.set(node.targetName, [node]);
3475
+ }
3476
+ this._annotateNodesByTarget = index;
3477
+ }
3478
+ return this._annotateNodesByTarget.get(targetName) ?? [];
3471
3479
  }
3472
3480
  /**
3473
3481
  * Resolves an interface with `extends` by merging parent structures with own props.
@@ -3522,45 +3530,81 @@ else {
3522
3530
  }
3523
3531
  /**
3524
3532
  * Returns a structure equivalent to `struct` with annotate-block contributions
3525
- * folded into matching props' annotation arrays. Skips chained entries
3526
- * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
3527
- * Original prop nodes are reused by reference when no extra annotations apply.
3533
+ * folded into matching props' annotation arrays. Chained entries
3534
+ * (e.g. `annotate Parent { account.active }`) are folded recursively into the
3535
+ * matching inline-object prop's nested structure. Only props/structures along a
3536
+ * touched path are cloned — siblings are reused by reference, so the base's own
3537
+ * (shared) nodes are never mutated.
3528
3538
  */ applyAnnotateBlocksToStructure(struct, annotateNodes) {
3529
3539
  if (!isStructure(struct)) return struct;
3530
- const annotationsByProp = new Map();
3540
+ const entries = [];
3531
3541
  for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
3532
- if (entry.hasChain) continue;
3533
- const propName$1 = entry.id;
3534
3542
  const anns = entry.annotations;
3535
- if (!propName$1 || !anns || anns.length === 0) continue;
3536
- const existing = annotationsByProp.get(propName$1);
3537
- annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
3543
+ if (!entry.id || !anns || anns.length === 0) continue;
3544
+ const parts = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)] : [entry.id];
3545
+ entries.push({
3546
+ parts,
3547
+ anns
3548
+ });
3549
+ }
3550
+ if (entries.length === 0) return struct;
3551
+ return this.foldAnnotationsIntoStructure(struct, entries) ?? struct;
3552
+ }
3553
+ /**
3554
+ * Recursively folds annotate-block entries into a structure's props. Each entry's
3555
+ * `parts[0]` names a prop in `struct`; remaining parts target a nested inline-object
3556
+ * prop. Returns a new structure with cloned props/structures along touched paths, or
3557
+ * `undefined` when nothing matched (so callers can reuse the original by reference).
3558
+ */ foldAnnotationsIntoStructure(struct, entries) {
3559
+ const byHead = new Map();
3560
+ for (const entry of entries) {
3561
+ const head = entry.parts[0];
3562
+ let group$1 = byHead.get(head);
3563
+ if (!group$1) {
3564
+ group$1 = {
3565
+ own: [],
3566
+ nested: []
3567
+ };
3568
+ byHead.set(head, group$1);
3569
+ }
3570
+ if (entry.parts.length === 1) group$1.own.push(...entry.anns);
3571
+ else group$1.nested.push({
3572
+ parts: entry.parts.slice(1),
3573
+ anns: entry.anns
3574
+ });
3538
3575
  }
3539
- if (annotationsByProp.size === 0) return struct;
3540
- const structNode = struct;
3541
3576
  const newProps = [];
3542
3577
  let changed = false;
3543
- for (const [name, prop] of structNode.props) {
3544
- const extras = annotationsByProp.get(name);
3545
- if (!extras) {
3578
+ for (const [name, prop] of struct.props) {
3579
+ const group$1 = byHead.get(name);
3580
+ if (!group$1) {
3581
+ newProps.push(prop);
3582
+ continue;
3583
+ }
3584
+ const propDef = prop.getDefinition();
3585
+ let newDef = propDef;
3586
+ if (group$1.nested.length > 0 && propDef && isStructure(propDef)) {
3587
+ const foldedNested = this.foldAnnotationsIntoStructure(propDef, group$1.nested);
3588
+ if (foldedNested) newDef = foldedNested;
3589
+ }
3590
+ if (group$1.own.length === 0 && newDef === propDef) {
3546
3591
  newProps.push(prop);
3547
3592
  continue;
3548
3593
  }
3549
3594
  const cloned = new SemanticPropNode();
3550
3595
  const idToken = prop.token("identifier");
3551
3596
  if (idToken) cloned.saveToken(idToken, "identifier");
3552
- const propDef = prop.getDefinition();
3553
- if (propDef) cloned.define(propDef);
3554
- cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
3597
+ if (newDef) cloned.define(newDef);
3598
+ cloned.annotations = group$1.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group$1.own) : prop.annotations;
3555
3599
  const optionalToken = prop.token("optional");
3556
3600
  if (optionalToken) cloned.saveToken(optionalToken, "optional");
3557
3601
  newProps.push(cloned);
3558
3602
  changed = true;
3559
3603
  }
3560
- if (!changed) return struct;
3604
+ if (!changed) return undefined;
3561
3605
  const newStruct = new SemanticStructureNode();
3562
3606
  newStruct.setProps(newProps);
3563
- newStruct.annotations = structNode.annotations;
3607
+ newStruct.annotations = struct.annotations;
3564
3608
  return newStruct;
3565
3609
  }
3566
3610
  usageListFor(token) {
@@ -4221,6 +4265,7 @@ else {
4221
4265
  */ _define_property$3(this, "dependenciesMap", void 0);
4222
4266
  _define_property$3(this, "nodes", void 0);
4223
4267
  _define_property$3(this, "_text", void 0);
4268
+ _define_property$3(this, "_annotateNodesByTarget", void 0);
4224
4269
  _define_property$3(this, "resolvedAnnotations", void 0);
4225
4270
  _define_property$3(this, "annotations", void 0);
4226
4271
  _define_property$3(this, "_nextTypeId", void 0);
package/dist/index.d.ts CHANGED
@@ -485,6 +485,7 @@ declare class AtscriptDoc {
485
485
  updateDependencies(docs: AtscriptDoc[]): void;
486
486
  nodes: SemanticNode[];
487
487
  private _text;
488
+ private _annotateNodesByTarget;
488
489
  get text(): string;
489
490
  update(text: string, debug?: boolean): void;
490
491
  cleanup(): void;
@@ -546,11 +547,20 @@ declare class AtscriptDoc {
546
547
  resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string>, _originDoc?: AtscriptDoc): SemanticNode | undefined;
547
548
  /**
548
549
  * Returns a structure equivalent to `struct` with annotate-block contributions
549
- * folded into matching props' annotation arrays. Skips chained entries
550
- * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
551
- * Original prop nodes are reused by reference when no extra annotations apply.
550
+ * folded into matching props' annotation arrays. Chained entries
551
+ * (e.g. `annotate Parent { account.active }`) are folded recursively into the
552
+ * matching inline-object prop's nested structure. Only props/structures along a
553
+ * touched path are cloned — siblings are reused by reference, so the base's own
554
+ * (shared) nodes are never mutated.
552
555
  */
553
556
  private applyAnnotateBlocksToStructure;
557
+ /**
558
+ * Recursively folds annotate-block entries into a structure's props. Each entry's
559
+ * `parts[0]` names a prop in `struct`; remaining parts target a nested inline-object
560
+ * prop. Returns a new structure with cloned props/structures along touched paths, or
561
+ * `undefined` when nothing matched (so callers can reuse the original by reference).
562
+ */
563
+ private foldAnnotationsIntoStructure;
554
564
  usageListFor(token: Token): Array<{
555
565
  uri: string;
556
566
  range: Token['range'];
package/dist/index.mjs CHANGED
@@ -3275,6 +3275,7 @@ var AtscriptDoc = class {
3275
3275
  this.imports.clear();
3276
3276
  this.resolvedImports.clear();
3277
3277
  this._allMessages = undefined;
3278
+ this._annotateNodesByTarget = undefined;
3278
3279
  this.tokensIndex = new TokensIndex();
3279
3280
  this.blocksIndex = new BlocksIndex();
3280
3281
  this.resolvedAnnotations = [];
@@ -3441,9 +3442,16 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3441
3442
  * Returns a map of property path (dot-joined) → annotations array.
3442
3443
  * For entries without a chain (root-level), the key is the entry identifier.
3443
3444
  */ getAnnotateNodesFor(targetName) {
3444
- const result = [];
3445
- for (const node of this.nodes) if (isAnnotate(node) && node.targetName === targetName) result.push(node);
3446
- return result;
3445
+ if (!this._annotateNodesByTarget) {
3446
+ const index = new Map();
3447
+ for (const node of this.nodes) if (isAnnotate(node)) {
3448
+ const existing = index.get(node.targetName);
3449
+ if (existing) existing.push(node);
3450
+ else index.set(node.targetName, [node]);
3451
+ }
3452
+ this._annotateNodesByTarget = index;
3453
+ }
3454
+ return this._annotateNodesByTarget.get(targetName) ?? [];
3447
3455
  }
3448
3456
  /**
3449
3457
  * Resolves an interface with `extends` by merging parent structures with own props.
@@ -3498,45 +3506,81 @@ else {
3498
3506
  }
3499
3507
  /**
3500
3508
  * Returns a structure equivalent to `struct` with annotate-block contributions
3501
- * folded into matching props' annotation arrays. Skips chained entries
3502
- * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
3503
- * Original prop nodes are reused by reference when no extra annotations apply.
3509
+ * folded into matching props' annotation arrays. Chained entries
3510
+ * (e.g. `annotate Parent { account.active }`) are folded recursively into the
3511
+ * matching inline-object prop's nested structure. Only props/structures along a
3512
+ * touched path are cloned — siblings are reused by reference, so the base's own
3513
+ * (shared) nodes are never mutated.
3504
3514
  */ applyAnnotateBlocksToStructure(struct, annotateNodes) {
3505
3515
  if (!isStructure(struct)) return struct;
3506
- const annotationsByProp = new Map();
3516
+ const entries = [];
3507
3517
  for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
3508
- if (entry.hasChain) continue;
3509
- const propName$1 = entry.id;
3510
3518
  const anns = entry.annotations;
3511
- if (!propName$1 || !anns || anns.length === 0) continue;
3512
- const existing = annotationsByProp.get(propName$1);
3513
- annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
3519
+ if (!entry.id || !anns || anns.length === 0) continue;
3520
+ const parts = entry.hasChain ? [entry.id, ...entry.chain.map((c) => c.text)] : [entry.id];
3521
+ entries.push({
3522
+ parts,
3523
+ anns
3524
+ });
3525
+ }
3526
+ if (entries.length === 0) return struct;
3527
+ return this.foldAnnotationsIntoStructure(struct, entries) ?? struct;
3528
+ }
3529
+ /**
3530
+ * Recursively folds annotate-block entries into a structure's props. Each entry's
3531
+ * `parts[0]` names a prop in `struct`; remaining parts target a nested inline-object
3532
+ * prop. Returns a new structure with cloned props/structures along touched paths, or
3533
+ * `undefined` when nothing matched (so callers can reuse the original by reference).
3534
+ */ foldAnnotationsIntoStructure(struct, entries) {
3535
+ const byHead = new Map();
3536
+ for (const entry of entries) {
3537
+ const head = entry.parts[0];
3538
+ let group$1 = byHead.get(head);
3539
+ if (!group$1) {
3540
+ group$1 = {
3541
+ own: [],
3542
+ nested: []
3543
+ };
3544
+ byHead.set(head, group$1);
3545
+ }
3546
+ if (entry.parts.length === 1) group$1.own.push(...entry.anns);
3547
+ else group$1.nested.push({
3548
+ parts: entry.parts.slice(1),
3549
+ anns: entry.anns
3550
+ });
3514
3551
  }
3515
- if (annotationsByProp.size === 0) return struct;
3516
- const structNode = struct;
3517
3552
  const newProps = [];
3518
3553
  let changed = false;
3519
- for (const [name, prop] of structNode.props) {
3520
- const extras = annotationsByProp.get(name);
3521
- if (!extras) {
3554
+ for (const [name, prop] of struct.props) {
3555
+ const group$1 = byHead.get(name);
3556
+ if (!group$1) {
3557
+ newProps.push(prop);
3558
+ continue;
3559
+ }
3560
+ const propDef = prop.getDefinition();
3561
+ let newDef = propDef;
3562
+ if (group$1.nested.length > 0 && propDef && isStructure(propDef)) {
3563
+ const foldedNested = this.foldAnnotationsIntoStructure(propDef, group$1.nested);
3564
+ if (foldedNested) newDef = foldedNested;
3565
+ }
3566
+ if (group$1.own.length === 0 && newDef === propDef) {
3522
3567
  newProps.push(prop);
3523
3568
  continue;
3524
3569
  }
3525
3570
  const cloned = new SemanticPropNode();
3526
3571
  const idToken = prop.token("identifier");
3527
3572
  if (idToken) cloned.saveToken(idToken, "identifier");
3528
- const propDef = prop.getDefinition();
3529
- if (propDef) cloned.define(propDef);
3530
- cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
3573
+ if (newDef) cloned.define(newDef);
3574
+ cloned.annotations = group$1.own.length > 0 ? this.mergeNodesAnnotations(prop.annotations, group$1.own) : prop.annotations;
3531
3575
  const optionalToken = prop.token("optional");
3532
3576
  if (optionalToken) cloned.saveToken(optionalToken, "optional");
3533
3577
  newProps.push(cloned);
3534
3578
  changed = true;
3535
3579
  }
3536
- if (!changed) return struct;
3580
+ if (!changed) return undefined;
3537
3581
  const newStruct = new SemanticStructureNode();
3538
3582
  newStruct.setProps(newProps);
3539
- newStruct.annotations = structNode.annotations;
3583
+ newStruct.annotations = struct.annotations;
3540
3584
  return newStruct;
3541
3585
  }
3542
3586
  usageListFor(token) {
@@ -4197,6 +4241,7 @@ else {
4197
4241
  */ _define_property$3(this, "dependenciesMap", void 0);
4198
4242
  _define_property$3(this, "nodes", void 0);
4199
4243
  _define_property$3(this, "_text", void 0);
4244
+ _define_property$3(this, "_annotateNodesByTarget", void 0);
4200
4245
  _define_property$3(this, "resolvedAnnotations", void 0);
4201
4246
  _define_property$3(this, "annotations", void 0);
4202
4247
  _define_property$3(this, "_nextTypeId", void 0);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.70",
3
+ "version": "0.1.72",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",