@atscript/core 0.1.110 → 0.2.0

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.
Files changed (4) hide show
  1. package/dist/index.cjs +5881 -943
  2. package/dist/index.d.ts +1644 -112
  3. package/dist/index.mjs +5887 -982
  4. package/package.json +1 -1
package/dist/index.d.ts CHANGED
@@ -83,6 +83,12 @@ declare class Token {
83
83
  * All the references must be marked with this flag
84
84
  */
85
85
  isReference?: boolean;
86
+ /**
87
+ * References only: the document the reference was written in (whose imports its name
88
+ * resolves against). A definition inlined into another document (an intersection member,
89
+ * `extends`, `annotate … as …` of an imported type) keeps it. Unset on synthetic references.
90
+ */
91
+ originDoc?: AtscriptDoc;
86
92
  /**
87
93
  * All the import tokens must be marked with this flag
88
94
  */
@@ -127,6 +133,25 @@ interface TPluginManagers {
127
133
  file?: string;
128
134
  dependants: Set<string>;
129
135
  }
136
+ /** Whether `doc` has a mutating `annotate` block (its generated module applies it). */
137
+ declare function hasMutatingAnnotates(doc: AtscriptDoc): boolean;
138
+ /**
139
+ * The documents declaring the types the mutating `annotate` blocks of `doc` annotate, other than
140
+ * `doc` itself: resolved as codegen and the runtime apply them (a block on a plain alias is a
141
+ * block on what it aliases, see `AtscriptDoc.blockTarget`). Their runtime state (and generated
142
+ * code, with bundled schemas) changes with these blocks.
143
+ */
144
+ declare function blockTargetDocuments(doc: AtscriptDoc): Set<AtscriptDoc>;
145
+ /**
146
+ * What the diagnostics of the mutating `annotate` blocks of `doc` read besides the documents it
147
+ * imports (directly or not): for each type they annotate that another document T declares (see
148
+ * {@link blockTargetDocuments}), T, the documents importing T (those using it) and the documents
149
+ * T and each of them import, directly or not (whether a block is reachable from them, see the
150
+ * warning of `AtscriptDoc.getDiagMessages`). When one of these documents changes — its text, or
151
+ * its imports (then also the documents it imports, now or before: their importers changed) —
152
+ * `doc`'s diagnostics are computed again.
153
+ */
154
+ declare function blockDependencies(doc: AtscriptDoc): Set<AtscriptDoc>;
130
155
  declare class AtscriptRepo {
131
156
  readonly root: string;
132
157
  readonly sharedConfig?: TAtscriptConfigInput | undefined;
@@ -189,7 +214,9 @@ declare class AtscriptRepo {
189
214
  protected _openDocument(id: string, text?: string): Promise<AtscriptDoc>;
190
215
  checkDoc(atscript: AtscriptDoc): Promise<void>;
191
216
  checkImports(atscript: AtscriptDoc, checked?: Set<string>): Promise<void>;
192
- checkImport(atscript: AtscriptDoc, from: Token, imports: Token[], checked?: Set<string>): Promise<AtscriptDoc | undefined>;
217
+ checkImport(atscript: AtscriptDoc, from: Token, imports: Token[], checked?: Set<string>,
218
+ /** where the messages go (the document's import messages; registered when not given) */
219
+ messages?: TMessages): Promise<AtscriptDoc | undefined>;
193
220
  }
194
221
 
195
222
  interface TOutput extends TOutputWithSource {
@@ -240,13 +267,22 @@ type TAtscriptRenderFormat = string;
240
267
  * ```
241
268
  */
242
269
  declare const DEFAULT_FORMAT: TAtscriptRenderFormat;
270
+ /** What the caller says about one render (see `TAtscriptPlugin.render`). */
271
+ interface TAtscriptRenderOptions {
272
+ /**
273
+ * Whether the render is checked as a real build's: the TypeScript plugin loads the generated
274
+ * modules and fails when one does not load (a one-shot bundler build, the CLI build). `true`:
275
+ * checked, `false`: not; unset: the plugin's default (`withLoadCheck` of `@atscript/typescript`).
276
+ */
277
+ loadCheck?: boolean;
278
+ }
243
279
  interface TAtscriptPlugin {
244
280
  name: string;
245
281
  config?: (config: TAtscriptConfig) => Promise<TAtscriptConfig | undefined> | TAtscriptConfig | undefined;
246
282
  resolve?: (id: string) => Promise<string | undefined> | string | undefined;
247
283
  load?: (id: string) => Promise<string | undefined> | string | undefined;
248
284
  onDocument?: (doc: AtscriptDoc) => Promise<void> | void;
249
- render?: (doc: AtscriptDoc, format: TAtscriptRenderFormat) => Promise<TPluginOutput[]> | TPluginOutput[];
285
+ render?: (doc: AtscriptDoc, format: TAtscriptRenderFormat, options?: TAtscriptRenderOptions) => Promise<TPluginOutput[]> | TPluginOutput[];
250
286
  buildEnd?: (output: TOutput[], format: TAtscriptRenderFormat, repo: AtscriptRepo) => Promise<void> | void;
251
287
  }
252
288
  declare const createAtscriptPlugin: (plugin: TAtscriptPlugin) => TAtscriptPlugin;
@@ -256,7 +292,11 @@ interface TOutputWithSource extends TPluginOutput {
256
292
  }
257
293
  declare class PluginManager {
258
294
  private readonly cfg;
259
- constructor(cfg: TAtscriptConfig);
295
+ /** The project root (absolute), the config's `rootDir` resolved. */
296
+ private readonly root?;
297
+ constructor(cfg: TAtscriptConfig,
298
+ /** The project root (absolute), the config's `rootDir` resolved. */
299
+ root?: string | undefined);
260
300
  private _config;
261
301
  name: string;
262
302
  protected _docConfig: TAtscriptDocConfig | undefined;
@@ -266,10 +306,9 @@ declare class PluginManager {
266
306
  resolve(id: string): Promise<string>;
267
307
  load(id: string): Promise<string>;
268
308
  onDocument(doc: AtscriptDoc): Promise<void>;
269
- render(doc: AtscriptDoc, format: TAtscriptRenderFormat): Promise<TOutputWithSource[]>;
309
+ render(doc: AtscriptDoc, format: TAtscriptRenderFormat, options?: TAtscriptRenderOptions): Promise<TOutputWithSource[]>;
270
310
  buildEnd(output: TOutput[], format: TAtscriptRenderFormat, repo: AtscriptRepo): Promise<void>;
271
311
  loopInAnnotationsSpec(cb: (name: string, a: AnnotationSpec) => void): Promise<void>;
272
- private _loopInAnnotationsSpec;
273
312
  }
274
313
 
275
314
  declare class IdRegistry {
@@ -387,9 +426,14 @@ declare class SemanticAnnotateNode extends SemanticNode {
387
426
  get isMutating(): boolean;
388
427
  get targetName(): string;
389
428
  get entries(): SemanticRefNode[];
429
+ private _annotatedEntries?;
430
+ /** The entries that carry annotations (an entry without any annotates nothing). */
431
+ get annotatedEntries(): SemanticRefNode[];
390
432
  get id(): string;
391
433
  registerAtDocument(doc: AtscriptDoc): void;
392
434
  }
435
+ /** The prop path (`['a', 'b', 'c']`) an `annotate` entry addresses. */
436
+ declare function entryParts(entry: SemanticRefNode): string[];
393
437
 
394
438
  declare class SemanticPropNode extends SemanticNode {
395
439
  constructor();
@@ -427,6 +471,1051 @@ declare class SemanticPrimitiveNode extends SemanticNode {
427
471
  toString(level?: number, prefix?: string): string;
428
472
  }
429
473
 
474
+ /**
475
+ * The final structure of a build's declarations: which runtime node every position of every
476
+ * declaration is, what def (type object) it has, which merges are written out as hidden classes,
477
+ * where blocks shell their paths, and in which static order blocks apply. Generated code prints
478
+ * it; diagnostics read it.
479
+ *
480
+ * Vocabulary:
481
+ * - a *def* ({@link TStructDef}) is a type object as the runtime builds it: a declaration's class,
482
+ * a builder def written in place (`{…}`, `T[]`), a union def, a hidden merge class (one per
483
+ * distinct operand list per module), a shell def (a copy of a shared def a path override needs);
484
+ * - a *slot* ({@link TStructSlot}) is the node a def holds under a prop name / `[]`: `loc` is its
485
+ * identity (equal locs = the same node object), `def` the def it has;
486
+ * - *steps* are internal paths: prop names, `[]` for array elements, `|i` for union branches.
487
+ *
488
+ * Identity: every prop / element is its holder's own node (a reference
489
+ * `p?: T` is a thin node over T whose def is T's); a merged field with one contributor IS that
490
+ * node; with several it is the merge's own node; a unit's layers (blocks, `as` entries) at path L
491
+ * give it shells at every prefix of L.
492
+ */
493
+
494
+ /** More hidden merge classes than this in one module is a compile error. */
495
+ declare const MERGE_CAP = 200;
496
+ /**
497
+ * The branch combinations a distributed merge may have; past it the merge is the compile error
498
+ * "merge too complex" at its module, never a truncated union.
499
+ */
500
+ declare const PRODUCT_CAP: number;
501
+ declare const UNION_IN_RECURSIVE_MERGE = "union members are not supported in recursive merges; split with named types";
502
+ declare const MERGE_TOO_COMPLEX = "merge too complex: split it with named types";
503
+ /** Why scalars (or an object and a scalar) merge to `never`. */
504
+ declare const NOTHING_IN_COMMON = "values with nothing in common";
505
+ /** A type written as an operand of its own merge (`type X = A & X`). */
506
+ declare const SELF_OPERAND = "a type cannot be an operand of its own merge; recurse through a field instead";
507
+ /** A db entity whose flattening reaches a web of mutually recursive merges. */
508
+ declare const FLATTEN_WEB = "flattening this type reaches mutually recursive merges; split it with named types";
509
+ /**
510
+ * A block entry whose path crosses a type path (a chain ref through a union) that the entry
511
+ * itself splits (MODEL §15 SELF-SPLIT): where it lands depends on the positions it decides.
512
+ */
513
+ declare const SELF_SPLIT = "A block's path can't cross the type path it splits.";
514
+ /** A declaration of the build: an interface, a `type`, or an `annotate T as X` copy. */
515
+ interface TStructDecl {
516
+ /** unique in the model: `name@<document index>` */
517
+ id: string;
518
+ name: string;
519
+ doc: AtscriptDoc;
520
+ node: SemanticNode;
521
+ kind: 'interface' | 'type' | 'as';
522
+ }
523
+ /** A written type expression, resolved. */
524
+ type TStructExpr = {
525
+ k: 'ref';
526
+ decl: TStructDecl;
527
+ node: SemanticNode;
528
+ } | {
529
+ k: 'chain';
530
+ decl: TStructDecl;
531
+ path: string[];
532
+ node: SemanticNode;
533
+ /**
534
+ * a position standing for its group in a type path's structure, its blocks looked through:
535
+ * no node stands for the group — its type only (see `StructureModel.groupExpr`)
536
+ */
537
+ rep?: true;
538
+ } | {
539
+ k: 'obj';
540
+ node: SemanticNode;
541
+ props: TStructProp[];
542
+ } | {
543
+ k: 'arr';
544
+ node: SemanticNode;
545
+ of: TStructExpr;
546
+ } | {
547
+ k: 'nul';
548
+ node: SemanticNode;
549
+ of: TStructExpr;
550
+ } | {
551
+ k: 'and';
552
+ node: SemanticNode;
553
+ items: TStructExpr[];
554
+ } | {
555
+ k: 'uni';
556
+ node: SemanticNode;
557
+ items: TStructExpr[];
558
+ /**
559
+ * a type path's positions (see `StructureModel.typePathPositions`) some of which differ
560
+ * only by blocks: the structure — one position per declared field (MODEL §15 STRUCT-N3)
561
+ */
562
+ struct?: TStructExpr;
563
+ } | {
564
+ k: 'tup';
565
+ node: SemanticNode;
566
+ items: TStructExpr[];
567
+ }
568
+ /** a primitive (`string`, `string.email`, `null`) or a literal */
569
+ | {
570
+ k: 'scalar';
571
+ node: SemanticNode;
572
+ doc: AtscriptDoc;
573
+ } | {
574
+ k: 'unknown';
575
+ node?: SemanticNode;
576
+ };
577
+ interface TStructProp {
578
+ name: string;
579
+ optional: boolean;
580
+ node: SemanticPropNode;
581
+ type: TStructExpr;
582
+ }
583
+ /** An intersection written in the build: its merge, module, and place (see `StructureModel.mergeRoots`). */
584
+ interface TMergeRoot {
585
+ mod: AtscriptDoc;
586
+ def: TStructDef;
587
+ own?: boolean;
588
+ decl: TStructDecl;
589
+ path: string[];
590
+ }
591
+ /** A def as the runtime builds it. */
592
+ interface TStructDef {
593
+ /** identity: equal keys = the same def object */
594
+ key: string;
595
+ /**
596
+ * `class`: a declaration's class def (interface, named merge); `builder`: written in place;
597
+ * `union`: a union of objects; `merge`: a hidden merge class; `umerge`: a merge with a union
598
+ * operand (distributes: a union of branch merges); `shell`: a shell def; `view`: an
599
+ * `annotate T as X` copy's view of T's def (the runtime shares T's def, shelled where X has
600
+ * entries or blocks)
601
+ */
602
+ kind: 'class' | 'builder' | 'union' | 'merge' | 'umerge' | 'shell' | 'view';
603
+ /** the unit (declaration id) whose own def this is (class, builder, union, shell) */
604
+ unit?: string;
605
+ /** a shell def: its position in its unit */
606
+ at?: string[];
607
+ slot: (k: string) => TStructSlot | undefined;
608
+ /** the slot as built before the unit's own shells (class / builder defs; shell step kinds) */
609
+ raw?: (k: string) => TStructSlot | undefined;
610
+ branch?: (i: number) => TStructDef | undefined;
611
+ /** the number of branches of a union / distributed merge (`branch(i)` for i < size) */
612
+ size?: number;
613
+ uni?: boolean;
614
+ names?: () => string[];
615
+ /** a hidden merge's operands */
616
+ ops?: TStructDef[];
617
+ /**
618
+ * a shell def's base; a view's: the def it views (an `as` copy's target's, an annotated-alias
619
+ * operand's target's)
620
+ */
621
+ base?: TStructDef;
622
+ /** the module a hidden merge class is written in */
623
+ module?: AtscriptDoc;
624
+ /** the written type expressions the def stands for (its shape; a merge: its operands') */
625
+ src?: TStructExpr[];
626
+ /** a union / distributed merge: the written expressions of branch `i` (a merge branch: its members') */
627
+ bsrc?: (i: number) => TStructExpr[];
628
+ /**
629
+ * a distributed merge: the member each union operand gives branch `i` — the operand (its
630
+ * structure key) and the item path of that member in it
631
+ */
632
+ bpick?: (i: number) => Array<{
633
+ key: string;
634
+ at: number[];
635
+ }>;
636
+ /**
637
+ * a union of a type path's positions some of which differ only by blocks: its structure, one
638
+ * position per declared field, the field's def without blocks (MODEL §15 STRUCT-N3; see
639
+ * {@link structDef})
640
+ */
641
+ struct?: TStructDef;
642
+ }
643
+ /** A node held by a def (a prop, an element, a merged field). */
644
+ interface TStructSlot {
645
+ /** identity: equal locs = the same node object (`unit:steps`, `m:<merge>/<name>`) */
646
+ loc: string;
647
+ def?: TStructDef;
648
+ /** the written type expressions of its contributors */
649
+ ends: TStructExpr[];
650
+ /** `?`: only if every contributor is optional */
651
+ optional: boolean;
652
+ /** a merged field's contributor nodes (several distinct ones), in operand order */
653
+ contributors?: TStructSlot[];
654
+ /**
655
+ * Where the node is defined: a unit (a declaration id, or `m:<key>` for a hidden merge class's
656
+ * own field) and the steps from its root (`$f(Root, …path)`; `&i` steps: an in-place merge
657
+ * operand). A reference slot is its target's own slot object (same owner).
658
+ */
659
+ owner?: {
660
+ unit: string;
661
+ path: string[];
662
+ };
663
+ /** a shell node: the node it shells (its base) */
664
+ shell?: TStructSlot;
665
+ /** the prop declaring the node (an own field; a shell keeps its base's): none for an element or a merged field */
666
+ prop?: SemanticPropNode;
667
+ }
668
+ /** The shape at a position (coarse). */
669
+ type TStructShape = {
670
+ k: 'obj';
671
+ props: Map<string, {
672
+ optional: boolean;
673
+ }>;
674
+ } | {
675
+ k: 'arr';
676
+ }
677
+ /** a union holding objects: `items` = its branches' shapes */
678
+ | {
679
+ k: 'uni';
680
+ n: number;
681
+ items: TStructShape[];
682
+ } | {
683
+ k: 'scalar';
684
+ } | {
685
+ k: 'never';
686
+ reason: string;
687
+ } | {
688
+ k: 'mixed';
689
+ };
690
+ /** A block (mutating `annotate T { … }`) or an `annotate … as` copy's entries, normalized. */
691
+ interface TStructBlock {
692
+ doc: AtscriptDoc;
693
+ node: SemanticAnnotateNode;
694
+ /** the declaration it writes into (a plain alias resolved to its target) */
695
+ target: TStructDecl;
696
+ /** `undefined` for `as` entries (rank ⊥) */
697
+ rank?: TStructRank;
698
+ /** index among its module's blocks, in source order */
699
+ index: number;
700
+ entries: TStructEntry[];
701
+ }
702
+ interface TStructEntry {
703
+ ref: SemanticRefNode;
704
+ /** the path as written */
705
+ names: string[];
706
+ /** normalized internal steps (one per union branch with the prop) */
707
+ paths: string[][];
708
+ /** per path, per step: 0 own node, 1 a reference child of an own def, 2 a shared def */
709
+ kinds: Array<Array<0 | 1 | 2>>;
710
+ error?: string;
711
+ }
712
+ /** The static rank of a module's blocks: (import depth, module id); then by source order. */
713
+ interface TStructRank {
714
+ depth: number;
715
+ id: string;
716
+ }
717
+ interface TStructError {
718
+ doc: AtscriptDoc;
719
+ node?: SemanticNode;
720
+ /** where it is reported, when not at `node`'s name */
721
+ token?: Token;
722
+ message: string;
723
+ /** an annotate entry the model refuses */
724
+ entry?: boolean;
725
+ }
726
+ /** A position a merge makes `never`, see `StructureModel.neverWarnings`. */
727
+ interface TStructNever {
728
+ decl: TStructDecl;
729
+ /** prop names from the declaration's root (array elements and union branches left out) */
730
+ path: string[];
731
+ reason: string;
732
+ /** the merged slot (none: the declaration itself) */
733
+ slot?: TStructSlot;
734
+ /** reached through a union branch (a distributed merge's) */
735
+ branch: boolean;
736
+ }
737
+ /** One layer of a unit at a path: a block's (or an `as` copy's) entry. */
738
+ interface TStructLayer {
739
+ block: TStructBlock;
740
+ entry: TStructEntry;
741
+ }
742
+ type Layer = TStructLayer;
743
+ /** A written `null`. */
744
+ declare const isNull: (x: TStructExpr) => boolean;
745
+ /** Slot `s` with its shells looked through (the node they shell). */
746
+ declare function baseSlot(s: TStructSlot): TStructSlot;
747
+ /** An `annotate T as X` copy's view of T's def (`d:<X>`). */
748
+ declare const isAsView: (t: TStructDef) => boolean;
749
+ /** A def with views looked through (an `as` copy's, an annotated-alias operand's): the def they view. */
750
+ declare function pastViews(t: TStructDef): TStructDef;
751
+ /** A def with its shells looked through (the def they shell). */
752
+ declare function unshell(t: TStructDef): TStructDef;
753
+ /** Where an own def of a unit is written (`pk` of its steps): a class at the root, a builder / union at its key's path. */
754
+ declare function defPosition(d: TStructDef): string | undefined;
755
+ /**
756
+ * An intersection's operands as written: inline `&` flattened, `| null` members as their inner
757
+ * type (any other expression: itself).
758
+ */
759
+ declare function andExprs(t: TStructExpr): TStructExpr[];
760
+ /**
761
+ * The strongly connected components of the graph reached from `starts` (Tarjan, iterative: chains
762
+ * can be long): node → its component (one array per component).
763
+ */
764
+ declare function components<T>(starts: Iterable<T>, succ: (k: T) => T[]): Map<T, T[]>;
765
+ /** One structure model per set of documents (a build). */
766
+ declare class StructureModel {
767
+ private readonly byField;
768
+ readonly docs: AtscriptDoc[];
769
+ private readonly docIndex;
770
+ private readonly declsByNode;
771
+ private readonly declsById;
772
+ readonly decls: TStructDecl[];
773
+ readonly errors: TStructError[];
774
+ /** layers per unit: path key -> layers (blocks and `as` entries) */
775
+ private readonly layers;
776
+ private readonly exprMemo;
777
+ /** chain refs whose plain chain stands in `exprMemo` while their positions are found */
778
+ private readonly placeholders;
779
+ /** chain refs resolved, by node: the type path written (see {@link crossings}) */
780
+ private readonly chainPaths;
781
+ /**
782
+ * The entries of the blocks (and `as` copies) writing into each unit, normalized on demand:
783
+ * a type path through a union reads the blocks at or below its fields (MODEL §15 POS-1a), and
784
+ * an entry's path may cross such a type path. See {@link ready}.
785
+ */
786
+ private readonly unitEntries;
787
+ /** entries being normalized (on the stack) */
788
+ private readonly busyEntries;
789
+ /** entries normalized */
790
+ private readonly doneEntries;
791
+ /** mutating blocks by the name they annotate: `[module, index among its blocks]` */
792
+ private readonly sitesByName;
793
+ /** blocks made (a mutating block whose target does not resolve: null), by node */
794
+ private readonly blockOf;
795
+ /** blocks whose entries are collected (see {@link unitBlocks}) */
796
+ private readonly registered;
797
+ /** units whose blocks are all collected */
798
+ private readonly collected;
799
+ private blocksMemo?;
800
+ private aliasesMemo?;
801
+ /** the `type P = <a reference>` declarations (see {@link aliases}) */
802
+ private readonly aliasLike;
803
+ /** bumped by every layer added: defs built before may lack its shells */
804
+ private layerEpoch;
805
+ /** {@link layerEpoch} when the defs were last cleared */
806
+ private defsEpoch;
807
+ /**
808
+ * bumped by every {@link clearDefs}: nodes walked before it are of defs no longer current (a
809
+ * type path's walk restarts when a nested walk — a block normalized on the way — cleared them)
810
+ */
811
+ private defsGen;
812
+ /** the type paths' positions (see {@link typePathPositions}): `decl id \0 path` */
813
+ private readonly positionsMemo;
814
+ /**
815
+ * The type paths being resolved, each with the number of block normalizations ({@link ready})
816
+ * open when it started: one met again from a normalization opened since — an entry whose path
817
+ * crosses it while its positions wait for that entry — is a cycle ({@link CYCLE_ABORT}); met
818
+ * again otherwise, a type path reaching itself (reported).
819
+ */
820
+ private readonly resolving;
821
+ /** block normalizations open on behalf of type paths (see {@link resolving}) */
822
+ private readyDepth;
823
+ /** entries whose landing depends on themselves: compile errors (see {@link meet}) */
824
+ private readonly selfSplits;
825
+ /** every entry normalized and the final model built (see {@link complete}) */
826
+ private completed;
827
+ /**
828
+ * The structural model: every type path by its declared fields, no block in it (see {@link
829
+ * byField}): where a block lands, and what it splits, without the splits it may cause.
830
+ */
831
+ private structuralMemo?;
832
+ /**
833
+ * The model of `docs` and what they import. Type paths and the blocks they depend on are
834
+ * resolved on demand; {@link complete} builds the final model (defs, layers, shell kinds,
835
+ * errors). `byField`: the structural model (see {@link structural}).
836
+ */
837
+ constructor(docs: Iterable<AtscriptDoc>, byField?: boolean);
838
+ /** Whether any block (or `as` copy's entry) is written: else no type path depends on blocks. */
839
+ private readonly layered;
840
+ /**
841
+ * Whether type path `key` is being resolved and waits for a block normalization opened since:
842
+ * a block's path crossing it now is a cycle (see {@link resolving}).
843
+ */
844
+ private waits;
845
+ /** The declaration `name` resolves to in `doc` (through imports). */
846
+ declOf(doc: AtscriptDoc, name: string): TStructDecl | undefined;
847
+ /** The model's declaration of a semantic declaration node. */
848
+ declOfNode(node: SemanticNode): TStructDecl | undefined;
849
+ /** `type P = T` / `type P = (T)`: the declaration it aliases directly. */
850
+ aliasStep(d: TStructDecl): TStructDecl | undefined;
851
+ /**
852
+ * A BARE plain alias (no type-level annotations of its own) is literally its target
853
+ * (`P = T` in the generated JS): its root IS the target's node. An alias with its own
854
+ * type-level annotations is a thin node of its own over its target. (Blocks on any plain alias
855
+ * target its final target: {@link plainTarget}.)
856
+ */
857
+ bareTarget(d: TStructDecl): TStructDecl;
858
+ /** A plain alias is its target (through aliases of aliases). */
859
+ plainTarget(d: TStructDecl): TStructDecl;
860
+ /** The expression a `type` declares. */
861
+ declExpr(d: TStructDecl): TStructExpr;
862
+ /** The target of an `annotate T as X` copy. */
863
+ asTarget(d: TStructDecl): TStructDecl | undefined;
864
+ /** The declaration whose structure `d` has: an `as` copy's (through copies of copies) target. */
865
+ structureRoot(d: TStructDecl): TStructDecl | undefined;
866
+ /** An interface's parents, in order. */
867
+ extendsOf(d: TStructDecl): TStructDecl[];
868
+ /** An interface's own props. */
869
+ ownProps(d: TStructDecl): TStructProp[];
870
+ private propsOf;
871
+ /** A written type expression of `doc`, resolved. */
872
+ exprOf(doc: AtscriptDoc, node: SemanticNode | undefined): TStructExpr;
873
+ /**
874
+ * A chain ref through a union of objects: one chain per position the path reaches (see
875
+ * {@link typePathPositions}); one: that field; none: the chain as written (core reports the
876
+ * unknown member). Several fields, every one phantom: one phantom prop none of which is its
877
+ * target, typed by the fields' common phantom primitive (`ui.action`), else `phantom`
878
+ * (MODEL §15 CHAIN-1 U4, POS-1c; a mix is a compile error).
879
+ */
880
+ private chainThroughUnions;
881
+ /**
882
+ * The written type standing for positions `group` of a type path (one type for structure, two
883
+ * or more of them; `first`: the first one's chain) in its structure: no position's blocks
884
+ * (MODEL §15 STRUCT-N3-META). One declared field: that field (`I0.h`, its own nodes). Several
885
+ * fields of one type: that type only, the same in every order (STRUCT-N3-DEF, GROUP-META,
886
+ * ALIAS) — the type every position writes (`H`, `P`, `string`), else the class they share
887
+ * (`H` for `h: H` and `h: P`, P an annotated alias of H): a field's or an alias's own
888
+ * annotations stay metadata on the runtime items.
889
+ * Else — a field no declaration names, a type no written type or class stands for — the first
890
+ * position, its blocks looked through for structure (`rep`: no node stands for the group).
891
+ */
892
+ private groupExpr;
893
+ /**
894
+ * What stands for type path `e` — written, or through type aliases — when its positions are
895
+ * one type for structure (see {@link groupExpr}): the declared field (a chain to it) or the type
896
+ * (MODEL §15 STRUCT-N3-META, GROUP-META); undefined for several types, a group no written
897
+ * type stands for (its type only, no node), or any other type.
898
+ */
899
+ oneType(e: TStructExpr): TStructExpr | undefined;
900
+ /**
901
+ * Whether the field chain `c` names is phantom: every type written there is a phantom
902
+ * primitive (through aliases, chains), each added to `prims` by its key.
903
+ */
904
+ private phantomField;
905
+ /**
906
+ * The positions type path `path` of `d` reaches through unions (MODEL §15 CHAIN-1, POS-1), as
907
+ * internal paths (`|i` steps): a union — or a distributed merge without the prop — fans out
908
+ * into its branches (nested unions flattened), each step keeps the positions that have the
909
+ * prop (a branch that dead-ends deeper is skipped), and branches reaching one position
910
+ * ({@link slotKey}) are one, the first. `undefined` when the path crosses no union or no
911
+ * position reaches its end.
912
+ *
913
+ * A field reached on several branches is one position only with the same blocks at or below it
914
+ * (POS-1a): before comparing them, the blocks of the units holding the nodes on the way are
915
+ * normalized ({@link onePerPosition}) — a type path is resolved once, on demand, with the blocks
916
+ * it depends on. A block whose own path crosses the type path is landed provisionally, or is a
917
+ * compile error when its landing depends on a split it causes ({@link meet}).
918
+ *
919
+ * (Core's `AtscriptDoc.pathWalk` is the same chain step on semantic nodes: the two must stay
920
+ * in step.)
921
+ */
922
+ typePathPositions(d: TStructDecl, path: string[]): string[][] | undefined;
923
+ /**
924
+ * {@link typePathPositions}' types for structure, one {@link typeKey} per position: positions
925
+ * of one type are one for structure, whatever field they come from (MODEL §15 STRUCT-N3-DEF) —
926
+ * the rule core's `AtscriptDoc.unwindType` reads too.
927
+ */
928
+ typePathTypes(d: TStructDecl, path: string[]): string[] | undefined;
929
+ /** {@link typePathPositions} with each position's declared field and type. */
930
+ private positionsAt;
931
+ /**
932
+ * {@link typePathPositions}'s walk: the positions with their nodes, or {@link RESTART}; no
933
+ * `ctx`: by declared field (no blocks). `units`: records the units holding the nodes on the way
934
+ * (see {@link TUnits}) — with `ctx`, from the first step reaching a field several times (only
935
+ * then do blocks decide: {@link onePerPosition}), the steps before walked again for theirs.
936
+ */
937
+ private positionsWalk;
938
+ /**
939
+ * The type of a type path's position (its node `s`) for structure (MODEL §15 STRUCT-N3-DEF):
940
+ * equal keys are one for structure, whatever field they come from — its def as structure sees
941
+ * it (see {@link structKey}: no block counts), and whether it takes `null`; a node without a def
942
+ * (a scalar, a tuple) by the types written there.
943
+ */
944
+ private typeKey;
945
+ private readonly typeKeys;
946
+ /** A number per object (an identity in a key). */
947
+ private idOf;
948
+ private readonly ids;
949
+ private nextId;
950
+ /** The declared field of each of positions `at` (see {@link slotKey}; none: `''`). */
951
+ private fieldsOf;
952
+ /**
953
+ * One step `s` of a type path from positions `at`: a union (or a distributed merge without the
954
+ * prop) fans out into the branches that have it; once a union is crossed, positions without
955
+ * the prop drop out. `units`: see {@link positionsWalk}.
956
+ */
957
+ private stepPositions;
958
+ /**
959
+ * Calls `visit` for def `t0` and every def it is held through: the defs a shell shells, an `as`
960
+ * view's target def (`everyView`: any view's), a merge's operands (the higher priority — later
961
+ * — first).
962
+ */
963
+ private forEachHolder;
964
+ /**
965
+ * Adds the units whose blocks may shell the nodes the walk reaches (see {@link TUnits}) at step
966
+ * `step` below def `def`: its own unit at its position, the defs it shells or views, a merge's
967
+ * operands, and the nodes a chain ref written there names (its field's def is that node's: see
968
+ * {@link addExprUnits}) — what a type path's positions are keyed by (see {@link slotKey}).
969
+ */
970
+ private addDefUnits;
971
+ /** {@link addDefUnits} of node `slot`: its owner and every shell's, a merged field's contributors'. */
972
+ private addSlotUnits;
973
+ /** {@link addDefUnits} of the nodes on the way to the field a chain ref written in `e` names. */
974
+ private addExprUnits;
975
+ /** {@link typePathPositions}'s step into the branches of union `def` (at `p`) that have prop `s`, nested unions flattened. */
976
+ private branchesWith;
977
+ /**
978
+ * Positions `at` of a type path, one per position (the first): by the declared field
979
+ * ({@link slotKey} without blocks); with `ctx`, a field reached several times by its blocks
980
+ * too, once the units holding the nodes on the way (`units`) have their blocks in
981
+ * ({@link RESTART} when that added layers).
982
+ */
983
+ private onePerPosition;
984
+ /**
985
+ * Whether `entry`'s layers differ between the positions of one field of type path (d, path)
986
+ * (by declared field, every position kept): its entries at or below each node, relative to it
987
+ * (see {@link slotKey}) — the entry splits the type path (MODEL §15 SELF-SPLIT-4).
988
+ */
989
+ private splits;
990
+ /**
991
+ * Where `entry` has layers at or below node `s`, relative to it: whichever shell of the node
992
+ * holds them (one entry's annotations are the same at any level — which nodes are shells
993
+ * depends on the blocks normalized so far, not on the entry); a merged field's contributors'.
994
+ */
995
+ private entrySig;
996
+ /**
997
+ * The identity of a position of a type path (MODEL §15 POS-1, POS-1a, POS-1b): the field its
998
+ * node `s` is — shells looked through: a declared field, or a merged field's contributors
999
+ * (each counted once, in order) — and the blocks at or below it: per shell (and the field
1000
+ * itself), the entries its unit's layers have at or below it, relative to it. Equal keys: one
1001
+ * position. `blocks` false: the field only.
1002
+ */
1003
+ private slotKey;
1004
+ /** {@link slotKey}s by slot: the field's; with blocks, at a layer epoch */
1005
+ private readonly fieldKeys;
1006
+ private readonly blockKeys;
1007
+ /**
1008
+ * The declared props the field at position (d, path) is (shells looked through): a declared
1009
+ * field its prop, a merged field its contributors' (each once, in order; MODEL §15 POS-1b).
1010
+ */
1011
+ declaredProps(d: TStructDecl, path: string[]): SemanticPropNode[];
1012
+ private slotProps;
1013
+ /** The entries unit `U`'s layers have at or below `at`: `relative path=entry`, sorted. */
1014
+ private entriesBelow;
1015
+ /** {@link entriesBelow} per unit, per path (cleared with the unit's layers) */
1016
+ private readonly belowMemo;
1017
+ private exprOf0;
1018
+ /**
1019
+ * The final model (once): every entry normalized — those no type path needed yet, unit by unit
1020
+ * in block order —, defs rebuilt with every layer, the layers in block order, the shell kinds,
1021
+ * the errors.
1022
+ */
1023
+ complete(): this;
1024
+ private clearDefs;
1025
+ /**
1026
+ * Every block (and `as` copy's entries), in static source order: the copies' first, then each
1027
+ * module's blocks in source order. Their entries are collected per unit (see {@link
1028
+ * unitBlocks}).
1029
+ */
1030
+ get blocks(): TStructBlock[];
1031
+ /** The block of mutating `annotate` node `node` (block `index` of `doc`), its target resolved. */
1032
+ private siteBlock;
1033
+ /** The plain aliases of the build (`type P = T`: a block on P is on T). */
1034
+ private aliases;
1035
+ /** The names that annotate unit `T`: its own, its plain aliases' (memoized per unit). */
1036
+ private namesOf;
1037
+ private readonly unitNames;
1038
+ /**
1039
+ * Collects the entries of the blocks writing into unit `T` for {@link ready}: its `as` copy's
1040
+ * (at their path only, no collapse), the mutating blocks on T or a plain alias of it, in static
1041
+ * source order. `props`: only blocks with an entry naming one of them (see {@link TUnits}) — a
1042
+ * block's target is resolved when it is collected.
1043
+ */
1044
+ private unitBlocks;
1045
+ /** a block entry's identity in the model (the order its unit's blocks were collected) */
1046
+ private readonly entryIds;
1047
+ /**
1048
+ * Normalizes the pending entries writing into unit `U` (`props`: those that may land at or
1049
+ * below its nodes starting with one of them, see {@link TUnits}). For a type path's blocks
1050
+ * (`ctx`): an entry that cannot be normalized before it — on the stack, or crossing a type path
1051
+ * being resolved — is met ({@link meet}).
1052
+ */
1053
+ private ready;
1054
+ /**
1055
+ * Type path `ctx` waits for entry `x`'s unit's blocks, but `x`'s landing waits for a type path
1056
+ * being resolved (`busy`: `x` is on the stack). Decided on the structural model, where every
1057
+ * type path is its declared fields (see {@link structural}): an entry whose landing depends on
1058
+ * itself — directly or through other blocks' landings — is a compile error (MODEL §15
1059
+ * SELF-SPLIT, -2, -3, -4); an entry that does not split `ctx` is left out of it (it does not
1060
+ * change its positions); one that splits it, and whose landing waits for another type path,
1061
+ * makes `ctx` wait too ({@link CYCLE_ABORT}: its reader is met in turn).
1062
+ */
1063
+ private meet;
1064
+ /** The structural model of this model's documents (see {@link structuralMemo}). */
1065
+ private structural;
1066
+ /** The pending entry of entry `ref` of block `node` (its unit's blocks collected), normalized. */
1067
+ private entryOf;
1068
+ /** type paths read so far, by key (see {@link pathKeyOf}): their declaration and path */
1069
+ private readonly typePaths;
1070
+ /**
1071
+ * (Structural model) the type paths entry `ref` of block `node` lands through — a node above
1072
+ * where it lands is typed through them, by any route ({@link crossings}) —, and transitively
1073
+ * what they depend on.
1074
+ */
1075
+ readsOf(node: SemanticAnnotateNode, ref: SemanticRefNode): Set<string>;
1076
+ private readonly readsMemo;
1077
+ /**
1078
+ * (Structural model) adds to `out` the type paths written expression `e` resolves through — a
1079
+ * chain ref (and what its positions and its fields' types resolve through: a chain hop), `X |
1080
+ * null`, a union, a merge operand, an array's element, an alias (MODEL §15 SELF-SPLIT-2).
1081
+ */
1082
+ private crossings;
1083
+ /**
1084
+ * (Structural model) what type path `key`'s positions depend on: the type paths the nodes above
1085
+ * its positions are typed through ({@link crossings}).
1086
+ */
1087
+ private deps;
1088
+ private readonly depsMemo;
1089
+ /**
1090
+ * (Structural model) whether entry `ref` of block `node` splits the type path `path` of
1091
+ * declaration `declId` (see {@link splits}).
1092
+ */
1093
+ entrySplits(node: SemanticAnnotateNode, ref: SemanticRefNode, [declId, path]: [string, string[]]): boolean;
1094
+ /**
1095
+ * (Structural model) the entries splitting type path `key`: among the blocks of the units
1096
+ * holding its positions' nodes (by declared field), those whose layers differ between the
1097
+ * positions of one field.
1098
+ */
1099
+ private affecters;
1100
+ private readonly affectersMemo;
1101
+ /**
1102
+ * (Structural model) the entries whose landings depend on entry `ref` of block `node` and on
1103
+ * which its landing depends — through the type paths they land through and the blocks
1104
+ * splitting those (MODEL §15 SELF-SPLIT-3): the cycle it is on, empty when none.
1105
+ */
1106
+ selfCycle(node: SemanticAnnotateNode, ref: SemanticRefNode): Set<SemanticRefNode>;
1107
+ /** (Structural model) {@link selfCycle} by entry */
1108
+ private readonly cycleOf;
1109
+ /** (Structural model) the block of each entry met by {@link landsAfter} */
1110
+ private readonly landingBlock;
1111
+ private readonly landsAfterMemo;
1112
+ /**
1113
+ * (Structural model) the entries entry `ref`'s landing depends on: those whose layers make
1114
+ * differ the positions of a type path it lands through ({@link readsOf}, {@link affecters}).
1115
+ */
1116
+ private landsAfter;
1117
+ /** An entry's internal paths (or its error), and its layers. */
1118
+ private normalizeEntry;
1119
+ private addLayer;
1120
+ /** The layers (blocks, `as` entries) of unit `d` at `steps`. */
1121
+ layersAt(d: TStructDecl, steps: string[]): Layer[];
1122
+ /**
1123
+ * An entry path (prop names) → internal steps from `T`'s root: `[]` through arrays, `| null`
1124
+ * passes through, and a step reaching T through a direct reference, a plain alias, an array
1125
+ * element or `| null` restarts at T's root (never through an intersection member or a merged
1126
+ * field). Through a union of objects: one path per branch that has the next prop, no collapse
1127
+ * there; no branch has it: an error. A string: the error.
1128
+ */
1129
+ normalize(T: TStructDecl, names: string[], collapse: boolean): string[][] | string;
1130
+ /**
1131
+ * The shape a block's path meets at `steps` of `T` (see `normalize`): a type path's positions
1132
+ * are its runtime union — a union of its positions whatever its structure (MODEL §15 STRUCT-N3:
1133
+ * blocks land per position, POS-1) —; else its shape.
1134
+ */
1135
+ private landingShape;
1136
+ /**
1137
+ * Whether the node at `steps` of `T` has a child `name`: by its def's names, without making the
1138
+ * child (see `normalize`); a name they do not list — a prop pattern's step — by the child.
1139
+ */
1140
+ private hasStep;
1141
+ /**
1142
+ * Whether a step reaching a node reaches `T`: every written type there unwraps (`| null`, plain
1143
+ * aliases, aliases of `X | null`) to a reference to T, or is an intersection whose operands are
1144
+ * all T.
1145
+ */
1146
+ private reaches;
1147
+ private readonly defMemo;
1148
+ private readonly slotAtMemo;
1149
+ private readonly layerPathMemo;
1150
+ private mk;
1151
+ private layerPaths;
1152
+ /** U has a layer at q or below it (a shell at q). */
1153
+ private covers;
1154
+ /** U has a layer strictly below q (shells among q's children). */
1155
+ private below;
1156
+ private wrapDef;
1157
+ /** A slot of unit U at Q, shelled when U's layers reach Q. */
1158
+ private applyShell;
1159
+ private shellDef;
1160
+ /**
1161
+ * The union fields of a def of unit U at q over def `x` (a shell, an `as` copy's view, a named
1162
+ * merge's class): x's branches — U's own layers through a branch shell it as U's own (MODEL §9
1163
+ * U4) —, written expressions, size, its structure (STRUCT-N3) and its names.
1164
+ */
1165
+ private unionPart;
1166
+ /** The node of a field of U at Q written as `t` (a prop `prop`, or an element): U's own. */
1167
+ private fieldSlot;
1168
+ private builderDef;
1169
+ /** The def of the node at (U, q) whose written type is `t`; shells are added by the callers. */
1170
+ /**
1171
+ * The def written expression `t` produces at (U, q): q may step
1172
+ * through in-place merge operands (`&i`), which {@link defAt} does not.
1173
+ */
1174
+ defOfExpr(U: TStructDecl, q: string[], t: TStructExpr): TStructDef | undefined;
1175
+ private exprDef;
1176
+ /**
1177
+ * The def of union `t` written at (U, q) (see {@link exprDef}); `structure`: a type path's
1178
+ * structure (its `struct`), a def no node has (keyed apart from the union's own).
1179
+ */
1180
+ private uniDef;
1181
+ /** The def of a type path's structure `s` (see {@link uniDef}): its types' defs, no blocks. */
1182
+ private structureDef;
1183
+ /**
1184
+ * The def of an item of a type path's structure written `e` (see {@link groupExpr}), def `d`:
1185
+ * no position's blocks (a position standing for its group: its shells looked through).
1186
+ */
1187
+ private groupDef;
1188
+ /** Type path union `t` as its positions (its runtime union), without its structure. */
1189
+ private rawUnion;
1190
+ private readonly rawUnions;
1191
+ /** A reference to a declaration: a plain alias is its target. */
1192
+ refDef(d: TStructDecl): TStructDef | undefined;
1193
+ /** The type def of the field node a chain ref names. */
1194
+ private fieldTypeDef;
1195
+ /**
1196
+ * The slots several contributors give a class of its own (named merge, extends child): one ->
1197
+ * that node (a reference), several -> the class's own node over the merge of their types.
1198
+ */
1199
+ private classSlot;
1200
+ /**
1201
+ * A merged field: its own node (`at`: loc, owner) over contributors `cs` (several, in priority
1202
+ * order), its def the merge of their types (`written`: the operands' defs as written, for the
1203
+ * merged object's prop order).
1204
+ */
1205
+ private mergedSlot;
1206
+ /** The def of a declaration: its class (interface, named merge), its written def, a view. */
1207
+ declDef(d: TStructDecl): TStructDef | undefined;
1208
+ private readonly declDefMemo;
1209
+ /** slots being computed (a cycle of `extends` reaching itself: no slot) */
1210
+ private readonly slotsInProgress;
1211
+ /** chain refs being resolved ({@link fieldTypeDef}) */
1212
+ private chainsOpen;
1213
+ /**
1214
+ * The class slots (`U/k/shell`) reached again through a chain ref while being computed — a
1215
+ * field whose type reaches the field itself, `I0.c?: M0.c` with `M0 = I0 & I2` (see
1216
+ * {@link selfTypedFields})
1217
+ */
1218
+ private readonly selfTyped;
1219
+ private guarded;
1220
+ private declDef0;
1221
+ /**
1222
+ * The operand defs of an intersection written in U at q: inline `&` flattened, `| null`
1223
+ * members as their inner type.
1224
+ */
1225
+ private andOps;
1226
+ /**
1227
+ * A reference written as a merge operand. An annotated alias as written
1228
+ * is part of the merge's identity (`P & X` is not `T & X`): a def of its own over its target's
1229
+ * (the same slots), so the merge's root reads P's type-level annotations, then T's.
1230
+ */
1231
+ private operandRefDef;
1232
+ private andDef;
1233
+ private readonly exprIds;
1234
+ private exprCount;
1235
+ /** A stable key of written expressions (their nodes' identity). */
1236
+ private exprsKey;
1237
+ /** The declaration of a unit id ({@link TStructDecl.id}). */
1238
+ declById(id: string): TStructDecl | undefined;
1239
+ /** The def of key `key` (a hidden merge class's unit id `m:<key>` is its def's key). */
1240
+ defByKey(key: string): TStructDef | undefined;
1241
+ /**
1242
+ * The merge of contributor defs written in module `mod`: one def -> that def; a union operand
1243
+ * distributes; else one hidden class per (operand list, module) whose single-contributor
1244
+ * fields are references.
1245
+ */
1246
+ mergeOf(defs0: Array<TStructDef | undefined>, mod: AtscriptDoc | undefined,
1247
+ /** operands without a def (scalars): only their shapes count */
1248
+ extra?: TStructExpr[],
1249
+ /**
1250
+ * the operands as written, when `defs0` is in priority order (an in-place one last): the
1251
+ * merged object's prop order (as 0.1.110 merged them)
1252
+ */
1253
+ written?: Array<TStructDef | undefined>): TStructDef | undefined;
1254
+ /**
1255
+ * A merge's operand list normalized: a merge operand is its operands; a repeated
1256
+ * operand counts at its last place, where it wins (finitely many distinct merges for recursive
1257
+ * ones). A shell def counts as the def it shells: a union and shell defs of it are
1258
+ * ONE operand — distributed they would be a product, another structure —, at its last place, the
1259
+ * highest shell kept: its blocks still layer below. Object / array defs and their shells merge
1260
+ * as a hidden class as before: the same structure, both layered.
1261
+ */
1262
+ private normOps;
1263
+ /**
1264
+ * A merge operand's operands: a merge's; a shell of a merge (structurally the
1265
+ * merge it shells) is the merge's operands, each under the shell — where the shell's unit has
1266
+ * layers, its node; elsewhere the operand's — so a raw write on the inner merge's field stays
1267
+ * local, and the unit's blocks still layer.
1268
+ */
1269
+ private opsOf;
1270
+ /** Operand `o` of the merge shell def `whole` shells (see {@link opsOf}). */
1271
+ private shellPart;
1272
+ /** The written expressions a def stands for (a shell / view: its base's). */
1273
+ private srcOf;
1274
+ private readonly distMemo;
1275
+ /** the modules a distributed merge of which has more than {@link PRODUCT_CAP} branches */
1276
+ private readonly tooComplex;
1277
+ /** Whether a merge written in module `doc` distributes past {@link PRODUCT_CAP} (so far). */
1278
+ tooComplexIn(doc: AtscriptDoc): boolean;
1279
+ /**
1280
+ * The branches of a merge with union operands — one member of each union
1281
+ * operand (its branches; a branch that is a union itself: its own), first operand outermost —
1282
+ * without those whose merge is `never` (unmergeable shapes, disjoint scalars) or holds `null`.
1283
+ */
1284
+ private distribute;
1285
+ /** {@link distribute} into `out`. */
1286
+ private distribute0;
1287
+ /** A union def's branches as merge members: a union branch flattened, `null` / never left out. */
1288
+ private leaves;
1289
+ /**
1290
+ * The item path, in union def `op` (a contributor's), of the member branch `i`
1291
+ * of distributed merge `def` takes from it (a branch item of a merged field layers over the
1292
+ * contributors' nodes at that branch; `op` the merge itself — every contributor has that type
1293
+ * —: its branch `i`); undefined when `op` is not one of its union operands.
1294
+ */
1295
+ branchItem(def: TStructDef, i: number, op: TStructDef | undefined): number[] | undefined;
1296
+ /**
1297
+ * The written type of the member at item path `at` ({@link branchItem}) of union def `op` when
1298
+ * `op` is a type path's positions taken as their structure (MODEL §15 STRUCT-N3): a member no
1299
+ * runtime item is — what stands for its positions (see `groupExpr`); undefined when `op` is
1300
+ * its own structure (`at` is the item path of its node).
1301
+ */
1302
+ structItem(op: TStructDef, at: number[]): TStructExpr | undefined;
1303
+ /** The def at (decl, steps) (`[]` the root's def). */
1304
+ defAt(d: TStructDecl, steps: string[]): TStructDef | undefined;
1305
+ /**
1306
+ * The slot at (decl, steps), steps not empty and not ending with a branch step (`slotAt(T,
1307
+ * [])`: a slot standing for T's root: `root:<id>`; a bare plain alias's root is its target's,
1308
+ * an annotated alias's its own over its target's).
1309
+ */
1310
+ slotAt(d: TStructDecl, steps: string[]): TStructSlot | undefined;
1311
+ /** The written types at the i-th branch of a union position (`(A | B) & C`: `A`, `C`). */
1312
+ private branchEnds;
1313
+ private readonly locMemo;
1314
+ /** The runtime node identity of the position (decl, steps): equal = the same node object. */
1315
+ locAt(d: TStructDecl, steps: string[]): string;
1316
+ private locAt0;
1317
+ /**
1318
+ * Per step of a normalized path of T, what the runtime does to give T its own node there
1319
+ * (the exact path): 0 = the def and the child are T's own (descend); 1 = the def is T's but the
1320
+ * child is a reference (shell the child); 2 = the def is shared (shell the def, then the child).
1321
+ */
1322
+ shellSteps(T: TStructDecl, steps: string[]): Array<0 | 1 | 2>;
1323
+ /** The shape at (decl, steps), `undefined` when no node is there. */
1324
+ shapeAt(d: TStructDecl, steps: string[]): TStructShape | undefined;
1325
+ /**
1326
+ * Whether `null` is a value of a merged slot's node: every written type there is nullable (a
1327
+ * single-contributor slot is its contributor's node, written as is).
1328
+ */
1329
+ nullableSlot(n: TStructSlot): boolean;
1330
+ /** A merged slot whose type is `null`: a contributor written `null`, every other one nullable. */
1331
+ nullSlot(n: TStructSlot): boolean;
1332
+ /** Whether `null` is a value of written type `t` (an intersection: every operand nullable). */
1333
+ nullableExpr(t: TStructExpr): boolean;
1334
+ private nullable;
1335
+ /** The shape of a slot's node (see {@link shapeAt}). */
1336
+ slotShape(n: TStructSlot): TStructShape;
1337
+ private readonly shapeMemo;
1338
+ /** The declarations (a chain: the chain) whose shape is being computed (see {@link shape}). */
1339
+ private readonly shapePath;
1340
+ private shapeCuts;
1341
+ shape(t: TStructExpr): TStructShape;
1342
+ private shape0;
1343
+ /** The shape of written types `xs` merged (one: its shape; see {@link combine}). */
1344
+ private endsShape;
1345
+ /**
1346
+ * The shape of a merge of shapes (`ends`: the written types, for the scalar algebra): objects
1347
+ * merge by name (required if required anywhere), arrays item-wise, scalars intersect (core
1348
+ * algebra: disjoint scalars are `never`), a single union operand of objects distributes.
1349
+ */
1350
+ private combine;
1351
+ /**
1352
+ * The shape of a merge with union operands — the product of their branches, first
1353
+ * operand outermost, the `never` ones dropped: none left is `never`, one is that branch.
1354
+ * (A repeated reference counts once, at its last place, as the merge's operands do.)
1355
+ */
1356
+ private productShape;
1357
+ /**
1358
+ * Merge operands `ss` (written `ends`) with each `mixed` one modelled: `null` as a scalar, a
1359
+ * written union of scalar / array branches (`number | number[]`) as a union shape of its
1360
+ * branches, which a product distributes; undefined when a `mixed` one is
1361
+ * neither (a tuple).
1362
+ */
1363
+ private mixedLeaves;
1364
+ /**
1365
+ * Written type `e` with every branch modelled: `null` a scalar, a union (`number | number[]`)
1366
+ * a union shape of its branches'; undefined when it is neither.
1367
+ */
1368
+ private branchShape;
1369
+ /**
1370
+ * Written type `e` past `| null` and type aliases (an alias met again, a cycle: there), as
1371
+ * structure reads it (a type path's positions: its structure, {@link structExpr}).
1372
+ */
1373
+ private pastAliases;
1374
+ /** A union shape's branches as merge members (see {@link leaves}); `e`: the written union, if known. */
1375
+ private shapeLeaves;
1376
+ /** The scalar values written types `ends` may share (core algebra, pairwise per atom). */
1377
+ private scalarsMeet;
1378
+ /**
1379
+ * The unmergeable shapes at a merged position: a written union of
1380
+ * objects, an array of unions / of arrays, a tuple of objects.
1381
+ */
1382
+ private neverShape;
1383
+ /**
1384
+ * Written type `e` past `| null`, aliases, `as` copies and chain refs (to one written type); a
1385
+ * declaration met again — an alias cycle, reported — stops there.
1386
+ */
1387
+ private stripExpr;
1388
+ /** Whether written type `e` reaches an object (core `containsObject`); each type looked at once. */
1389
+ private holdsObject;
1390
+ /**
1391
+ * The shape of a merge of arrays and tuples (`ends`, an array and a tuple at least) —
1392
+ * a tuple of the items' intersections, an array's element intersecting each item, as the core
1393
+ * algebra builds it: `never` when the tuples' lengths differ, two operands hold objects (core
1394
+ * `tuples of objects`) or an item's intersection is `never`; undefined for other operands.
1395
+ */
1396
+ private tupleShape;
1397
+ private readonly tupleBusy;
1398
+ /** {@link tupleShape} of arrays / tuples `xs` (tuples of `length` items). */
1399
+ private tupleItems;
1400
+ private rootsMemo?;
1401
+ /**
1402
+ * The intersections written in the build (places, named merges, several `extends` parents): the
1403
+ * merge each gives, its module, and where it is written. `own`: a declaration's own class — a
1404
+ * named merge, an `extends` child —, not a hidden class.
1405
+ */
1406
+ mergeRoots(): TMergeRoot[];
1407
+ private graphMemo?;
1408
+ /**
1409
+ * The merges the build writes out, per module: every hidden merge class reachable
1410
+ * from an intersection written in the module (places, named merges, several `extends`
1411
+ * parents) through its multi-contributor fields and union branches. `uniRec`: a merge with a
1412
+ * union operand ON a recursion cycle of merges; `perModule`: hidden merge
1413
+ * classes per module (> {@link MERGE_CAP}: "merge too complex").
1414
+ */
1415
+ mergeGraph(): {
1416
+ uniRec: TStructDef[];
1417
+ perModule: Map<AtscriptDoc, number>;
1418
+ };
1419
+ private mergeGraph0;
1420
+ /**
1421
+ * The db entities (`@db.table`, `@db.view`: the db layer and the `.d.ts`
1422
+ * `__flat` flatten them) whose structure reaches a web of mutually recursive merges — a
1423
+ * recursion cycle through two or more distinct hidden merge classes. A node is the type the
1424
+ * readers' cut keys it by (a shell is the def it shells); its successors are its fields', array
1425
+ * elements' and union branches' types. A self-recursive merge alone is no web.
1426
+ */
1427
+ flatWebs(): TStructDecl[];
1428
+ private flatWebsMemo?;
1429
+ private findFlatWebs;
1430
+ /** The structure compile errors of the build. */
1431
+ /**
1432
+ * The named merges that are an operand of themselves, directly or through a cycle
1433
+ * of named merges (operands: intersection members, inline `&` / `| null` looked through, plain
1434
+ * aliases resolved, a union operand's branches — each is an operand of a branch merge).
1435
+ */
1436
+ selfOperandMerges(): TStructDecl[];
1437
+ private selfOperandMemo?;
1438
+ private findSelfOperandMerges;
1439
+ /**
1440
+ * The positions of `doc`'s declarations an unmergeable merge makes `never` (the
1441
+ * warnings), with why. A declaration reports the positions of its own defs and of the hidden
1442
+ * merge classes it reaches through its own nodes (each walked once, from the first path
1443
+ * reaching it), not those of the declarations it references (they report theirs). A shell def
1444
+ * is the def it shells (a metadata-only block changes no warning). A whole union branch with
1445
+ * nothing in common is
1446
+ * dropped (`X | never` = X): no warning. Each merge walked once (a visited set); the merges of a
1447
+ * module refused as too complex are not (it reports that).
1448
+ */
1449
+ neverWarnings(doc: AtscriptDoc): TStructNever[];
1450
+ /**
1451
+ * A slot without a def (scalars, tuples, arrays of them): `never` in the core algebra's merge of
1452
+ * its written types, as generated code merges them (`js-next.ts`).
1453
+ */
1454
+ private scalarNever;
1455
+ /**
1456
+ * The structure checks' errors of module `doc` (merges, `extends`), on the final model: a
1457
+ * union member of a merge on a recursion cycle, too many merge classes, a type operand of its
1458
+ * own merge, a flattening web, an interface extending a union. The annotate entries' are
1459
+ * {@link entryErrors}.
1460
+ */
1461
+ structuralErrors(doc: AtscriptDoc): TStructError[];
1462
+ /**
1463
+ * The fields several contributors give a class of module `doc` (a named merge, an `extends`
1464
+ * child) whose type reaches the field itself through a chain ref (`I0.c?: M0.c`,
1465
+ * `M0 = I0 & I2`): a type with no finite resolution — a compile error, as a chain reaching
1466
+ * itself is.
1467
+ */
1468
+ private selfTypedFields;
1469
+ /**
1470
+ * The errors of the annotate entries written in module `doc` (its blocks, its `as` copies'),
1471
+ * as {@link complete} reports them: each entry normalized on demand — the type paths and blocks
1472
+ * its landing depends on with it —, not the rest of the model's (a module's diagnostics after
1473
+ * an edit, MODEL §15 SELF-SPLIT across modules).
1474
+ */
1475
+ entryErrors(doc: AtscriptDoc): TStructError[];
1476
+ private readonly extendsMemo;
1477
+ /**
1478
+ * The interfaces of module `doc` extending a union of two or more branches that are not `null`
1479
+ * (a union, or a merge distributing into one): a compile error, it has no props to inherit
1480
+ * (MODEL §15 EXT-U). `extends X | null` is `extends X`.
1481
+ */
1482
+ private extendsUnions;
1483
+ /** Whether declaration `p` is a union of two or more branches that are not `null`. */
1484
+ private unionOfTwo;
1485
+ private rankMemo?;
1486
+ /**
1487
+ * Per module (import depth, module id). Depth is 0 for a module importing no `.as`
1488
+ * module of the build, else 1 + the max depth of its imports, on the SCC-condensed import graph
1489
+ * (a cycle shares one depth); the module id is core `moduleId()`.
1490
+ */
1491
+ ranks(): Map<AtscriptDoc, TStructRank>;
1492
+ /**
1493
+ * The layers on the node at position (d, path), innermost first (a read of the node gets them,
1494
+ * last wins): of every unit whose own node it is — the declaring unit's, then each unit's on
1495
+ * the way out to `d`'s own (its plain target's) at `path`: a unit whose def (own, a shell, an
1496
+ * `as` view; a merge's operands, lower priority first) holds a prefix of the path writes the
1497
+ * node at the rest of it (MODEL §3).
1498
+ */
1499
+ fieldLayers(d: TStructDecl, path: string[]): Layer[];
1500
+ /** {@link fieldLayers} by type path, at a layer epoch */
1501
+ private readonly fieldLayersMemo;
1502
+ private fieldLayers0;
1503
+ /**
1504
+ * The chain ref a node written `e` is the field node of (a reference to an alias of it: a
1505
+ * reference layer over that node); not `final` — a step below the node —: through `X | null`
1506
+ * too, whose item it is.
1507
+ */
1508
+ private chainNode;
1509
+ /** {@link layersAt}, in block order (`as` entries first). */
1510
+ orderedLayersAt(d: TStructDecl, steps: string[]): Layer[];
1511
+ private orderedMemo?;
1512
+ /** The blocks in static order: (import depth, module id, source order); `as` entries first. */
1513
+ orderedBlocks(): TStructBlock[];
1514
+ private blocksOnMemo?;
1515
+ /** The {@link orderedBlocks} whose target is declaration node `node`. */
1516
+ blocksOn(node: SemanticNode): TStructBlock[];
1517
+ }
1518
+
430
1519
  /**
431
1520
  * Interface for a token index system that allows adding tokens and querying the most nested token at a specific position.
432
1521
  */
@@ -452,11 +1541,62 @@ interface ITokensIndex {
452
1541
  before: (line: number, character: number) => Token | undefined;
453
1542
  }
454
1543
 
1544
+ /**
1545
+ * Starts recording the documents read by resolutions (a type, an annotation, a definition of
1546
+ * another document — directly or through other documents): what is derived meanwhile depends
1547
+ * on them only (besides the documents read directly). Recordings may overlap (asynchronous
1548
+ * work interleaving): each records every read while it is active, so none misses one. The
1549
+ * caches are dropped first (a resolution cached earlier would skip the reads it made).
1550
+ * Call `stop()` to end it and get the documents.
1551
+ */
1552
+ declare function recordDocumentReads(): {
1553
+ stop: () => Set<AtscriptDoc>;
1554
+ };
1555
+ /**
1556
+ * The current epoch of the documents: it changes whenever a document's text or imports change
1557
+ * (see `AtscriptDoc.changedSince`).
1558
+ */
1559
+ declare function documentsEpoch(): number;
1560
+ /** A build's import component: the documents connected by imports (both ways, directly or not). */
1561
+ interface TComponent {
1562
+ /** by module id: the same component, whichever document asks first */
1563
+ docs: AtscriptDoc[];
1564
+ /** its structure model (see `AtscriptDoc.componentStructure`), made on first use */
1565
+ model?: StructureModel;
1566
+ }
1567
+ /**
1568
+ * The import component of `doc` (see {@link TComponent}), per documents' epoch: what a
1569
+ * module's generated code is built and loaded with (the blocks that load with its types, MODEL
1570
+ * §7). Internal: the TypeScript plugin's code generation and realm read it.
1571
+ */
1572
+ declare function componentOf(doc: AtscriptDoc): TComponent;
1573
+ /** A field a type path reaches (see `AtscriptDoc.unwindType`): its prop, its type, resolved. */
1574
+ interface TUnwoundField {
1575
+ /** The document `def` resolves in. */
1576
+ doc: AtscriptDoc;
1577
+ /** The prop a path reaches (else the last node met before `def`). */
1578
+ node?: SemanticNode;
1579
+ def: SemanticNode;
1580
+ }
1581
+ /**
1582
+ * What `AtscriptDoc.unwindType` resolves a type path to: one field (or a type), or — through a
1583
+ * union, two or more fields — `fields`, with `def` the union of their types and no `node`.
1584
+ */
1585
+ interface TUnwound extends TUnwoundField {
1586
+ fields?: TUnwoundField[];
1587
+ /**
1588
+ * the walk took branches reaching one field as one, there or on a type path met on the way: a
1589
+ * path through it counts its positions by blocks (POS-1; see `AtscriptDoc.positionsByBlocks`)
1590
+ */
1591
+ collapsed?: true;
1592
+ }
455
1593
  interface TAtscriptDocConfig {
456
1594
  primitives?: Map<string, SemanticPrimitiveNode>;
457
1595
  annotations?: TAnnotationsTree;
458
1596
  unknownAnnotation?: 'allow' | 'warn' | 'error';
459
1597
  plugins?: TAtscriptPlugin[];
1598
+ /** The project root of the config the document is read with (see `TAtscriptConfig`). */
1599
+ rootDir?: string;
460
1600
  }
461
1601
  declare class AtscriptDoc {
462
1602
  readonly id: string;
@@ -467,6 +1607,14 @@ declare class AtscriptDoc {
467
1607
  readonly registry: IdRegistry;
468
1608
  semanticMessages: TMessages;
469
1609
  messages: TMessages;
1610
+ /**
1611
+ * The messages of the last check of this document's imports (`"./b" not found`, no exported
1612
+ * member…): replaced by every check (see `AtscriptRepo.checkImports`), so a file created or
1613
+ * deleted since is reported anew, once.
1614
+ */
1615
+ importMessages: TMessages;
1616
+ /** Replaces {@link importMessages}; the diagnostics are computed again when they changed. */
1617
+ setImportMessages(messages: TMessages): void;
470
1618
  /**
471
1619
  * All the non-blocks tokens, that could be referred
472
1620
  */
@@ -521,7 +1669,7 @@ declare class AtscriptDoc {
521
1669
  */
522
1670
  readonly dependenciesMap: Map<string, AtscriptDoc>;
523
1671
  get primitives(): SemanticPrimitiveNode[];
524
- render(format: TAtscriptRenderFormat): Promise<TOutputWithSource[] | undefined>;
1672
+ render(format: TAtscriptRenderFormat, options?: TAtscriptRenderOptions): Promise<TOutputWithSource[] | undefined>;
525
1673
  private readonly _annotationSpecCache;
526
1674
  resolveAnnotation(name: string): AnnotationSpec | undefined;
527
1675
  /**
@@ -534,9 +1682,25 @@ declare class AtscriptDoc {
534
1682
  */
535
1683
  rekeyImport(oldKey: string, newKey: string): void;
536
1684
  updateDependencies(docs: AtscriptDoc[]): void;
1685
+ /**
1686
+ * The documents reachable from this one through `edge` (imports, or importers), breadth-first
1687
+ * — this one itself only through a cycle.
1688
+ */
1689
+ transitive(edge: 'dependencies' | 'dependants'): Set<AtscriptDoc>;
537
1690
  nodes: SemanticNode[];
538
1691
  private _text;
539
- private _annotateNodesByTarget;
1692
+ /** The {@link documentsEpoch} of this document's last change. */
1693
+ private _changedAt;
1694
+ /** This document's text or imports changed (see {@link changedSince}). */
1695
+ private changed;
1696
+ /**
1697
+ * Whether this document or one it imports (directly or not) changed since `since` (a
1698
+ * {@link documentsEpoch}): what is derived from them at that epoch no longer holds. Decided for
1699
+ * every document at once per epoch, in time linear in the import graph.
1700
+ */
1701
+ changedSince(since: number): boolean;
1702
+ /** The {@link documentsEpoch} of this document's last change. */
1703
+ get changedAtEpoch(): number;
540
1704
  get text(): string;
541
1705
  /** Comment spans of `text`, in source order. */
542
1706
  private commentSpans;
@@ -560,8 +1724,103 @@ declare class AtscriptDoc {
560
1724
  private parseBacktickArgAs;
561
1725
  cleanup(): void;
562
1726
  private registerNodes;
1727
+ /** Records this document as the one declaring prop `prop` (see {@link declaringDoc}). */
1728
+ registerProp(prop: SemanticNode): void;
1729
+ /**
1730
+ * The document declaring `node` (a declaration, a prop; a merged field: its first
1731
+ * contributor's, see `propUnion`), `fallback` when not known.
1732
+ */
1733
+ declaringDoc(node: SemanticNode | undefined, fallback: AtscriptDoc): AtscriptDoc;
563
1734
  resolvedAnnotations: Token[];
564
1735
  annotations: TAnnotationTokens[];
1736
+ /**
1737
+ * The document a type reference was written in, where its name resolves (see
1738
+ * {@link Token.originDoc}): this document for a synthetic reference.
1739
+ */
1740
+ refOrigin(ref: SemanticRefNode): AtscriptDoc;
1741
+ /** {@link unwindType} of a type reference, resolved in the document it was written in. */
1742
+ unwindRef(ref: SemanticRefNode): ReturnType<AtscriptDoc['unwindType']>;
1743
+ /**
1744
+ * The type non-mutating `annotate … as` alias `alias` (declared in this document) stands for:
1745
+ * what its class is built from — its target's definition (with `extends` resolved, see
1746
+ * {@link declDefinition}) — with the alias's entries folded into its props (over the target's
1747
+ * blocks; through a reference, the referenced type inlined, as the alias's class does), and the
1748
+ * type-level annotations of the alias (merged over its target's). The same node every time
1749
+ * (until a document changes): a type of its own, like a hand-written copy (`Alias & Target`
1750
+ * merges their props).
1751
+ */
1752
+ aliasDefinition(alias: SemanticAnnotateNode): SemanticNode | undefined;
1753
+ /**
1754
+ * {@link unwindType} of type name `name` (resolved in this document, no chain) as its
1755
+ * definition (see {@link declDefinition}) when it names a declaration.
1756
+ */
1757
+ declTarget(name: string): {
1758
+ def: SemanticNode;
1759
+ doc: AtscriptDoc;
1760
+ } | undefined;
1761
+ /** {@link declTarget} of a type reference, resolved where it was written. */
1762
+ declRef(ref: SemanticRefNode): {
1763
+ def: SemanticNode;
1764
+ doc: AtscriptDoc;
1765
+ } | undefined;
1766
+ /**
1767
+ * The declaration plain alias `decl` (of this document) stands for: `type A = B` (a reference,
1768
+ * no chain) is B — through aliases of aliases. `undefined` for any other declaration. A block
1769
+ * on a plain alias is a block on what it aliases (see {@link blockTarget}), like the runtime
1770
+ * applies it (`ownPath` follows the alias's `refTo`).
1771
+ */
1772
+ aliasedDeclaration(decl: SemanticNode): {
1773
+ doc: AtscriptDoc;
1774
+ node: SemanticNode;
1775
+ } | undefined;
1776
+ /** The declaration plain alias `decl` (of this document) names directly, if it is one. */
1777
+ private aliasStep;
1778
+ private findAliasStep;
1779
+ /**
1780
+ * The declaration mutating block `node` (of this document) annotates: its target — what it
1781
+ * aliases, for a plain alias (`annotate UA {…}` with `type UA = User` is `annotate User {…}`).
1782
+ */
1783
+ blockTarget(node: SemanticAnnotateNode): {
1784
+ doc: AtscriptDoc;
1785
+ node: SemanticNode;
1786
+ } | undefined;
1787
+ /**
1788
+ * The type-level annotations of declaration `decl` (of this document) as build-time readers
1789
+ * see them: its own, with the top-level annotations of its mutating blocks over them, in order.
1790
+ */
1791
+ declarationAnnotations(decl: SemanticNode): TAnnotationTokens[] | undefined;
1792
+ /**
1793
+ * `base` with the annotations of a mutating block (`overlay`) applied, like the block applies
1794
+ * them to its target's metadata: an `append` annotation adds its values after the existing
1795
+ * ones, any other replaces them.
1796
+ */
1797
+ overlayAnnotations(base: TAnnotationTokens[] | undefined, overlay: TAnnotationTokens[]): TAnnotationTokens[];
1798
+ /**
1799
+ * What declaration `decl` (of this document) is defined as — an alias's, its target's (an
1800
+ * `annotate … as` alias's with its entries): what generated code builds from it.
1801
+ */
1802
+ declDefinition(decl: SemanticNode): {
1803
+ def: SemanticNode;
1804
+ doc: AtscriptDoc;
1805
+ } | undefined;
1806
+ /**
1807
+ * The definition generated code inlines for a type: an interface's own (with `extends`
1808
+ * resolved), an intersection merged, any other as it is.
1809
+ */
1810
+ inlinedDefinition(unwound: {
1811
+ def: SemanticNode;
1812
+ doc: AtscriptDoc;
1813
+ } | undefined): SemanticNode | undefined;
1814
+ /**
1815
+ * The built-in primitive a type reference names, which generated code emits inline — not a
1816
+ * named alias of one (`type MyString = string`), which stays a reference.
1817
+ */
1818
+ inlinedPrimitive(ref: SemanticRefNode, decl?: SemanticNode | undefined): SemanticPrimitiveNode | undefined;
1819
+ /**
1820
+ * {@link getDeclarationOwnerNode} of a type reference's name, resolved in the document it
1821
+ * was written in.
1822
+ */
1823
+ resolveRefOwner(ref: SemanticRefNode): ReturnType<AtscriptDoc['getDeclarationOwnerNode']>;
565
1824
  /**
566
1825
  * Annotation tokens survive merges across refs, chain refs and `extends`
567
1826
  * unchanged, so they are keyed by identity to the document that declared them.
@@ -576,44 +1835,97 @@ declare class AtscriptDoc {
576
1835
  annotationOrigin(annotation: TAnnotationTokens): AtscriptDoc | undefined;
577
1836
  registerAnnotation(annotationTokens: TAnnotationTokens): void;
578
1837
  /**
579
- * Recursively resolves a type reference (and any property chain) to find the final underlying definition.
1838
+ * Resolves a type name and a type path (`T.a.b`) to the type it names.
580
1839
  *
581
- * This method performs a **multi-step** resolution:
582
- * 1. Locates the declaration owner of the type (via `getDeclarationOwnerNode`).
583
- * 2. Follows references, type aliases, or nested property chains:
584
- * - For “Ref” nodes, it uses the identifier to look up the next type.
585
- * - For “Type” nodes, it calls `getDefinition()` to move to the underlying structure.
586
- * - For property chains (`chain`), it navigates nested properties or nested types,
587
- * resolving each level until the final type is reached.
1840
+ * The name resolves through references, aliases and `annotate … as` copies. Each step of the
1841
+ * path keeps a set of positions (one rule for every reader, MODEL §15 CHAIN-1): a union —
1842
+ * written, through an alias, or a distributed merge — fans out into its branches (nested
1843
+ * unions flattened; branches that are not objects have no props), and the step keeps the
1844
+ * positions that have the prop. Then:
1845
+ * - no position: `undefined` (an unknown member);
1846
+ * - one: that field — `node` is the prop, `def` its type, resolved;
1847
+ * - several: `fields` (each such a field) and `def`, the union of their types — for structure,
1848
+ * one per declared field: a field reached with different blocks is one type (MODEL §15
1849
+ * STRUCT-N3) —; no `node`.
588
1850
  *
589
1851
  * @param {string} name - The name of the type or identifier to resolve.
590
- * @param {Array<string | Token>} [chain=[]] - An optional chain of properties or tokens, each of which
591
- * refines the path to the final type (e.g., for `SomeType.prop1.prop2`, `chain` might be `[ "prop1", "prop2" ]`).
592
- * @returns {Object | undefined} An object containing:
593
- * - `doc`: The `AtscriptDoc` where the final definition is located.
594
- * - `node`: The last encountered `SemanticNode` before reaching the final underlying definition (often a `Prop` node).
595
- * - `def`: The final resolved `SemanticNode`.
1852
+ * @param {Array<string | Token>} [chain=[]] - The path below it (`T.a.b`: `["a", "b"]`).
1853
+ * @returns `doc` (where `def` resolves), `node` (the prop a path reaches; else the last node
1854
+ * met before `def`), `def`, and `fields` for several fields; `undefined` when nothing resolves.
596
1855
  *
597
- * If the type cannot be resolved or does not exist, returns `undefined`.
1856
+ * `watchCb` gets each declaration and prop met on the way while the path has one position;
1857
+ * `declaring` is true for those met on the way to a chain's field (its head, the props and
1858
+ * types it goes through: what declares the field — not what the field is).
598
1859
  */
599
- unwindType(name: string, chain?: string[] | Token[], watchCb?: (def: SemanticNode) => void, _tracked?: Set<SemanticNode>): {
600
- doc: AtscriptDoc;
601
- node?: SemanticNode;
602
- def: SemanticNode;
603
- } | undefined;
1860
+ unwindType(name: string, chain?: string[] | Token[], watchCb?: (def: SemanticNode, declaring: boolean) => void, _tracked?: Set<SemanticNode>, _declaring?: boolean): TUnwound | undefined;
1861
+ /**
1862
+ * The props the next step of type path `name.chain` can name (completion): those of every
1863
+ * object position the path reaches (see {@link unwindType}), the first position's first.
1864
+ */
1865
+ pathMembers(name: string, chain?: string[] | Token[]): SemanticNode[];
1866
+ private unwindDeclaration;
1867
+ /**
1868
+ * The type for structure of each of `fields`, the fields type path (decl, chain) names: equal
1869
+ * types are one for structure — the structure model's rule, read here (MODEL §15 STRUCT-N3,
1870
+ * STRUCT-N3-DEF: positions of one type are one, whatever field they come from; see
1871
+ * `StructureModel.typePathTypes`). A field the model has no position for: its def.
1872
+ */
1873
+ private structureTypes;
1874
+ /**
1875
+ * How many positions each of `found`, the positions of a type path (one per field: see {@link
1876
+ * sameField}), is: one field reached with different blocks at or below it is that many (MODEL
1877
+ * §15 POS-1, POS-1a; the blocks loading with the path's head, as generated code counts them:
1878
+ * see {@link componentStructure}). Positions standing for the same declared props (an alias's
1879
+ * folded copy of a prop and the prop) share that field's positions, the first ones taking one
1880
+ * more; a position no field of the model matches is one. Undefined when no field is several.
1881
+ */
1882
+ private positionsByBlocks;
1883
+ /**
1884
+ * The walk of a type path (see {@link unwindType}): its positions, how a position resolves,
1885
+ * and what it reports to `watchCb` (`cb`; `declaring`: on the way to a chain's field).
1886
+ * `collapsed`: branches reaching one field (or one object) were taken as one (blocks may make
1887
+ * it several positions: POS-1).
1888
+ *
1889
+ * (The structure model's `StructureModel.typePathPositions` is the same chain step on the
1890
+ * model's defs — MODEL §15 CHAIN-1, POS-1: the two must stay in step.)
1891
+ */
1892
+ private pathWalk;
604
1893
  getUsageListAt(line: number, character: number): {
605
1894
  uri: string;
606
1895
  range: Token["range"];
607
1896
  token: Token;
608
1897
  }[] | undefined;
609
- evalAnnotationsForNode(givenNode: SemanticNode, own?: TAnnotationTokens[] | undefined): TAnnotationTokens[] | undefined;
1898
+ /**
1899
+ * The type-level annotations of `givenNode` (its own: `own`) over those of what it references.
1900
+ * `blocks`: a declaration reached on the way has its mutating blocks' top-level annotations
1901
+ * too (see {@link declarationAnnotations}) — what a reader showing the type's full set wants
1902
+ * (the LSP hover, `.d.ts` comments); generated code writes the declaration's own (the blocks
1903
+ * apply theirs at runtime).
1904
+ */
1905
+ evalAnnotationsForNode(givenNode: SemanticNode, own?: TAnnotationTokens[] | undefined, blocks?: boolean): TAnnotationTokens[] | undefined;
1906
+ /**
1907
+ * {@link evalAnnotationsForNode} of a node defined as `definition` (e.g. a reference used as
1908
+ * a union / tuple / intersection member or an array element: `A.x | null`), with annotations
1909
+ * `own` of its own.
1910
+ */
1911
+ evalAnnotationsForDefinition(definition: SemanticNode | undefined, own?: TAnnotationTokens[], givenNode?: SemanticNode, blocks?: boolean): TAnnotationTokens[] | undefined;
1912
+ /**
1913
+ * The annotations of the field chain reference `ref` names (its node `node`), with the blocks:
1914
+ * the structure model's layers on that field's node — T's at `a.b`, through a union at its `|i`
1915
+ * path, and every other unit's on the way down to the field's own, MODEL §3 — innermost first,
1916
+ * each applied over the earlier ones; a merged field's node layers over its contributors, each
1917
+ * with its own blocks, later first (MODEL §5), as the runtime reads it. `undefined` when no
1918
+ * block writes there (its own annotations); none for a chain naming several fields (no one
1919
+ * field is its target).
1920
+ */
1921
+ private chainFieldAnnotations;
610
1922
  /**
611
1923
  * The annotations a reference to `node` (`field: Alias`) inherits: its evaluated
612
1924
  * set without the `passedWhenReferred: false` ones. The node's own are filtered
613
1925
  * before the merge, so a dropped one cannot shadow a primitive's intrinsic
614
1926
  * annotation of the same name (`@meta.required 'msg'` on `type N = string.required`).
615
1927
  */
616
- evalReferredAnnotations(node: SemanticNode): TAnnotationTokens[] | undefined;
1928
+ evalReferredAnnotations(node: SemanticNode, blocks?: boolean): TAnnotationTokens[] | undefined;
617
1929
  /**
618
1930
  * Drops annotations whose spec declares `passedWhenReferred: false` — used
619
1931
  * when folding annotations across a ref boundary. Annotations without a
@@ -642,41 +1954,39 @@ declare class AtscriptDoc {
642
1954
  doc: AtscriptDoc;
643
1955
  } | undefined;
644
1956
  /**
645
- * Collects ad-hoc annotations from all `annotate` blocks targeting a given type/interface.
646
- * Returns a map of property path (dot-joined) → annotations array.
647
- * For entries without a chain (root-level), the key is the entry identifier.
1957
+ * The type entry `names` of `annotate` block `block` (of this document) names, from the
1958
+ * structure model: the entry's first normalized path, the types
1959
+ * written at its node — one: that type; several (a merged field): the core algebra's merge of
1960
+ * them —, resolved through a reference. `null`: the model refuses the path; `undefined`: the
1961
+ * model does not know the target.
648
1962
  */
649
- getAnnotateNodesFor(targetName: string): SemanticAnnotateNode[];
1963
+ private entryType;
650
1964
  /**
651
1965
  * Resolves an interface with `extends` by merging parent structures with own props.
652
1966
  * Parents are merged left-to-right, then own props overlay on top (own takes priority).
653
1967
  * Only merges props and their annotations; interface-level annotations are NOT inherited.
654
1968
  *
655
- * Mutating `annotate <Ancestor> { @x field }` blocks contribute to the merged view, so
656
- * inherited fields carry annotate-block metadata in the child's flat prop view. At each
657
- * level of the chain we consult: (1) the immediate parent's own document and (2) the
658
- * `_originDoc` — the document that started the resolution (typically the leaf child).
659
- * Threading `_originDoc` is what lets `annotate <Grandparent> { ... }` blocks living in
660
- * the child's file apply to grandparent-inherited fields, even when the chain crosses
661
- * package boundaries (child → mid → grandparent, all in different .as files).
1969
+ * Mutating `annotate` blocks are not folded in: they are metadata, applied at runtime
1970
+ *.
662
1971
  */
663
1972
  resolveInterfaceExtends(node: SemanticInterfaceNode, _visited?: Set<string>, _originDoc?: AtscriptDoc): SemanticNode | undefined;
1973
+ private resolveExtends;
664
1974
  /**
665
- * Returns a structure equivalent to `struct` with annotate-block contributions
666
- * folded into matching props' annotation arrays. Chained entries
667
- * (e.g. `annotate Parent { account.active }`) are folded recursively into the
668
- * matching inline-object prop's nested structure. Only props/structures along a
669
- * touched path are cloned — siblings are reused by reference, so the base's own
670
- * (shared) nodes are never mutated.
1975
+ * Folds an `annotate … as` alias's entries into a structure's props (see `aliasDefinition`).
1976
+ * Each entry's `parts[0]` names a prop in `struct`; remaining parts target a nested prop —
1977
+ * through a prop typed by a reference, the referenced type inlined: the folded structures are
1978
+ * types of their own (`Alias & Target` merges like a hand-written copy). Returns a new
1979
+ * structure with cloned props/structures along touched paths, or `undefined` when nothing
1980
+ * matched (so callers can reuse the original by reference).
671
1981
  */
672
- private applyAnnotateBlocksToStructure;
1982
+ private foldAnnotationsIntoStructure;
673
1983
  /**
674
- * Recursively folds annotate-block entries into a structure's props. Each entry's
675
- * `parts[0]` names a prop in `struct`; remaining parts target a nested inline-object
676
- * prop. Returns a new structure with cloned props/structures along touched paths, or
677
- * `undefined` when nothing matched (so callers can reuse the original by reference).
1984
+ * Folds the entries (relative to `def`) into definition `def`: an inline object's props (an
1985
+ * intersection: its merge's); the branches of a union and the items of a tuple having them;
1986
+ * through a reference, the referenced type's definition inlined. `undefined` when nothing
1987
+ * matched.
678
1988
  */
679
- private foldAnnotationsIntoStructure;
1989
+ private foldIntoNode;
680
1990
  /**
681
1991
  * Usages of the symbol `token` stands for. `character` (the cursor column)
682
1992
  * narrows a dotted field-path string argument to the segment under the cursor.
@@ -711,6 +2021,8 @@ declare class AtscriptDoc {
711
2021
  private reportUnknownIdentifier;
712
2022
  /** Definition link from `token` to `target`, or to what the token resolves to when omitted. */
713
2023
  private definitionLink;
2024
+ /** Links to the field(s) a type path names: through a union, to each of its fields. */
2025
+ private fieldLinks;
714
2026
  private toRangeTarget;
715
2027
  getToDefinitionAt(line: number, character: number): {
716
2028
  targetUri: string;
@@ -786,18 +2098,174 @@ declare class AtscriptDoc {
786
2098
  renderDiagMessage(m: TMessages[number], addSourceLinses?: boolean, colors?: boolean): string;
787
2099
  getDiagMessages(): TMessages;
788
2100
  /**
789
- * Walks a property chain step-by-step, applying mergeIntersection at each
790
- * level. Mirrors the completion logic in the LSP server so that intersection
791
- * types like `{ a: string } & { b: number }` are handled correctly.
792
- *
793
- * Returns the resolved leaf definition (unwound through refs, parity with
794
- * `unwindType`), or `undefined` when the chain can't be resolved. Callers that
795
- * only need a yes/no resolution check use the truthiness of the result.
2101
+ * The structure model's compile errors of this module (its import component's model, as
2102
+ * generated code reads it): a union member of a merge on a recursion cycle, too many merge
2103
+ * classes, a type operand of its own merge, an annotate entry the model refuses.
2104
+ */
2105
+ private structureMessages;
2106
+ /**
2107
+ * The structure model's compile errors of this module, as generated code is refused for: the
2108
+ * structure checks (merges, `extends`) on this module's model ({@link structure}: a block, any
2109
+ * module's, never changes structure — MODEL §14 N3), and its annotate entries' on its import
2110
+ * component's ({@link componentStructure}: the blocks of a sibling module too — its errors are
2111
+ * this module's whatever module asks), each entry normalized on demand.
2112
+ */
2113
+ structureErrors(): TStructError[];
2114
+ private _structure?;
2115
+ /**
2116
+ * Why a scalar merge of the core algebra (`node`: written types, merged here when an
2117
+ * intersection) has `never` in it — itself, a tuple item, an array element (what
2118
+ * generated code prints as `never`) —; `undefined` when nothing is `never`. A union's branch
2119
+ * with nothing in common is dropped (`X | never` = X), and references are other declarations'.
2120
+ */
2121
+ neverReasonIn(node: SemanticNode | undefined, depth?: number): string | undefined;
2122
+ /**
2123
+ * The structure model of this document and those it imports (directly or not), per documents'
2124
+ * epoch: what diagnostics read (blocks of importers change metadata only).
2125
+ */
2126
+ structure(): StructureModel;
2127
+ /**
2128
+ * The structure model of this document's import component (see {@link componentOf}), per
2129
+ * documents' epoch: every block that loads with this document's types (MODEL §7) — what
2130
+ * generated code is built from (call `complete()` for the final model), and what a type path
2131
+ * through a union counts its positions by (MODEL §15 POS-1: resolved on demand, with the blocks
2132
+ * it depends on). Internal: the TypeScript plugin's code generation reads it.
2133
+ */
2134
+ componentStructure(): StructureModel;
2135
+ /** Whether chain ref `ref` names a field a merge makes `never` (the structure model's shape). */
2136
+ private chainToNever;
2137
+ /**
2138
+ * Warnings for the positions of this document's declarations an unmergeable merge makes
2139
+ * `never` (see `StructureModel.neverWarnings`).
2140
+ */
2141
+ private neverMessages;
2142
+ /**
2143
+ * Errors for references to a type another document does not export, in definitions inlined
2144
+ * from that document (`extends`, an intersection member, `annotate … as …`): the generated
2145
+ * code of this document would have to import it from there. Checks what codegen emits (see
2146
+ * {@link emittedRefs}).
2147
+ */
2148
+ /**
2149
+ * Warnings for the mutating `annotate` blocks of this document whose target another document
2150
+ * declares, when the block is not reachable: the declaring document does not import this one
2151
+ * (directly or not), and a document using the target does not either. A block is part of its
2152
+ * target's definition, built into whatever uses the target in the same build — a build of a
2153
+ * document using it without this one (another entry, the target's package built on its own)
2154
+ * would not have it.
2155
+ */
2156
+ private unreachableBlockMessages;
2157
+ /**
2158
+ * The documents using declaration `decl` (of this document) other than through mutating
2159
+ * `annotate` blocks: this one when another of its declarations references it, and those
2160
+ * importing it that reference it.
2161
+ */
2162
+ documentsUsing(decl: SemanticNode): Set<AtscriptDoc>;
2163
+ /**
2164
+ * Merges an intersection (anything else is returned as it is): scalars by the core algebra,
2165
+ * objects into their structural prop union (see `propUnion`), a union operand distributed. The
2166
+ * same node every time (until a document changes). Generated code reads the structure model
2167
+ *; this is for build-time readers and the scalar merges.
796
2168
  */
797
- private resolveChainWithMerge;
798
- private findPropInGroup;
799
2169
  mergeIntersection(node: SemanticNode): SemanticNode;
2170
+ private mergeGroup;
2171
+ /**
2172
+ * The operands of intersection `group`, a nested intersection (`E & (B & A)`, or a reference
2173
+ * to an intersection alias) contributing its own: they all merge as one (`A & A` is `A`).
2174
+ */
2175
+ private intersectionOperands;
2176
+ /**
2177
+ * The definition `def` of an optional prop intersected with `other` of a required one: `def |
2178
+ * null` when `other` may be `null` (an optional prop passes `null`), else `def`. The same node
2179
+ * for the same `def` (a merge must build the same nodes every time, see `memoMerge`).
2180
+ */
2181
+ private orNullFor;
2182
+ /**
2183
+ * The merge of a merged field's contributors' written types (`optional`: written `?`): an
2184
+ * optional one passes `null` when a required one may be `null` (see {@link orNullFor}), as the
2185
+ * merge of their props does.
2186
+ */
2187
+ mergeFieldTypes(cs: Array<{
2188
+ def: SemanticNode;
2189
+ optional: boolean;
2190
+ }>): SemanticNode;
2191
+ /**
2192
+ * Whether intersection operands `a` and `b` are the same type: the same node (or copies of
2193
+ * it), or references to it (`A & A` is `A`, `(A | B) & (A | B)` is `A | B`, like TypeScript).
2194
+ */
2195
+ private sameOperand;
2196
+ /**
2197
+ * The annotations an intersection operand carries on top of its resolved definition: those
2198
+ * of the aliases and props its reference goes through (`S3` of `type S3 = string` with
2199
+ * `@expect.minLength 3`, `A.x`'s prop annotations), nearest first. None for a definition
2200
+ * written inline.
2201
+ */
2202
+ private operandAnnotations;
2203
+ /**
2204
+ * An intersection member, unwound through a reference, and the document declaring it (`doc`
2205
+ * for one that is not a reference).
2206
+ */
2207
+ private mergeMember;
2208
+ /** The props an intersection member contributes: an interface's include inherited ones. */
2209
+ private memberProps;
800
2210
  mergeDefs(_left: SemanticNode, _right: SemanticNode): [SemanticNode] | [SemanticNode, SemanticNode];
2211
+ /**
2212
+ * {@link mergeDefs} of operands written in documents `leftDoc` / `rightDoc` (where a member
2213
+ * that is not a reference resolves its `extends`).
2214
+ */
2215
+ private mergeOperands;
2216
+ /**
2217
+ * Scalars (primitives and literals, resolved: `left` / `right`) intersected, like TypeScript:
2218
+ * `never` when they have no value in common; a literal narrows a primitive of its type
2219
+ * (`'x' & string` is `'x'`), an extension its base (`string & string.email` is
2220
+ * `string.email`, which carries the base's constraints too). A side is dropped only when it
2221
+ * checks nothing the other does not — no annotations of its own or of the aliases and props
2222
+ * its reference goes through (`@expect.minLength 3 type S3 = string`), no built-in checks
2223
+ * (an extension's, `decimal`'s format) — so the result does not depend on the operand order.
2224
+ * Otherwise (`string.email & string.uuid`, a literal and an extension, `S3 & L4`) both stay,
2225
+ * a runtime intersection checking both.
2226
+ */
2227
+ private mergeScalars;
2228
+ /**
2229
+ * What a definition (resolved) can be, for {@link mayIntersect}: an object, an array (or a
2230
+ * tuple), a scalar (itself) — `undefined` when not known (a union, an intersection of no
2231
+ * objects nor arrays).
2232
+ */
2233
+ private valueShape;
2234
+ /**
2235
+ * Whether a value may match both definitions (resolved): not a scalar and an object or array,
2236
+ * nor scalars having no value in common (see `scalarsDisjoint`), nor an array and an object.
2237
+ * When not known (a union, …), it may.
2238
+ */
2239
+ private mayIntersect;
2240
+ /**
2241
+ * An intersection with a union, distributed (`(A | null) & B` is `(A & B) | (null & B)`): the
2242
+ * union of the intersections of the branches that can match together (`null & B` cannot).
2243
+ * Each stays an intersection, merged by a reader stepping into it — merging
2244
+ * them here would multiply the merges of every union nested in their props. A branch whose
2245
+ * merge is `never` (`2 & (number & 1)`) is no branch. However many branches there are.
2246
+ */
2247
+ private mergeUnions;
2248
+ /** Whether intersection `group` (a distributed branch) merges into `never`. */
2249
+ private mergesToNever;
2250
+ private mergeResolvedDefs;
2251
+ /** The one item of nullable union `def` (`X | null`) that is not `null` / `undefined`. */
2252
+ private nonNullItem;
2253
+ /** Whether a value of definition `def` may hold an object (a structure, an interface). */
2254
+ private containsObject;
2255
+ /**
2256
+ * The structural prop union of two objects (an interface's props include those it inherits),
2257
+ * for build-time readers (generated code reads the structure model): a prop only one
2258
+ * side has is that side's own node (go-to-definition lands in its document); a prop both have
2259
+ * is a new prop — required if one side's is — whose definition is the intersection of theirs
2260
+ * (merged by a reader stepping into it; scalars merged here, by the core algebra), its
2261
+ * annotations the later side's over the earlier's.
2262
+ */
2263
+ private propUnion;
2264
+ /**
2265
+ * Whether definition `def` holds scalars only (primitives, literals, unions and intersections
2266
+ * of them, through references): what {@link propUnion} merges in place.
2267
+ */
2268
+ private scalarsOnly;
801
2269
  /**
802
2270
  * Merges two arrays of annotation tokens, ensuring that annotations from the
803
2271
  * `right` array take precedence over those from the `left` array.
@@ -810,8 +2278,44 @@ declare class AtscriptDoc {
810
2278
  * @param right - An optional array of annotation tokens to merge (higher priority).
811
2279
  * @returns A merged array of annotation tokens, preserving order while preventing duplicates.
812
2280
  */
2281
+ /**
2282
+ * The type-level annotations intersection `group` carries: those of the declarations its
2283
+ * operands name (interfaces, types, `annotate … as` aliases; intersections written in place
2284
+ * expanded), the later member winning (`append` ones concatenated) — with the node each comes
2285
+ * from. Generated code links them live (`.members(…)`) and writes these build-time values under
2286
+ * them (`.inherit(…)`).
2287
+ */
2288
+ intersectionAnnotations(group: SemanticGroup, blocks?: boolean): Array<{
2289
+ node: SemanticNode;
2290
+ an: TAnnotationTokens;
2291
+ }>;
2292
+ /**
2293
+ * What stands for merge operand `ref` when it is a type path naming several positions of one
2294
+ * type for structure — written, or through type aliases —: the structure model's one member
2295
+ * (MODEL §15 STRUCT-N3, STRUCT-N3-META; as generated code layers the merge); else undefined.
2296
+ */
2297
+ private oneTypeOf;
2298
+ /**
2299
+ * The annotations a merge reads through `e`, what stands for a type path's positions (see
2300
+ * {@link oneTypeOf}): a declared field, as a reference to it; a type, as a reference to it.
2301
+ */
2302
+ private oneTypeAnnotations;
2303
+ /**
2304
+ * The references to declarations (interfaces, types, `annotate … as` aliases) whose type-level
2305
+ * annotations intersection `group` carries, lower priority first: its operands naming one
2306
+ * (intersections written in place expanded), looked through a nullable union (`(X | null) & Z`
2307
+ * is `X & Z`; an alias `XN = X | null`: X, then XN's own).
2308
+ */
2309
+ intersectionMemberRefs(group: SemanticGroup): SemanticRefNode[];
813
2310
  mergeNodesAnnotations(left?: TAnnotationTokens[], right?: TAnnotationTokens[]): TAnnotationTokens[];
814
2311
  }
2312
+ /**
2313
+ * {@link unwoundFields}, each declared field once: several positions of a type path may be one
2314
+ * declared field (MODEL §15 POS-1; an `annotate … as` copy's prop is the prop it copies, a merged
2315
+ * field its contributors, see {@link declaredProps}) — what a reader listing the fields shows
2316
+ * (links, hover).
2317
+ */
2318
+ declare function distinctFields(unwound?: TUnwound): TUnwoundField[];
815
2319
 
816
2320
  type TQueryOperator = '=' | '!=' | '>' | '>=' | '<' | '<=' | 'in' | 'not in' | 'matches' | 'exists' | 'not exists';
817
2321
  type TQueryLogicalOperator = 'and' | 'or' | 'not';
@@ -923,6 +2427,12 @@ declare class SemanticGroup extends SemanticNode {
923
2427
  get first(): SemanticNode;
924
2428
  get op(): TPunctuation | undefined;
925
2429
  define(node: SemanticNode): this;
2430
+ /**
2431
+ * Whether `node` (what the parser defines this group with) is a list of members to adopt
2432
+ * rather than a single member: only a plain group is — a structure or a tuple is one
2433
+ * member (unwrapping it would turn `({ a: string })` into its props, `([a, b])` into `a & b`).
2434
+ */
2435
+ protected adoptsMembers(node: SemanticNode): node is SemanticGroup;
926
2436
  wrap(node: SemanticNode, token: Token): this;
927
2437
  unwrap(): SemanticNode[];
928
2438
  protected renderChildren(): string;
@@ -951,6 +2461,11 @@ declare class SemanticStructureNode extends SemanticGroup {
951
2461
 
952
2462
  declare class SemanticTupleNode extends SemanticGroup {
953
2463
  constructor();
2464
+ /**
2465
+ * The item list is a comma-separated (or operator-less) plain group (`[a, b]`, `[(a)]`);
2466
+ * anything else is the single item (`[{ n: string }]`, `[[a, b]]`, `[a | b]`).
2467
+ */
2468
+ protected adoptsMembers(node: SemanticNode): node is SemanticGroup;
954
2469
  }
955
2470
 
956
2471
  declare class SemanticTypeNode extends SemanticNode {
@@ -984,6 +2499,8 @@ declare function isTuple(node?: SemanticNode): node is SemanticTupleNode;
984
2499
  declare function isArray(node?: SemanticNode): node is SemanticArrayNode;
985
2500
  declare function isImport(node?: SemanticNode): node is SemanticImportNode;
986
2501
  declare function isPrimitive(node?: SemanticNode): node is SemanticPrimitiveNode;
2502
+ /** `node` is a primitive whose type is `phantom` (`phantom` or a phantom extension, resolved). */
2503
+ declare function isPhantomPrimitive(node?: SemanticNode): node is SemanticPrimitiveNode;
987
2504
  declare function isAnnotate(node?: SemanticNode): node is SemanticAnnotateNode;
988
2505
 
989
2506
  declare function isQueryLogical(node?: SemanticNode): node is SemanticQueryLogicalNode;
@@ -1174,6 +2691,12 @@ declare class AnnotationSpec {
1174
2691
  protected getDefaultValueForType(name: string, type: TAnnotationArgument['type']): string;
1175
2692
  }
1176
2693
  declare function isAnnotationSpec(a?: TAnnotationsTree | AnnotationSpec): a is AnnotationSpec;
2694
+ /**
2695
+ * Calls `cb` with the full name (`db.table`, `$self` entries as their parent's name) of every
2696
+ * annotation spec in `tree`. A tree reaching itself stops there; a spec several names share is
2697
+ * reported under each.
2698
+ */
2699
+ declare function forEachAnnotationSpec(tree: TAnnotationsTree, cb: (name: string, spec: AnnotationSpec) => void): void;
1177
2700
  declare function resolveAnnotation(name: string, annotationsTree?: TAnnotationsTree): AnnotationSpec | undefined;
1178
2701
  /**
1179
2702
  * Resolved members of a union other than `null` / `undefined`, or `undefined`
@@ -1256,54 +2779,8 @@ declare function clearResolveBareCache(): void;
1256
2779
  */
1257
2780
  declare function resolveBareSpecifier(specifier: string, fromDir: string): Promise<string | undefined>;
1258
2781
 
1259
- /**
1260
- * Descriptor for a single field in the flattened interface map.
1261
- */
1262
- interface TFlatFieldDescriptor {
1263
- /** The resolved type definition node. */
1264
- def: SemanticNode;
1265
- /** The owning document (may differ from root for cross-file refs). */
1266
- doc: AtscriptDoc;
1267
- /** Whether the field is optional. */
1268
- optional: boolean;
1269
- /** The property node (for annotation access). Undefined for the root entry. */
1270
- propNode?: SemanticPropNode;
1271
- /**
1272
- * Whether this is an intermediate (non-leaf) path — a structure, array of structures,
1273
- * or union of only complex types. Intermediate entries should be typed as `never`
1274
- * in the rendered output to prevent meaningless `$eq` comparisons, while still
1275
- * appearing in autocomplete for `$select` and `$exists` checks.
1276
- */
1277
- intermediate?: boolean;
1278
- /** Whether this field has the `@db.json` annotation (stored as JSON string in DB). */
1279
- dbJson?: boolean;
1280
- }
1281
- interface TFlattenOptions {
1282
- /** When true, skip properties annotated with @db.rel.to, @db.rel.from, or @db.rel.via. */
1283
- skipNavProps?: boolean;
1284
- }
1285
- /**
1286
- * Flattens an interface node into a map of dot-notation paths to their type descriptors.
1287
- *
1288
- * This utility exists to improve type-safety for filter expressions and `$select`/`$sort`
1289
- * operations in the DB layer. The generated `__flat` static property on `@db.table`
1290
- * interfaces uses this map to provide autocomplete and compile-time checks for
1291
- * dot-notation query paths.
1292
- *
1293
- * Walks the interface structure (including inherited props from `extends`) and collects
1294
- * all reachable field paths. Nested objects are recursed into, arrays are recursed through
1295
- * their element types, and unions/intersections are recursed through each branch (with
1296
- * colliding paths merged into union groups).
1297
- *
1298
- * Fields annotated with `@db.json` are treated as leaves — their sub-paths are NOT included,
1299
- * because `@db.json` fields are stored as a single JSON column in the database and their
1300
- * sub-paths are not individually queryable.
1301
- *
1302
- * @param doc - The document owning the interface node.
1303
- * @param node - The interface node to flatten.
1304
- * @returns A map of dot-separated paths to their field descriptors.
1305
- */
1306
- declare function flattenInterfaceNode(doc: AtscriptDoc, node: SemanticInterfaceNode, options?: TFlattenOptions): Map<string, TFlatFieldDescriptor>;
2782
+ /** Annotations that make a prop a navigation property (a relation, not a stored field). */
2783
+ declare const NAV_PROP_ANNOTATIONS: readonly ["db.rel.to", "db.rel.from", "db.rel.via"];
1307
2784
  declare function hasNavPropAnnotation(prop: SemanticPropNode): boolean;
1308
2785
  /**
1309
2786
  * Annotations that make an interface a DB entity — a table, or a managed view.
@@ -1314,7 +2791,37 @@ declare function hasNavPropAnnotation(prop: SemanticPropNode): boolean;
1314
2791
  declare const DB_ENTITY_ANNOTATIONS: readonly ["db.table", "db.view", "db.view.for"];
1315
2792
  /** AST side of {@link DB_ENTITY_ANNOTATIONS}: whether a node carries a DB-entity annotation. */
1316
2793
  declare function isDbEntityNode(node: SemanticNode): boolean;
2794
+ /** The fields `unwound` (a type path's resolution, `AtscriptDoc.unwindType`) names: its `fields`, else itself (none for `undefined`). */
2795
+ declare function unwoundFields(unwound?: TUnwound): TUnwoundField[];
2796
+ /**
2797
+ * Whether a type path's resolution (`AtscriptDoc.unwindType`) is phantom: every field it names
2798
+ * is the `phantom` primitive (through a union, several fields: all of them; a mix is a compile
2799
+ * error).
2800
+ */
2801
+ declare function isPhantomPath(unwound?: TUnwound): boolean;
2802
+ /**
2803
+ * Whether `def` (a prop's type) is phantom: the `phantom` primitive, or a reference to it (a
2804
+ * type path: see {@link isPhantomPath}).
2805
+ */
1317
2806
  declare function isPhantomNode(doc: AtscriptDoc, def?: SemanticNode): boolean;
2807
+ /** A definition written at a path of a type (see {@link flatDefinitions}). */
2808
+ interface TFlatDefinition {
2809
+ /** The prop at the path's last step. */
2810
+ prop: SemanticPropNode;
2811
+ /** Its type, resolved through references and declarations (an interface: its structure). */
2812
+ def: SemanticNode;
2813
+ /** The document `def` is read in. */
2814
+ doc: AtscriptDoc;
2815
+ }
2816
+ /**
2817
+ * The written definitions at the dot-separated paths of interface `node` (for the TS types of
2818
+ * its flattened paths; the paths themselves are the runtime flatten's, `flattenAnnotatedType`):
2819
+ * the props a path's last step names in every structure its prefix reaches — through
2820
+ * references, aliases, `extends`, merges (`&`), unions (`| null` too), arrays, tuples and chain
2821
+ * references. Several when branches (or merge members) reach different props at one path.
2822
+ * A path is looked up step by step from its longest prefix looked up already (memoized).
2823
+ */
2824
+ declare function flatDefinitions(doc: AtscriptDoc, node: SemanticInterfaceNode): (path: string) => TFlatDefinition[];
1318
2825
 
1319
2826
  /** A field reference resolved to the property it names. */
1320
2827
  interface TFieldRefTarget {
@@ -1355,9 +2862,23 @@ declare function getQueryScope(argToken: Token, doc: AtscriptDoc): TQueryScope |
1355
2862
  * only up to the segment under the cursor — `'address.city'` with the cursor on
1356
2863
  * `address` resolves `address` — and `range` is that segment's range.
1357
2864
  *
1358
- * Returns `undefined` for any other token, or when the scope or the path does not resolve.
2865
+ * Returns `undefined` for any other token, when the scope or the path does not resolve, and
2866
+ * when the path names several fields through a union (see {@link resolveFieldRefsAt}).
1359
2867
  */
1360
2868
  declare function resolveFieldRefAt(token: Token, doc: AtscriptDoc, character?: number): TFieldRefTarget | undefined;
2869
+ /**
2870
+ * {@link resolveFieldRefAt}, with every field a path through a union names (go-to-definition,
2871
+ * references and hover list each).
2872
+ */
2873
+ declare function resolveFieldRefsAt(token: Token, doc: AtscriptDoc, character?: number): TFieldRefTarget[];
2874
+ /**
2875
+ * The fields a field ref at `token` names ({@link resolveFieldRefsAt}), each once (several
2876
+ * positions may be one declared field, MODEL §15 POS-1), with the name token of its prop when it
2877
+ * has one.
2878
+ */
2879
+ declare function fieldRefTokens(token: Token, doc: AtscriptDoc, character?: number): Array<TFieldRefTarget & {
2880
+ propToken?: Token;
2881
+ }>;
1361
2882
  /**
1362
2883
  * Resolve a query field ref node to a property definition.
1363
2884
  */
@@ -1430,5 +2951,16 @@ declare const BACKTICK_ARG_VOCABULARY: {
1430
2951
  readonly orderDirections: readonly ["asc", "desc"];
1431
2952
  };
1432
2953
 
1433
- export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, PluginManager, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, Token, analyzeQueryCursorContext, annotationExample, build, clearResolveBareCache, createAtscriptPlugin, defineConfig, fileUriToPath, flattenInterfaceNode, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isPhantomNode, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, nonNullishMembers, parseBareSpecifier, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveQueryFieldRef };
1434
- export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TBacktickArgKind, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatFieldDescriptor, TFlattenOptions, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken, TValueCandidate };
2954
+ /**
2955
+ * The id of `doc`'s module, which orders the blocks of modules at one import depth: the name of
2956
+ * the package of its project root (the nearest `package.json` with a `name` above the `rootDir`
2957
+ * of its config) and its path in that package (`name:src/a.as`). Without such a package, a hash
2958
+ * of the project root's path relative to the nearest directory with a `package.json` (or of
2959
+ * nothing, without one) stands for the name (`#1f0c…:src/a.as`, the path relative to the project
2960
+ * root) — the same on every machine. Without an atscript config, the project root is the working
2961
+ * directory the build ran in.
2962
+ */
2963
+ declare function moduleId(doc: AtscriptDoc): string;
2964
+
2965
+ export { $n, AnnotationSpec, AtscriptDoc, AtscriptRepo, BACKTICK_ARG_VOCABULARY, BuildRepo, DB_ENTITY_ANNOTATIONS, DEFAULT_FORMAT, FLATTEN_WEB, MERGE_CAP, MERGE_TOO_COMPLEX, NAV_PROP_ANNOTATIONS, NOTHING_IN_COMMON, PRODUCT_CAP, PluginManager, SELF_OPERAND, SELF_SPLIT, SemanticAnnotateNode, SemanticArrayNode, SemanticConstNode, SemanticExprBinaryNode, SemanticExprCallNode, SemanticExprNode, SemanticExprNumberNode, SemanticExprUnaryNode, SemanticGroup, SemanticImportNode, SemanticInterfaceNode, SemanticNode, SemanticOrderNode, SemanticPrimitiveNode, SemanticPropNode, SemanticQueryComparisonNode, SemanticQueryFieldRefNode, SemanticQueryLogicalNode, SemanticQueryNode, SemanticQueryValueListNode, SemanticQueryValueNode, SemanticRefNode, SemanticStructureNode, SemanticTupleNode, SemanticTypeNode, StructureModel, Token, UNION_IN_RECURSIVE_MERGE, analyzeQueryCursorContext, andExprs, annotationExample, baseSlot, blockDependencies, blockTargetDocuments, build, clearResolveBareCache, componentOf, components, createAtscriptPlugin, defPosition, defineConfig, distinctFields, documentsEpoch, entryParts, fieldRefTokens, fileUriToPath, flatDefinitions, forEachAnnotationSpec, getDeclaredValue, getFieldPathCompletionScope, getFieldsForType, getQueryCompletionScope, getQueryScope, getRelPath, getSiblingAnnotation, getValueCandidates, hasMutatingAnnotates, hasNavPropAnnotation, isAnnotate, isAnnotationSpec, isArray, isAsView, isBacktickArgType, isBareId, isBareSpecifier, isConst, isDbEntityNode, isGroup, isImport, isInterface, isNull, isPhantomNode, isPhantomPath, isPhantomPrimitive, isPrimitive, isProp, isQueryComparison, isQueryFieldRef, isQueryLogical, isRef, isStructure, isTuple, isType, loadConfig, loadTsConfig, moduleId, nonNullishMembers, parseBareSpecifier, pastViews, recordDocumentReads, resolveAnnotation, resolveAtscriptFromPath, resolveBareSpecifier, resolveConfigFile, resolveFieldRefAt, resolveFieldRefsAt, resolveQueryFieldRef, unshell, unwoundFields };
2966
+ export type { SemanticExprItemNode, SemanticQueryExprNode, TAnnotationArgument, TAnnotationSpecConfig, TAnnotationTokens, TAnnotationsTree, TAtscriptConfig, TAtscriptConfigInput, TAtscriptConfigOutput, TAtscriptDocConfig, TAtscriptPlugin, TAtscriptRenderFormat, TAtscriptRenderOptions, TBacktickArgKind, TComponent, TDbConfig, TDbConfigDeclarative, TExprBinaryOperator, TFlatDefinition, TMergeRoot, TMessages, TNodeEntity, TOrderItem, TOutput, TOutputWithSource, TPluginManagers, TPluginOutput, TPrimitiveAnnotationArg, TPrimitiveAnnotationArgs, TPrimitiveAnnotationValue, TPrimitiveBaseConfig, TPrimitiveConfig, TPrimitiveTypeArray, TPrimitiveTypeComplex, TPrimitiveTypeDef, TPrimitiveTypeFinal, TPrimitiveTypeFinalOptional, TPrimitiveTypeObject, TQueryCursorContext, TQueryLogicalOperator, TQueryOperator, TQueryScope, TSemanticToken, TStructBlock, TStructDecl, TStructDef, TStructEntry, TStructError, TStructExpr, TStructLayer, TStructNever, TStructProp, TStructRank, TStructShape, TStructSlot, TUnwound, TUnwoundField, TValueCandidate };