Skip to main content

Module emitter

Module emitter 

Source
Expand description

TypeScript emission (spec §7, v0.1 §6, v0.2 §6).

Walks the typed AST and writes a single TypeScript module.

v0.2 lowering rules:

  • Refined-base types: branded type alias + constructor object with of/unsafe (+ any user-declared methods).
  • Record types: TypeScript interface + namespace object with methods.
  • Sum types: discriminated-union type alias + namespace object with variant constructors and methods.
  • Field access lowers to property access.
  • Method calls lower to Type.method(receiver, args) (UFCS).
  • match lowers to a switch on .tag; in tail position it inlines, otherwise it becomes an IIFE.
  • is lowers to a tag check; bindings become const declarations on the truthy side of if/&&.

Re-exports§

pub use workers::emit_worker_compose;
pub use workers_entry::emit_worker_entry;
pub use wrangler::emit_wrangler_toml;

Modules§

serialisation
Per-type serialise / deserialise helper generation for workers mode (v0.8 §3.4 / §5.2).
workers
Per-Worker composition root generation (v0.8 §4.5, v0.9 §5.1).
workers_entry
Per-Worker index.ts generation (v0.8 §4.3, v0.9 §5.1).
wrangler
wrangler.toml generation per Worker (v0.8 §4.4 / §4.5).

Functions§

agent_factory_name
The exported agent-construction factory name for an agent class.
emit
Emit TypeScript source for the typed commons (single-file mode).
emit_project
Emit TypeScript source for a single file inside a multi-file project, including cross-file and cross-commons imports computed from EmitProjectCtx. Emit one unit’s TypeScript, plus its source map (slice 1, ADR 0103).
emit_runtime_module
Emit the contents of out/runtime.ts. This module ships with every project so the per-context / per-test emissions can import { Ok, Err, Some, None, ... } from a single source. It includes:
emit_tsconfig
Emit the contents of out/tsconfig.json. The CLI uses tsc -p against this when running bynkc test; users can also drive tsc against it directly to produce JS for deployment.
runtime_import_for
Compute the runtime import specifier for a module at from_source. For a file at commerce/payment.ts the runtime sits two levels up, so this returns ../runtime.js; for a top-level file it returns ./runtime.js.