Expand description
The Bynk compiler as a wasm module for the in-browser REPL/playground (the in-browser track, slice 3 — ADR 0139).
One entry — bynk_compile (wasm) / compile (native) — takes an in-memory
Bynk source and returns a runnable JavaScript module graph plus diagnostics,
with no filesystem and no tsc:
source ─▶ bynk_emit::compile_in_memory (Bundle / Browser) ─▶ ProjectOutput (TS)
─▶ bynk_strip::strip_project_to_js ─▶ ProjectOutput (JS)
─▶ { files: [{ path, kind, contents }], diagnostics }The pipeline reuses the on-disk path wholesale (first-party injection, the
per-platform binding, the strip-only emitter), so the returned graph is the
complete set the browser links: the user module, the runtime modules it
reaches (__bynk_runtime/<module>.js, ADR 0615), the bynk-browser.js
binding, and compose.js. The crate compiles to wasm32
(the cdylib); the same logic is exercised natively (the rlib) by the
slice-3 tests, with the browser harness deferred to the REPL shell (slice 4).
Structs§
- Analyze
Result - The diagnostics of a single in-memory source — non-bailing analysis, no emission (the editor’s live, on-type diagnostics — slice 5d).
- Compile
Result - The outcome of compiling one in-memory source.
- Complete
Result - The editor’s completion list at a cursor position (#808).
- Completion
Candidate - One completion candidate, serialised for the JS side — a shadow of
bynk_ide::completion::Completion/CompletionKind(that crate stays serde-free; this is the wire DTO, same pattern asEmittedFile/Diagnostic). - Diagnostic
- A diagnostic flattened for the JS side, with a 1-indexed line/column.
- Emitted
File - One emitted JavaScript module of the compiled program.
- Hover
Result - The inferred type at a cursor position in a single in-memory source, or
Noneif the expression at that position failed to type — per ADR 0094, a well-typed function still contributes types even when a different function in the same file has an error, so this isn’t blanked by every mid-edit error, only by one at the position itself (or upstream of it, an unresolved name). The editor’s hover tooltip (#397). - Project
Analyze Result - Every file’s diagnostics, each carrying its project-relative
path. A project-level diagnostic (a manifest problem, say) haspath: null. A project analysis: every file’s diagnostics, pluswarningsabout the project itself that aren’t tied to a file (an ignored absolute[paths]entry), for the caller to show.
Enums§
- File
Kind - Where an emitted module comes from, so a consumer can show only the code that corresponds to what the user wrote (#2425). The graph itself is unchanged: the sandbox still links every file.
- Format
Result - The result of formatting a single in-memory source (#2431).
Functions§
- analyze
- Analyse a source for diagnostics only (no compile/emit), for the given platform.
- analyze_
project - analyze_
to_ json - Analyse to a JSON string —
{ diagnostics: [{ from, to, line, col, severity, category, message }] }. - compile
- Compile a single in-memory Bynk source to a JavaScript module graph for the
given platform (the playground passes
Platform::Browser). Pure: no filesystem, notsc. The in-processBundlesubset only; programs that reach Workers/Cloudflare-only shapes are reported as diagnostics (slice-2 platform lock), never silently mis-compiled. - compile_
to_ json - Compile to a JSON string — the wasm boundary representation of
CompileResult. - complete
- Completion at a byte
offsetinto an in-memory Bynk source, for the given platform (capability methods, types, keywords, in-scope locals, and value-receiver members — #808, the other half of #397 hover shipped). Single buffer, single call — no project files, no multi-doc overlay/caching (the wasm boundary has none of those, sofiles: Nonethroughout). - complete_
project - Completion at a byte
offsetinto the project file atpath: the single-source candidates, plus the ones that need the rest of the project (names ausesbrings in, another unit’s capabilities). - complete_
to_ json - Complete to a JSON string —
{ items: [{ label, kind, detail, insert_text }] }. - format
- Format a source to the house style with default options. A source that does
not parse yields the first error as
line:col: message, never a panic. - format_
to_ json - Format to a JSON string —
{"ok":true,"formatted":…}or{"ok":false,"error":…}. - hover
- Hover for a byte
offsetintosource, for the given platform. - hover_
project - Hover at a byte
offsetinto the project file atpath, typed in the context of the whole project. - hover_
to_ json - Hover to a JSON string —
{ ty: string | null }. - platform_
named - The platform an editor entry point analyses for, from the optional name the JS
side passes (#2102).
Nonekeeps the playground’sbrowser(its programs run in the page). The VS Code web extension passes"cloudflare", the platformbynk-lspanalyses a project for (Platform::default()), so a unit that consumesbynk.cloudflaredoesn’t drawbynk.target.vendor_requiredin vscode.dev when it checks clean on the desktop. An unrecognised name falls back tobrowser, the same asNone. - project_
files - Parse a project’s
{ path: text }JSON. Malformed JSON is an empty project.