Expand description
Bynk v0.3 compiler library.
Compiles .bynk commons source into TypeScript modules.
Pipeline: lex → parse → resolve → check → emit.
v0.3 introduces multi-file commons and the uses mechanism. A “project”
is a directory containing one or more commons; a commons is either a
single .bynk file or a directory of .bynk files that share a
commons name header. See compile_project.
The single-string entrypoint compile remains for v0–v0.2 fixtures
and any single-file commons that does not declare uses against another
commons.
Modules§
- cli
- The
bynkccommand-line interface definition.
Structs§
- Attributed
Error - v0.24 (ADR 0052): a compile error attributed — where possible — to the
project-relative source file it belongs to, tagged at the collection
point (the phase that produced it knows which file it was processing).
Noneis the project-level bucket: validations spanning files (group/cycle/directory consistency) with no single owning file. - Compile
Error - A compile error.
- Compile
Options - Options for
compile_project. Construct withCompileOptions::singleorCompileOptions::split, then chain.target(…)/.platform(…)/.import_ext(…)to override the bundle/default-platform/.jsdefaults. - Compiled
- A single-file compile that also returns the non-failing warnings produced on
success — what a CLI prints (v0.89, ADR 0117).
compileis the warning-discarding convenience over this. - Compiled
File - One generated TypeScript file.
- Discovered
Case - One discovered
test "<name>"case.locationpoints at the case-name literal (a run failure instead points at the failingassert), giving the editor click-through to the declaration before any run. - Discovered
Suite - v0.67: a discovered test suite — one
test <target>group (unit) ortest integration "<suite>"(integration).name+kindmirror exactly what the NDJSON runner emits atsuite-begin(kind"unit"carries the joined target name;"integration"carries the bare suite name), so the editor reconciles discovery and run documents to the same tree items. - Project
Failure - v0.24: a failed build with its attribution and snapshots intact — what
the CLI renders rich (ariadne source context per file); the plain
compile_project*wrappers flatten it to the pre-v0.24 error list. - Project
Output - Result of compiling a project.
- Project
Paths - v0.113 (DECISION S): the project’s source tree, read from
bynk.toml’s[paths]section. Test-ness is a property of thesuitedeclaration, not of a directory, so the layout is a flatincludelist of trees to compile and anexcludelist of subtrees to skip — not the role-namedsrc/testssplit. Eachincludeentry is a root walked for.bynkfiles; a file’s identity path is relative to theincluderoot that contains it. - Strip
Error - A failure to strip TypeScript to JavaScript. For input produced by the Bynk
emitter this should never occur — the emitter only emits valid, strip-only
TypeScript (ADR 0136) — so a
StripErrorindicates an emitter or toolchain bug rather than user error. - Test
Location - A project-root-relative
path:line:colsource location, structured. Line and col are 1-indexed (thebynk_syntax::span::line_colconvention).
Enums§
- Build
Target - The build target. Determines how cross-context calls and per-context modules are emitted (v0.8). Bundle mode is the default — all contexts emit into one TypeScript bundle and cross-context calls are direct function invocations. Workers mode produces per-context Cloudflare Worker bundles that communicate via Service Bindings.
- Import
Ext - The extension emitted import specifiers use (
import … from "./x.<ext>"). - Platform
- The deploy platform — a selection axis distinct from the
--target {bundle,workers}emit mode (§6.2). It chooses whichbynk-<platform>.tsbinding is linked for thebynksurface. v0.17 shippedcloudflare; v0.18 addsnode, making the axis observable (and giving v0.19’s platform-lock enforcement a second platform to fire against). - Project
Options Error - v0.24 (ADR 0052 rider) / ADR 0100: the project-failure flattening layer.
#521: the implementation is shared with the
bynkdriver in [bynk_driver]; these re-exports keepbynkc’s public API (and its callers) unchanged. Why [try_project_options] could not produce a usableCompileOptions: either the manifest itself is unreadable (ProjectPathsError), or a well-formed manifest names a project tree that can’t be walked ([discovery::DiscoveryError]) — #1081 review. - Project
Paths Error - A problem in
bynk.tomlthattry_read_project_pathssurfaces instead of silently falling back to the conventional layout. - Roots
- Where a project’s
.bynkfiles live. - Schema
Lock bynk-emit’sCompileOptions::schema_registryvalue — whether a build reconcilesbynk.schema.lock, and if so, its current content.- Severity
- Severity classification for a
CompileError. Mirrors LSP severity levels so the LSP server can map diagnostics to the protocol without reinterpreting error categories. Lives in the syntax leaf besideCompileError(it classifies one): shared by the IDE diagnose path (bynk-ide) and theshort/jsonrenderers, without either depending on the other.
Constants§
- NODE_
MAJOR_ FLOOR - Minimum supported Node.js major version for the
nodeplatform binding and for running Bynk’s emitted TypeScript.
Functions§
- compile
- Compile a single Bynk source string to a TypeScript string.
- compile_
project - Compile a Bynk project, keeping error attribution + snapshots on failure
(so the CLI can render project errors with source context, ADR 0052). Use
.map_err(ProjectFailure::flatten)for the flattenedVec<CompileError>shape. - compile_
with_ warnings - The warning-preserving single-file compile behind
compile. SeeCompiled. - print_
errors - Render to stderr with color, used by the CLI.
- print_
errors_ short - v0.38 (ADR 0071): one terse line per diagnostic for tooling consumers
(
bynkc check --format short):path:line:col: <severity>[<category>]: <message>. Line/column are 1-indexed, computed from the byte span against the source. The VS Codebynkcproblem-matcher keys off this exact shape — keep it stable. - print_
project_ errors - Render project-level errors as plain
[category] messagelines — the fallback for errors with no file attribution. Rich, source-context rendering lives in the front-end’s project-failure renderer (v0.24). - print_
project_ failure - v0.24 (ADR 0052 rider) / ADR 0100: the project-failure flattening layer.
#521: the implementation is shared with the
bynkdriver in [bynk_driver]; these re-exports keepbynkc’s public API (and its callers) unchanged. Render a project build failure with per-file ariadne context, exactly as single-file mode had rich rendering. Unattributed (project-level) errors keep the plain form. - print_
project_ failure_ short - v0.24 (ADR 0052 rider) / ADR 0100: the project-failure flattening layer.
#521: the implementation is shared with the
bynkdriver in [bynk_driver]; these re-exports keepbynkc’s public API (and its callers) unchanged. The project-failure analogue ofbynk_render::print_errors_short: each attributed error is positioned against its file’s snapshot; an unattributed (project-level) error falls back to<severity>[<category>]: <message>. - print_
project_ warnings - v0.24 (ADR 0052 rider) / ADR 0100: the project-failure flattening layer.
#521: the implementation is shared with the
bynkdriver in [bynk_driver]; these re-exports keepbynkc’s public API (and its callers) unchanged. v0.89 (ADR 0117): print a successful build’s non-failing warnings, with real per-file ariadne context now that a successful build’ssnapshots(mirroringProjectFailure::snapshots) make that possible. A warning whose source isn’t attributable (or doesn’t fit the snapshot) falls back to the plainwarning[<category>]: <message>form. - project_
failure_ short_ lines - v0.24 (ADR 0052 rider) / ADR 0100: the project-failure flattening layer.
#521: the implementation is shared with the
bynkdriver in [bynk_driver]; these re-exports keepbynkc’s public API (and its callers) unchanged. The string form ofprint_project_failure_short: onepath:line:col: severity[category]: messageline per attributed error (an unattributed project-level error falls back toseverity[category]: message). Backs both the printer above and thebynkc test --format jsoncompile-error document, whosediagnosticsthe VS Codebynkcproblem-matcher re-parses — eachVecentry is exactly one line by that contract, so unlike the other renderers in this file this one deliberately does not grow note/label continuation lines (finding #47): doing so would break a machine consumer that re-parses every entry as a single diagnostic line. - render_
errors - Render a list of compile errors to a string (for tests) using the given filename as the diagnostic source label.
- render_
errors_ plain - Render a list of compile errors to a string with colour disabled and the
given filename as the source label. Unlike
render_errors, the output contains no ANSI escape codes, so it is byte-stable — suitable for the committed diagnostic transcripts undersite/src/diagnostics/. - render_
errors_ short - The string form of
print_errors_short— one…[category]: messageline per error, each newline-terminated. The renderer behind the CLI’s--format short, exposed for testing. - render_
project_ errors - Render a list of compile errors as plain
[category] messagelines (with notes and labels), for test assertion. - strip_
project_ to_ js - Rewrite a compiled
ProjectOutputfrom TypeScript into a JavaScript artefact (the in-browser track’s first-class JS output — ADR 0137). The emitter always produces TypeScript; a JS artefact is that same output with types stripped, which is total because the emitter is strip-only (ADR 0136). - strip_
types - Strip TypeScript types from
source, returning equivalent JavaScript. - try_
read_ project_ paths - Read
bynk.toml’s[paths]section, surfacing a malformed manifest — a parse failure or an unrecognised[paths]key — as an error instead of silently falling back to the conventional layout (the previousread_project_pathstotal form’s behaviour, R3.8 — deleted in favour of this at all 18 of its callers, #1113). - write_
compiled_ file - Write a single
CompiledFileunderdir, map-aware: a.bynk-sourced file gets a sibling.ts.mapand a//# sourceMappingURLtrailer (slice 1, ADR 0103); a file with no map is written verbatim. Shared bywrite_outputandbynkc test’s output loops, so every disk-writing path emits maps uniformly (slice 2 —bynkc test --inspectruns the emitted.tsdirectly and needs the maps on disk). The trailer lives only on the on-disk artefact; the in-memoryfile.typescriptstays trailer-free, so golden comparisons are unaffected. The map name appends.mapto the output file name. - write_
output - Write a
ProjectOutput’s files underdir, creating parent directories as needed. The shared writer behind bothbynkc’scompile/testpaths andbynk dev’s in-process build (slice 7) — so the on-disk result is identical however the build was driven.