@atscript/core 0.1.62 → 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 +86 -2
- package/dist/index.d.ts +23 -1
- package/dist/index.mjs +86 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -3472,21 +3472,50 @@ 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
|
-
|
|
3475
|
+
*
|
|
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) {
|
|
3476
3484
|
if (!node.hasExtends) return undefined;
|
|
3477
3485
|
const visited = _visited || new Set();
|
|
3478
3486
|
if (node.id && visited.has(node.id)) return undefined;
|
|
3479
3487
|
if (node.id) visited.add(node.id);
|
|
3488
|
+
const originDoc = _originDoc ?? this;
|
|
3480
3489
|
let mergedStruct;
|
|
3481
3490
|
for (const extendsToken of node.extendsTokens) {
|
|
3482
3491
|
const unwound = this.unwindType(extendsToken.text);
|
|
3483
3492
|
if (!unwound?.def) continue;
|
|
3484
3493
|
let parentDef = unwound.def;
|
|
3494
|
+
const parentDeclName = unwound.node?.id ?? parentDef.id;
|
|
3485
3495
|
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
3486
|
-
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
3496
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
|
|
3487
3497
|
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
3488
3498
|
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
3489
3499
|
parentDef = this.mergeIntersection(parentDef);
|
|
3500
|
+
const annotateNodes = [];
|
|
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
|
+
}
|
|
3517
|
+
}
|
|
3518
|
+
if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
|
|
3490
3519
|
if (!mergedStruct) mergedStruct = parentDef;
|
|
3491
3520
|
else {
|
|
3492
3521
|
const merged = this.mergeDefs(mergedStruct, parentDef);
|
|
@@ -3500,6 +3529,61 @@ else {
|
|
|
3500
3529
|
}
|
|
3501
3530
|
return mergedStruct || ownDef;
|
|
3502
3531
|
}
|
|
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
|
+
/**
|
|
3545
|
+
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
3546
|
+
* folded into matching props' annotation arrays. Skips chained entries
|
|
3547
|
+
* (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
|
|
3548
|
+
* Original prop nodes are reused by reference when no extra annotations apply.
|
|
3549
|
+
*/ applyAnnotateBlocksToStructure(struct, annotateNodes) {
|
|
3550
|
+
if (!isStructure(struct)) return struct;
|
|
3551
|
+
const annotationsByProp = new Map();
|
|
3552
|
+
for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
|
|
3553
|
+
if (entry.hasChain) continue;
|
|
3554
|
+
const propName$1 = entry.id;
|
|
3555
|
+
const anns = entry.annotations;
|
|
3556
|
+
if (!propName$1 || !anns || anns.length === 0) continue;
|
|
3557
|
+
const existing = annotationsByProp.get(propName$1);
|
|
3558
|
+
annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
|
|
3559
|
+
}
|
|
3560
|
+
if (annotationsByProp.size === 0) return struct;
|
|
3561
|
+
const structNode = struct;
|
|
3562
|
+
const newProps = [];
|
|
3563
|
+
let changed = false;
|
|
3564
|
+
for (const [name, prop] of structNode.props) {
|
|
3565
|
+
const extras = annotationsByProp.get(name);
|
|
3566
|
+
if (!extras) {
|
|
3567
|
+
newProps.push(prop);
|
|
3568
|
+
continue;
|
|
3569
|
+
}
|
|
3570
|
+
const cloned = new SemanticPropNode();
|
|
3571
|
+
const idToken = prop.token("identifier");
|
|
3572
|
+
if (idToken) cloned.saveToken(idToken, "identifier");
|
|
3573
|
+
const propDef = prop.getDefinition();
|
|
3574
|
+
if (propDef) cloned.define(propDef);
|
|
3575
|
+
cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
|
|
3576
|
+
const optionalToken = prop.token("optional");
|
|
3577
|
+
if (optionalToken) cloned.saveToken(optionalToken, "optional");
|
|
3578
|
+
newProps.push(cloned);
|
|
3579
|
+
changed = true;
|
|
3580
|
+
}
|
|
3581
|
+
if (!changed) return struct;
|
|
3582
|
+
const newStruct = new SemanticStructureNode();
|
|
3583
|
+
newStruct.setProps(newProps);
|
|
3584
|
+
newStruct.annotations = structNode.annotations;
|
|
3585
|
+
return newStruct;
|
|
3586
|
+
}
|
|
3503
3587
|
usageListFor(token) {
|
|
3504
3588
|
if (token.isDefinition) {
|
|
3505
3589
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|
package/dist/index.d.ts
CHANGED
|
@@ -534,8 +534,30 @@ 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 <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).
|
|
545
|
+
*/
|
|
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;
|
|
554
|
+
/**
|
|
555
|
+
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
556
|
+
* folded into matching props' annotation arrays. Skips chained entries
|
|
557
|
+
* (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
|
|
558
|
+
* Original prop nodes are reused by reference when no extra annotations apply.
|
|
537
559
|
*/
|
|
538
|
-
|
|
560
|
+
private applyAnnotateBlocksToStructure;
|
|
539
561
|
usageListFor(token: Token): Array<{
|
|
540
562
|
uri: string;
|
|
541
563
|
range: Token['range'];
|
package/dist/index.mjs
CHANGED
|
@@ -3448,21 +3448,50 @@ 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
|
-
|
|
3451
|
+
*
|
|
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) {
|
|
3452
3460
|
if (!node.hasExtends) return undefined;
|
|
3453
3461
|
const visited = _visited || new Set();
|
|
3454
3462
|
if (node.id && visited.has(node.id)) return undefined;
|
|
3455
3463
|
if (node.id) visited.add(node.id);
|
|
3464
|
+
const originDoc = _originDoc ?? this;
|
|
3456
3465
|
let mergedStruct;
|
|
3457
3466
|
for (const extendsToken of node.extendsTokens) {
|
|
3458
3467
|
const unwound = this.unwindType(extendsToken.text);
|
|
3459
3468
|
if (!unwound?.def) continue;
|
|
3460
3469
|
let parentDef = unwound.def;
|
|
3470
|
+
const parentDeclName = unwound.node?.id ?? parentDef.id;
|
|
3461
3471
|
if (isInterface(parentDef) && parentDef.hasExtends) {
|
|
3462
|
-
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited);
|
|
3472
|
+
const resolved = unwound.doc.resolveInterfaceExtends(parentDef, visited, originDoc);
|
|
3463
3473
|
parentDef = resolved || parentDef.getDefinition() || parentDef;
|
|
3464
3474
|
} else if (isInterface(parentDef)) parentDef = parentDef.getDefinition() || parentDef;
|
|
3465
3475
|
parentDef = this.mergeIntersection(parentDef);
|
|
3476
|
+
const annotateNodes = [];
|
|
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
|
+
}
|
|
3493
|
+
}
|
|
3494
|
+
if (annotateNodes.length > 0) parentDef = this.applyAnnotateBlocksToStructure(parentDef, annotateNodes);
|
|
3466
3495
|
if (!mergedStruct) mergedStruct = parentDef;
|
|
3467
3496
|
else {
|
|
3468
3497
|
const merged = this.mergeDefs(mergedStruct, parentDef);
|
|
@@ -3476,6 +3505,61 @@ else {
|
|
|
3476
3505
|
}
|
|
3477
3506
|
return mergedStruct || ownDef;
|
|
3478
3507
|
}
|
|
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
|
+
/**
|
|
3521
|
+
* Returns a structure equivalent to `struct` with annotate-block contributions
|
|
3522
|
+
* folded into matching props' annotation arrays. Skips chained entries
|
|
3523
|
+
* (e.g. `annotate Parent { user.address.city }`) — only root-level entries apply.
|
|
3524
|
+
* Original prop nodes are reused by reference when no extra annotations apply.
|
|
3525
|
+
*/ applyAnnotateBlocksToStructure(struct, annotateNodes) {
|
|
3526
|
+
if (!isStructure(struct)) return struct;
|
|
3527
|
+
const annotationsByProp = new Map();
|
|
3528
|
+
for (const annotateNode of annotateNodes) for (const entry of annotateNode.entries) {
|
|
3529
|
+
if (entry.hasChain) continue;
|
|
3530
|
+
const propName$1 = entry.id;
|
|
3531
|
+
const anns = entry.annotations;
|
|
3532
|
+
if (!propName$1 || !anns || anns.length === 0) continue;
|
|
3533
|
+
const existing = annotationsByProp.get(propName$1);
|
|
3534
|
+
annotationsByProp.set(propName$1, existing ? [...existing, ...anns] : [...anns]);
|
|
3535
|
+
}
|
|
3536
|
+
if (annotationsByProp.size === 0) return struct;
|
|
3537
|
+
const structNode = struct;
|
|
3538
|
+
const newProps = [];
|
|
3539
|
+
let changed = false;
|
|
3540
|
+
for (const [name, prop] of structNode.props) {
|
|
3541
|
+
const extras = annotationsByProp.get(name);
|
|
3542
|
+
if (!extras) {
|
|
3543
|
+
newProps.push(prop);
|
|
3544
|
+
continue;
|
|
3545
|
+
}
|
|
3546
|
+
const cloned = new SemanticPropNode();
|
|
3547
|
+
const idToken = prop.token("identifier");
|
|
3548
|
+
if (idToken) cloned.saveToken(idToken, "identifier");
|
|
3549
|
+
const propDef = prop.getDefinition();
|
|
3550
|
+
if (propDef) cloned.define(propDef);
|
|
3551
|
+
cloned.annotations = this.mergeNodesAnnotations(prop.annotations, extras);
|
|
3552
|
+
const optionalToken = prop.token("optional");
|
|
3553
|
+
if (optionalToken) cloned.saveToken(optionalToken, "optional");
|
|
3554
|
+
newProps.push(cloned);
|
|
3555
|
+
changed = true;
|
|
3556
|
+
}
|
|
3557
|
+
if (!changed) return struct;
|
|
3558
|
+
const newStruct = new SemanticStructureNode();
|
|
3559
|
+
newStruct.setProps(newProps);
|
|
3560
|
+
newStruct.annotations = structNode.annotations;
|
|
3561
|
+
return newStruct;
|
|
3562
|
+
}
|
|
3479
3563
|
usageListFor(token) {
|
|
3480
3564
|
if (token.isDefinition) {
|
|
3481
3565
|
const refs = this.referred.filter((t) => t.text === token.text).map((r) => ({
|