code-wasm — run code in any JS host
The real parser + interpreter as a small WASM bridge. One call per program, synchronous results, and third-party modules as plain JS callbacks.
# bundler (Vite, webpack, Rollup…) npm install code-wasm # …or straight from a CDN, no build step import init, { run } from "https://esm.sh/code-wasm";
await init(); console.log(run("let a = 5\nassert a = 5\n")); // "a = 5\n" — final bindings, like `code run` stdout
const modules = { math: { dispatch(particleJson) { const p = JSON.parse(particleJson); if (p._class === "Double") return JSON.stringify({ _class: "DoubleResult", value: p.value * 2 }); throw new Error("unknown handler"); }, }, }; run_with_modules( 'link "math" as m\nemit Double { "value": 21 } to m get r\n' + "assert r.value = 42\n", modules, );
Everything crosses that boundary as JSON strings — a module backed by
a plain function works exactly like one backed by a real
.wasm file. All modules must be provided up front:
link resolves before the program starts.
code