@atscript/core 0.1.63 → 0.1.64
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 +38 -12
- package/dist/index.d.ts +15 -6
- package/dist/index.mjs +38 -12
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3473,16 +3473,19 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
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
3475
|
*
|
|
3476
|
-
* Mutating `annotate <
|
|
3477
|
-
* inherited fields carry annotate-block metadata in the child's flat prop view.
|
|
3478
|
-
*
|
|
3479
|
-
*
|
|
3480
|
-
*
|
|
3481
|
-
|
|
3476
|
+
* Mutating `annotate <Ancestor> { @x field }` blocks contribute to the merged view, so
|
|
3477
|
+
* inherited fields carry annotate-block metadata in the child's flat prop view. At each
|
|
3478
|
+
* level of the chain we consult: (1) the immediate parent's own document and (2) the
|
|
3479
|
+
* `_originDoc` — the document that started the resolution (typically the leaf child).
|
|
3480
|
+
* Threading `_originDoc` is what lets `annotate <Grandparent> { ... }` blocks living in
|
|
3481
|
+
* the child's file apply to grandparent-inherited fields, even when the chain crosses
|
|
3482
|
+
* package boundaries (child → mid → grandparent, all in different .as files).
|
|
3483
|
+
*/ resolveInterfaceExtends(node, _visited, _originDoc) {
|
|
3482
3484
|
if (!node.hasExtends) return undefined;
|
|
3483
3485
|
const visited = _visited || new Set();
|
|
3484
3486
|
if (node.id && visited.has(node.id)) return undefined;
|
|
3485
3487
|
if (node.id) visited.add(node.id);
|
|
3488
|
+
const originDoc = _originDoc ?? this;
|
|
3486
3489
|
let mergedStruct;
|
|
3487
3490
|
for (const extendsToken of node.extendsTokens) {
|
|
3488
3491
|
const unwound = this.unwindType(extendsToken.text);
|
|
@@ -3490,16 +3493,27 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
3490
3493
|
let parentDef = unwound.def;
|
|
3491
3494
|
const parentDeclName = unwound.node?.id ?? parentDef.id;
|
|
3492
3495
|
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
3493
|
-
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
3496
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
|
|
3494
3497
|
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
3495
3498
|
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
3496
3499
|
parentDef = this.mergeIntersection(parentDef);
|
|
3497
3500
|
const annotateNodes = [];
|
|
3498
|
-
|
|
3499
|
-
|
|
3500
|
-
|
|
3501
|
-
|
|
3502
|
-
|
|
3501
|
+
const seenAnnotates = new Set();
|
|
3502
|
+
const collect = (doc, name) => {
|
|
3503
|
+
if (!name) return;
|
|
3504
|
+
for (const n of doc.getAnnotateNodesFor(name)) if (n.isMutating && !seenAnnotates.has(n)) {
|
|
3505
|
+
seenAnnotates.add(n);
|
|
3506
|
+
annotateNodes.push(n);
|
|
3507
|
+
}
|
|
3508
|
+
};
|
|
3509
|
+
collect(unwound.doc, parentDeclName);
|
|
3510
|
+
if (this !== unwound.doc) collect(this, extendsToken.text);
|
|
3511
|
+
if (originDoc !== this && originDoc !== unwound.doc) {
|
|
3512
|
+
collect(originDoc, parentDeclName);
|
|
3513
|
+
if (parentDeclName) {
|
|
3514
|
+
const originAlias = originDoc.getLocalAliasForExternal(parentDeclName, unwound.doc);
|
|
3515
|
+
if (originAlias && originAlias !== parentDeclName) collect(originDoc, originAlias);
|
|
3516
|
+
}
|
|
3503
3517
|
}
|
|
3504
3518
|
if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
|
|
3505
3519
|
if (!mergedStruct) mergedStruct = parentDef;
|
|
@@ -3516,6 +3530,18 @@ else {
|
|
|
3516
3530
|
return mergedStruct || ownDef;
|
|
3517
3531
|
}
|
|
3518
3532
|
/**
|
|
3533
|
+
* Returns the local identifier under which `externalName` (declared in `externalDoc`)
|
|
3534
|
+
* is imported into this document. Walks the import statements and matches by the
|
|
3535
|
+
* declaration owner of each imported token. Returns `undefined` when this document
|
|
3536
|
+
* doesn't import the symbol, or when the import name matches the declaration name.
|
|
3537
|
+
*/ getLocalAliasForExternal(externalName, externalDoc) {
|
|
3538
|
+
for (const [, entry] of this.imports) for (const t of entry.imports) {
|
|
3539
|
+
const decl = this.getDeclarationOwnerNode(t.text);
|
|
3540
|
+
if (decl?.doc === externalDoc && decl.token?.text === externalName) return t.text;
|
|
3541
|
+
}
|
|
3542
|
+
return undefined;
|
|
3543
|
+
}
|
|
3544
|
+
/**
|
|
3519
3545
|
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
3520
3546
|
* folded into matching props' annotation arrays. Skips chained entries
|
|
3521
3547
|
* (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
|
package/dist/index.d.ts
CHANGED
|
@@ -535,13 +535,22 @@ declare class AtscriptDoc {
|
|
|
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
537
|
*
|
|
538
|
-
* Mutating `annotate <
|
|
539
|
-
* inherited fields carry annotate-block metadata in the child's flat prop view.
|
|
540
|
-
*
|
|
541
|
-
*
|
|
542
|
-
*
|
|
538
|
+
* Mutating `annotate <Ancestor> { @x field }` blocks contribute to the merged view, so
|
|
539
|
+
* inherited fields carry annotate-block metadata in the child's flat prop view. At each
|
|
540
|
+
* level of the chain we consult: (1) the immediate parent's own document and (2) the
|
|
541
|
+
* `_originDoc` — the document that started the resolution (typically the leaf child).
|
|
542
|
+
* Threading `_originDoc` is what lets `annotate <Grandparent> { ... }` blocks living in
|
|
543
|
+
* the child's file apply to grandparent-inherited fields, even when the chain crosses
|
|
544
|
+
* package boundaries (child → mid → grandparent, all in different .as files).
|
|
543
545
|
*/
|
|
544
|
-
resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string
|
|
546
|
+
resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string>, _originDoc?: AtscriptDoc): SemanticNode | undefined;
|
|
547
|
+
/**
|
|
548
|
+
* Returns the local identifier under which `externalName` (declared in `externalDoc`)
|
|
549
|
+
* is imported into this document. Walks the import statements and matches by the
|
|
550
|
+
* declaration owner of each imported token. Returns `undefined` when this document
|
|
551
|
+
* doesn't import the symbol, or when the import name matches the declaration name.
|
|
552
|
+
*/
|
|
553
|
+
private getLocalAliasForExternal;
|
|
545
554
|
/**
|
|
546
555
|
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
547
556
|
* folded into matching props' annotation arrays. Skips chained entries
|
package/dist/index.mjs
CHANGED
|
@@ -3449,16 +3449,19 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
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
3451
|
*
|
|
3452
|
-
* Mutating `annotate <
|
|
3453
|
-
* inherited fields carry annotate-block metadata in the child's flat prop view.
|
|
3454
|
-
*
|
|
3455
|
-
*
|
|
3456
|
-
*
|
|
3457
|
-
|
|
3452
|
+
* Mutating `annotate <Ancestor> { @x field }` blocks contribute to the merged view, so
|
|
3453
|
+
* inherited fields carry annotate-block metadata in the child's flat prop view. At each
|
|
3454
|
+
* level of the chain we consult: (1) the immediate parent's own document and (2) the
|
|
3455
|
+
* `_originDoc` — the document that started the resolution (typically the leaf child).
|
|
3456
|
+
* Threading `_originDoc` is what lets `annotate <Grandparent> { ... }` blocks living in
|
|
3457
|
+
* the child's file apply to grandparent-inherited fields, even when the chain crosses
|
|
3458
|
+
* package boundaries (child → mid → grandparent, all in different .as files).
|
|
3459
|
+
*/ resolveInterfaceExtends(node, _visited, _originDoc) {
|
|
3458
3460
|
if (!node.hasExtends) return undefined;
|
|
3459
3461
|
const visited = _visited || new Set();
|
|
3460
3462
|
if (node.id && visited.has(node.id)) return undefined;
|
|
3461
3463
|
if (node.id) visited.add(node.id);
|
|
3464
|
+
const originDoc = _originDoc ?? this;
|
|
3462
3465
|
let mergedStruct;
|
|
3463
3466
|
for (const extendsToken of node.extendsTokens) {
|
|
3464
3467
|
const unwound = this.unwindType(extendsToken.text);
|
|
@@ -3466,16 +3469,27 @@ else if (isStructure(def) || isInterface(def) || isPrimitive(def)) def = def.pro
|
|
|
3466
3469
|
let parentDef = unwound.def;
|
|
3467
3470
|
const parentDeclName = unwound.node?.id ?? parentDef.id;
|
|
3468
3471
|
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
3469
|
-
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
3472
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
|
|
3470
3473
|
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
3471
3474
|
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
3472
3475
|
parentDef = this.mergeIntersection(parentDef);
|
|
3473
3476
|
const annotateNodes = [];
|
|
3474
|
-
|
|
3475
|
-
|
|
3476
|
-
|
|
3477
|
-
|
|
3478
|
-
|
|
3477
|
+
const seenAnnotates = new Set();
|
|
3478
|
+
const collect = (doc, name) => {
|
|
3479
|
+
if (!name) return;
|
|
3480
|
+
for (const n of doc.getAnnotateNodesFor(name)) if (n.isMutating && !seenAnnotates.has(n)) {
|
|
3481
|
+
seenAnnotates.add(n);
|
|
3482
|
+
annotateNodes.push(n);
|
|
3483
|
+
}
|
|
3484
|
+
};
|
|
3485
|
+
collect(unwound.doc, parentDeclName);
|
|
3486
|
+
if (this !== unwound.doc) collect(this, extendsToken.text);
|
|
3487
|
+
if (originDoc !== this && originDoc !== unwound.doc) {
|
|
3488
|
+
collect(originDoc, parentDeclName);
|
|
3489
|
+
if (parentDeclName) {
|
|
3490
|
+
const originAlias = originDoc.getLocalAliasForExternal(parentDeclName, unwound.doc);
|
|
3491
|
+
if (originAlias && originAlias !== parentDeclName) collect(originDoc, originAlias);
|
|
3492
|
+
}
|
|
3479
3493
|
}
|
|
3480
3494
|
if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
|
|
3481
3495
|
if (!mergedStruct) mergedStruct = parentDef;
|
|
@@ -3492,6 +3506,18 @@ else {
|
|
|
3492
3506
|
return mergedStruct || ownDef;
|
|
3493
3507
|
}
|
|
3494
3508
|
/**
|
|
3509
|
+
* Returns the local identifier under which `externalName` (declared in `externalDoc`)
|
|
3510
|
+
* is imported into this document. Walks the import statements and matches by the
|
|
3511
|
+
* declaration owner of each imported token. Returns `undefined` when this document
|
|
3512
|
+
* doesn't import the symbol, or when the import name matches the declaration name.
|
|
3513
|
+
*/ getLocalAliasForExternal(externalName, externalDoc) {
|
|
3514
|
+
for (const [, entry] of this.imports) for (const t of entry.imports) {
|
|
3515
|
+
const decl = this.getDeclarationOwnerNode(t.text);
|
|
3516
|
+
if (decl?.doc === externalDoc && decl.token?.text === externalName) return t.text;
|
|
3517
|
+
}
|
|
3518
|
+
return undefined;
|
|
3519
|
+
}
|
|
3520
|
+
/**
|
|
3495
3521
|
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
3496
3522
|
* folded into matching props' annotation arrays. Skips chained entries
|
|
3497
3523
|
* (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
|