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/&&.

Modules§

contracts
bynk-contracts.json generation per Worker (v0.177, #643).
secrets
bynk-secrets.json generation per Worker (v0.172, ADR 0195).
wrangler
wrangler.toml generation per Worker (v0.8 §4.4 / §4.5).

Functions§

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.
emit_tsconfig_with_source_maps
The bynkc test --coverage variant (#854): the same config with sourceMap enabled, so tsc emits the .js.maps the coverage remap consumes (hop 1, .js → emitted .ts). Kept coverage-only rather than folded into the default so a normal bynkc test / deployment tsc run ships no .js.maps. The runner overwrites the default out/tsconfig.json with this before tsc.