Skip to main content

Crate bynk_wasm

Crate bynk_wasm 

Source
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§

AnalyzeResult
The diagnostics of a single in-memory source — non-bailing analysis, no emission (the editor’s live, on-type diagnostics — slice 5d).
CompileResult
The outcome of compiling one in-memory source.
CompleteResult
The editor’s completion list at a cursor position (#808).
CompletionCandidate
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 as EmittedFile/Diagnostic).
Diagnostic
A diagnostic flattened for the JS side, with a 1-indexed line/column.
EmittedFile
One emitted JavaScript module of the compiled program.
HoverResult
The inferred type at a cursor position in a single in-memory source, or None if 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).
ProjectAnalyzeResult
Every file’s diagnostics, each carrying its project-relative path. A project-level diagnostic (a manifest problem, say) has path: null. A project analysis: every file’s diagnostics, plus warnings about the project itself that aren’t tied to a file (an ignored absolute [paths] entry), for the caller to show.

Enums§

FileKind
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.
FormatResult
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, no tsc. The in-process Bundle subset 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 offset into 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, so files: None throughout).
complete_project
Completion at a byte offset into the project file at path: the single-source candidates, plus the ones that need the rest of the project (names a uses brings 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 offset into source, for the given platform.
hover_project
Hover at a byte offset into the project file at path, 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). None keeps the playground’s browser (its programs run in the page). The VS Code web extension passes "cloudflare", the platform bynk-lsp analyses a project for (Platform::default()), so a unit that consumes bynk.cloudflare doesn’t draw bynk.target.vendor_required in vscode.dev when it checks clean on the desktop. An unrecognised name falls back to browser, the same as None.
project_files
Parse a project’s { path: text } JSON. Malformed JSON is an empty project.