@atscript/core 0.1.61 → 0.1.63

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
@@ -3472,6 +3472,12 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3472
3472
  * Resolves an interface with `extends` by merging parent structures with own props.
3473
3473
  * Parents are merged left-to-right, then own props overlay on top (own takes priority).
3474
3474
  * Only merges props and their annotations; interface-level annotations are NOT inherited.
3475
+ *
3476
+ * Mutating `annotate <Parent> { @x field }` blocks contribute to the merged view, so
3477
+ * inherited fields carry annotate-block metadata in the child's flat prop view. Two
3478
+ * sources are consulted per parent: the parent's own document (using the parent's
3479
+ * declaration name) and the child's document (using the local extends token, which may
3480
+ * differ from the canonical name due to import aliasing).
3475
3481
  */ resolveInterfaceExtends(node, _visited) {
3476
3482
  if (!node.hasExtends) return undefined;
3477
3483
  const visited = _visited || new Set();
@@ -3482,11 +3488,20 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3482
3488
  const unwound = this.unwindType(extendsToken.text);
3483
3489
  if (!unwound?.def) continue;
3484
3490
  let parentDef = unwound.def;
3491
+ const parentDeclName = unwound.node?.id ?? parentDef.id;
3485
3492
  if (isInterface(parentDef) && parentDef.hasExtends) {
3486
3493
  const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
3487
3494
  parentDef = resolved || parentDef.getDefinition() || parentDef;
3488
3495
  } else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3489
3496
  parentDef = this.mergeIntersection(parentDef);
3497
+ const annotateNodes = [];
3498
+ if (parentDeclName) {
3499
+ for (const n of unwound.doc.getAnnotateNodesFor(parentDeclName)) if (n.isMutating) annotateNodes.push(n);
3500
+ }
3501
+ if (this !== unwound.doc) {
3502
+ for (const n of this.getAnnotateNodesFor(extendsToken.text)) if (n.isMutating) annotateNodes.push(n);
3503
+ }
3504
+ if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
3490
3505
  if (!mergedStruct) mergedStruct = parentDef;
3491
3506
  else {
3492
3507
  const merged = this.mergeDefs(mergedStruct, parentDef);
@@ -3500,6 +3515,49 @@ else {
3500
3515
  }
3501
3516
  return mergedStruct || ownDef;
3502
3517
  }
3518
+ /**
3519
+ * Returns a structure equivalent to `struct` with annotate-block contributions
3520
+ * folded into matching props' annotation arrays. Skips chained entries
3521
+ * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
3522
+ * Original prop nodes are reused by reference when no extra annotations apply.
3523
+ */ applyAnnotateBlocksToStructure(struct, annotateNodes) {
3524
+ if (!isStructure(struct)) return struct;
3525
+ const annotationsByProp = new Map();
3526
+ for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
3527
+ if (entry.hasChain) continue;
3528
+ const propName$1 = entry.id;
3529
+ const anns = entry.annotations;
3530
+ if (!propName$1 || !anns || anns.length === 0) continue;
3531
+ const existing = annotationsByProp.get(propName$1);
3532
+ annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
3533
+ }
3534
+ if (annotationsByProp.size === 0) return struct;
3535
+ const structNode = struct;
3536
+ const newProps = [];
3537
+ let changed = false;
3538
+ for (const [name, prop] of structNode.props) {
3539
+ const extras = annotationsByProp.get(name);
3540
+ if (!extras) {
3541
+ newProps.push(prop);
3542
+ continue;
3543
+ }
3544
+ const cloned = new SemanticPropNode();
3545
+ const idToken = prop.token("identifier");
3546
+ if (idToken) cloned.saveToken(idToken, "identifier");
3547
+ const propDef = prop.getDefinition();
3548
+ if (propDef) cloned.define(propDef);
3549
+ cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
3550
+ const optionalToken = prop.token("optional");
3551
+ if (optionalToken) cloned.saveToken(optionalToken, "optional");
3552
+ newProps.push(cloned);
3553
+ changed = true;
3554
+ }
3555
+ if (!changed) return struct;
3556
+ const newStruct = new SemanticStructureNode();
3557
+ newStruct.setProps(newProps);
3558
+ newStruct.annotations = structNode.annotations;
3559
+ return newStruct;
3560
+ }
3503
3561
  usageListFor(token) {
3504
3562
  if (token.isDefinition) {
3505
3563
  const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
package/dist/index.d.ts CHANGED
@@ -534,8 +534,21 @@ declare class AtscriptDoc {
534
534
  * Resolves an interface with `extends` by merging parent structures with own props.
535
535
  * Parents are merged left-to-right, then own props overlay on top (own takes priority).
536
536
  * Only merges props and their annotations; interface-level annotations are NOT inherited.
537
+ *
538
+ * Mutating `annotate <Parent> { @x field }` blocks contribute to the merged view, so
539
+ * inherited fields carry annotate-block metadata in the child's flat prop view. Two
540
+ * sources are consulted per parent: the parent's own document (using the parent's
541
+ * declaration name) and the child's document (using the local extends token, which may
542
+ * differ from the canonical name due to import aliasing).
537
543
  */
538
544
  resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string>): SemanticNode | undefined;
