/** * Heritage-walk helpers for type-level annotation inheritance. * * Walks `extends` clauses and type-alias RHS chains breadth-first to collect * inheritable annotation identities that the derived declaration does not * declare locally. * * Lives in `@stripe/formspec-analysis` so the same walk is reusable by IDE surfaces * (hover, diagnostics) without depending on `@stripe/formspec-build`. The walk * itself is decoupled from JSDoc parsing — callers supply an * `extractAnnotations` callback so this module does not bind to build's * `ParseTSDocOptions` / `ExtensionRegistry`. * * @see https://github.com/mike-north/formspec/issues/367 — initial @format inheritance * @see https://github.com/mike-north/formspec/issues/374 — type-alias RHS chains * @see https://github.com/mike-north/formspec/issues/376 — interface-extends-alias mid-chain * @see https://github.com/mike-north/formspec/issues/379 — relocate to @stripe/formspec-analysis */ import * as ts from "typescript"; import type { AnnotationNode } from "@stripe/formspec-core/internals"; export interface HeritageAnnotationOptions { readonly inheritableAnnotationKeys?: ReadonlySet; } /** * Extracts annotation nodes from a declaration. Heritage-walk callers supply * this so the walk is independent of how JSDoc is parsed (e.g., build uses * its TSDoc parser plus an extension registry; another consumer may use a * cached or simplified extractor). * * Implementations may throw; the heritage walk does not catch — callers * decide whether to soft-fail (e.g., skip a hover) or propagate. * * @internal */ export type HeritageAnnotationExtractor = (decl: ts.Declaration, file: string) => readonly AnnotationNode[]; /** * Walks base declarations reachable from a derived declaration and returns * any inheritable type-level annotations that the derived declaration does * not already specify. * * Supports three entry shapes: * - **Class / interface** — walks `extends` clauses (issue #367). * - **Interface extends a type alias** — crosses the alias node to reach * annotations on a deeper object-shaped ancestor (issue #376). * - **Type alias whose body is a type reference** — walks the alias * derivation chain (`type Foo = Bar`), following through alias-of-alias * and alias-of-interface cases (issue #374). * * The walk is breadth-first across reachable bases. A seen-set on * declarations prevents infinite loops on pathological self-referential * chains. Annotations already present on the derived type (matched by * annotation identity) always win — only missing identities are filled in * from the base chain. When multiple bases provide the same identity, the * first found wins (earliest in the `extends` clause list, nearest ancestor * first). * * @param derivedDecl - The class / interface / type alias whose effective * annotations are being computed. * @param existingAnnotations - Annotations already collected from * `derivedDecl` itself. Local non-empty values suppress inheritance for * their annotation identity. * @param checker - TypeScript checker, used to resolve symbols across * alias and import boundaries. * @param extractAnnotations - Callback that returns annotation nodes for a * given declaration. Heritage walkers do not parse JSDoc themselves. * * @internal */ export declare function collectInheritedTypeAnnotations(derivedDecl: ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration, existingAnnotations: readonly AnnotationNode[], checker: ts.TypeChecker, extractAnnotations: HeritageAnnotationExtractor, options?: HeritageAnnotationOptions): readonly AnnotationNode[]; /** * Extracts type-level annotations from a named declaration (class, interface, * or type alias), applying inheritance where applicable (issues #367, #374, * #376). Any inheritable annotation identity absent from the local declaration * is filled in by walking `extends` clauses and type-alias RHS chains via * {@link collectInheritedTypeAnnotations}. * * @internal */ export declare function extractNamedTypeAnnotations(namedDecl: ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration, checker: ts.TypeChecker, file: string, extractAnnotations: HeritageAnnotationExtractor, options?: HeritageAnnotationOptions): readonly AnnotationNode[]; /** * Returns `true` when `namedDecl` carries an inheritable type-level * annotation identity, either locally with inherited schema meaning or * reachable through the alias / heritage chain. Used by build to decide whether a * pass-through alias warrants its own `$defs` entry * (issue #374) or should collapse to the base (issue #364 sibling-keyword * composition). * * @internal */ export declare function hasInheritableTypeAnnotation(namedDecl: ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeAliasDeclaration, checker: ts.TypeChecker, file: string, extractAnnotations: HeritageAnnotationExtractor, options?: HeritageAnnotationOptions): boolean; //# sourceMappingURL=heritage-annotations.d.ts.map