Expand description
Rust AST → TypeScript emitter for ontogen’s long-tail type bindings.
This crate is the build-time replacement for the OF-014 spike’s specta
side-car. Given a set of root types, a pool of candidate type definitions
(syn::Item keyed by canonical TypePath), and an EmitConfig, it
produces TypeScript source covering the supported subset documented in
OF-015:
- Named structs over primitive / container / smart-pointer / reference field types
- C-style enums (and tagged enums where the tag is implicit from variant idents)
Vec<T>,Option<T>,HashMap<K, V>,BTreeMap<K, V>- Primitives:
bool, all integer types,f32/f64,String,&str - Smart-pointer wrappers (
Box,Rc,Arc,Cow,Pin) peeled silently - External types via
EmitConfig::external_types #[serde(flatten)]on a struct field (or an enum struct-variant field), emitted as a TS intersection:StepMeta & { program: string }- The full rename family, each on the axis serde gives it:
rename_all(a container’s members),rename_all_fields(an enum’s struct-variant fields),rename_allon a variant (that variant’s fields),rename
See docs/tasks/OF-015-productionize-typescript-generation.md for the
full design pass.
§PR series state (PR 4 of 8)
PR 1-3 landed the crate scaffold, per-type emission, serde rename
family, type-pool walker, use-resolution, external-types table, and
topological ordering. PR 4 wires them together: the top-level emit
function now composes collection → name resolution → collision
detection → topological ordering → per-type emission → error
aggregation, all in one pass. The #[ts_opaque(target = "...")] and
#[ts_name = "..."] proc-macro attrs (shipped in ontogen-macros)
are read here to short-circuit emission for opaque types and override
TS names. External-types lookup is wired into emit_type’s
fall-through so types like chrono::DateTime resolve to string
per the shipped defaults.
PR 5 wires ontogen itself to call emit instead of the side-car
emitter.
Structs§
- Emit
Config - Per-build configuration for an
crate::emitcall. - Module
Imports - Per-module
usetables for a scanned source tree, keyed by the module’s canonical path segments (empty = crate root). The keys mirror the type pool’s key prefixes, so a referencing item’s module — the pool key with its terminal dropped — looks up directly. - Type
Path - Fully-qualified canonical path to a type in the user’s crate (or an external crate).
Enums§
- BigInt
Behavior - How
u64/i64/usize/isizeare rendered in TypeScript. - Emit
Error - Every way emission can fail.
- Quote
Style - How TypeScript string literals are quoted in emitted source.
- Rename
All - Serde’s eight
rename_allmodes. - Resolution
- Outcome of resolving a type reference against the pool.
- Scan
Error - Failure modes for
scan_src_dir. - Type
Path Error - Construction error for
TypePath.
Constants§
- LOCAL_
CRATE_ ROOT - First key segment for types scanned from the consuming crate’s own
src/.
Functions§
- emit
- Emit TypeScript source for
rootsand everything they transitively reach intype_pool, honoringconfig. - emit_
with_ imports - Like
emit, but resolves bare single-segment references throughimports— each referencing module’susetable — so a type pulled in viause(possibly through several re-export hops) links to the right pool key even when several modules define same-terminal types. - render_
type - Render one Rust type as TypeScript, with no type pool and no surrounding declaration.
- render_
type_ str - Parse
rust_tyas a Rust type expression and render it viarender_type. - resolve_
reference - Resolve a type reference —
segmentsare the reference’s path idents with generic args already stripped (["BackupManifest"],["crate","models","Workout"]) — written inmodule(the referencing item’s canonical module path, i.e. its pool key minus the terminal). - scan_
crate_ root_ with_ imports - Scan a
src/directory as the crate namedcrate_root, so every pool key and every module-imports key begins with that segment. - scan_
src_ dir - Scan a
src/directory and collect every module-level struct, enum, and type-alias into a pool keyed by canonicalTypePath, rooted atLOCAL_CRATE_ROOT. - scan_
src_ dir_ with_ imports - Scan a
src/directory, returning both the type pool and the per-moduleModuleImportstables built from each module’susedeclarations.