545
+ /**
546
+ * Returns a structure equivalent to `struct` with annotate-block contributions
547
+ * folded into matching props' annotation arrays. Skips chained entries
548
+ * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
549
+ * Original prop nodes are reused by reference when no extra annotations apply.
550
+ */
551
+ private applyAnnotateBlocksToStructure;
539
552
  usageListFor(token: Token): Array<{
540
553
  uri: string;
541
554
  range: Token['range'];
package/dist/index.mjs CHANGED
@@ -3448,6 +3448,12 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3448
3448
  * Resolves an interface with `extends` by merging parent structures with own props.
3449
3449
  * Parents are merged left-to-right, then own props overlay on top (own takes priority).
3450
3450
  * Only merges props and their annotations; interface-level annotations are NOT inherited.
3451
+ *
3452
+ * Mutating `annotate <Parent> { @x field }` blocks contribute to the merged view, so
3453
+ * inherited fields carry annotate-block metadata in the child's flat prop view. Two
3454
+ * sources are consulted per parent: the parent's own document (using the parent's
3455
+ * declaration name) and the child's document (using the local extends token, which may
3456
+ * differ from the canonical name due to import aliasing).
3451
3457
  */ resolveInterfaceExtends(node, _visited) {
3452
3458
  if (!node.hasExtends) return undefined;
3453
3459
  const visited = _visited || new Set();
@@ -3458,11 +3464,20 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
3458
3464
  const unwound = this.unwindType(extendsToken.text);
3459
3465
  if (!unwound?.def) continue;
3460
3466
  let parentDef = unwound.def;
3467
+ const parentDeclName = unwound.node?.id ?? parentDef.id;
3461
3468
  if (isInterface(parentDef) && parentDef.hasExtends) {
3462
3469
  const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
3463
3470
  parentDef = resolved || parentDef.getDefinition() || parentDef;
3464
3471
  } else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
3465
3472
  parentDef = this.mergeIntersection(parentDef);
3473
+ const annotateNodes = [];
3474
+ if (parentDeclName) {
3475
+ for (const n of unwound.doc.getAnnotateNodesFor(parentDeclName)) if (n.isMutating) annotateNodes.push(n);
3476
+ }
3477
+ if (this !== unwound.doc) {
3478
+ for (const n of this.getAnnotateNodesFor(extendsToken.text)) if (n.isMutating) annotateNodes.push(n);
3479
+ }
3480
+ if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
3466
3481
  if (!mergedStruct) mergedStruct = parentDef;
3467
3482
  else {
3468
3483
  const merged = this.mergeDefs(mergedStruct, parentDef);
@@ -3476,6 +3491,49 @@ else {
3476
3491
  }
3477
3492
  return mergedStruct || ownDef;
3478
3493
  }
3494
+ /**
3495
+ * Returns a structure equivalent to `struct` with annotate-block contributions
3496
+ * folded into matching props' annotation arrays. Skips chained entries
3497
+ * (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
3498
+ * Original prop nodes are reused by reference when no extra annotations apply.
3499
+ */ applyAnnotateBlocksToStructure(struct, annotateNodes) {
3500
+ if (!isStructure(struct)) return struct;
3501
+ const annotationsByProp = new Map();
3502
+ for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
3503
+ if (entry.hasChain) continue;
3504
+ const propName$1 = entry.id;
3505
+ const anns = entry.annotations;
3506
+ if (!propName$1 || !anns || anns.length === 0) continue;
3507
+ const existing = annotationsByProp.get(propName$1);
3508
+ annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
3509
+ }
3510
+ if (annotationsByProp.size === 0) return struct;
3511
+ const structNode = struct;
3512
+ const newProps = [];
3513
+ let changed = false;
3514
+ for (const [name, prop] of structNode.props) {
3515
+ const extras = annotationsByProp.get(name);
3516
+ if (!extras) {
3517
+ newProps.push(prop);
3518
+ continue;
3519
+ }
3520
+ const cloned = new SemanticPropNode();
3521
+ const idToken = prop.token("identifier");
3522
+ if (idToken) cloned.saveToken(idToken, "identifier");
3523
+ const propDef = prop.getDefinition();
3524
+ if (propDef) cloned.define(propDef);
3525
+ cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
3526
+ const optionalToken = prop.token("optional");
3527
+ if (optionalToken) cloned.saveToken(optionalToken, "optional");
3528
+ newProps.push(cloned);
3529
+ changed = true;
3530
+ }
3531
+ if (!changed) return struct;
3532
+ const newStruct = new SemanticStructureNode();
3533
+ newStruct.setProps(newProps);
3534
+ newStruct.annotations = structNode.annotations;
3535
+ return newStruct;
3536
+ }
3479
3537
  usageListFor(token) {
3480
3538
  if (token.isDefinition) {
3481
3539
  const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/core",
3
- "version": "0.1.61",
3
+ "version": "0.1.63",
4
4
  "description": "Core library for Atscript parsing and file generation.",
5
5
  "keywords": [
6
6
  "annotations",