typescript-alias-registry.ts

Alias-registry pre-pass — builds the identity-keyed AliasRegistry the TypeJson builder consults at nameless positions (see typescript-extract-type-json.ts for the registry types and the consult policy).

buildAliasRegistry walks the export tables of the emitted modules and registers each exported, non-@nodocs, non-generic type alias whose alias the checker dropped (isAliasLostType) and whose resolved type passes the safety gate (containsAnonymousComponent). It runs before declaration extraction — checker caches make the duplicate getTypeAtLocation cheap — and the registry is query-scoped: built per analysis cycle, discarded after, so sessions never pin stale-program type objects.

Deliberately an exported, independently callable function rather than a private step of analyzeCore: the fixture harnesses don't route through analyzeCore, so they build and thread the registry themselves — without that seam their committed baselines would silently lock the no-registry path.

@internal Used by analyzeCore and the test harnesses — not part of the public barrel export.

view source

Declarations
#

2 declarations

AliasRegistrySource
#

typescript-alias-registry.ts view source

AliasRegistrySource import type {AliasRegistrySource} from 'svelte-docinfo/typescript-alias-registry.js';

One emitted module offered to the pre-pass: the program's source file (for a Svelte module, the svelte2tsx *virtual* — program.getSourceFile returns undefined for a raw .svelte id, so the caller resolves through virtualPath) and its ModuleJson.path, which becomes AliasRegistryEntry.module and ships verbatim on recovered reference nodes — analyzeCore derives it with the same extractPath call that mints ModuleJson.path, and normalizeModulePathsInTypes deliberately skips the module key, so a caller passing anything else (an absolute path, a virtual-suffixed one) would publish it unrewritten.

sourceFile

type SourceFile

modulePath

type string

buildAliasRegistry
#

typescript-alias-registry.ts view source

(sources: readonly AliasRegistrySource[], checker: TypeChecker): AliasRegistry import {buildAliasRegistry} from 'svelte-docinfo/typescript-alias-registry.js';

Build the alias registry for one analysis cycle.

Registration walks each source's export table and registers an export when it:

  • survives the svelte2tsx filters on virtuals (default and generated $$/__sveltets_ names skipped)
  • is declared in the file (star-projected bindings skipped, mirroring analyzeExports's locality rule)
  • resolves — through local export clauses, @nodocs-free ones only — to a TypeAliasDeclaration in the *same* file (a re-export of another module's alias registers from that module when it's emitted, and never when it's gated — gated aliases have no doc page for a reference to land on; merged value+type symbols select the type-space node via selectDeclarationNode)
  • is non-generic (instantiations are per-argument type objects — the declared type of a generic alias never matches a use site)
  • carries no @nodocs on either declaration of a merged pair
  • is alias-lost (isAliasLostType) and passes the safety gate

Ambiguity — two aliases over one lost type (type A = z.infer<typeof S> beside type B of the same, z.infer vs z.output, cross-module, type A = B over a lost B) resolves to a global single winner via compareStrings on name then module, so one type documents under one name everywhere (coherent cross-linking, deterministic regardless of iteration order). The member-set side index is derived from the settled winners, so the two indexes can't disagree.

sources

the emitted modules (Svelte modules via their virtuals — see AliasRegistrySource)

type readonly AliasRegistrySource[]

checker

the program's type checker (registry entries are valid exactly as long as this checker's types are)

type TypeChecker

returns

AliasRegistry

Depends on
#

Imported by
#