oxbox
v0.1.0
Published
OXC parser and transformer packaged as a portable wasm module
Readme
oxbox
Usage
Same API as oxc-transform and oxc-parser (parse, parseSync), backed by an embedded wasm binary built from oxc sources (no native binaries, no runtime dependencies):
import { parseSync, transformSync } from "oxbox";
const { code } = transformSync("input.ts", "const a: number = 1");
const { program } = parseSync("input.ts", "const a: number = 1");The wasm is embedded in the JS bundle (deflate-raw + base93) and decoded, decompressed and instantiated lazily on first call. Use await init() to warm it up ahead of time (required before calling sync APIs in browsers).
Async APIs run on worker threads when SharedArrayBuffer is available (in browsers the page must be cross-origin isolated); otherwise oxbox runs single-threaded and async APIs run on the calling thread.
Benchmarks
Compared with the official oxc-transform / oxc-parser wasm and native (napi) bindings.
Install size
oxbox ships transform and parser as a single wasm; oxc ships them as two packages (and the wasm bindings share the emnapi / napi-rs runtime).
Performance
Development
- Clone this repository
- Install latest LTS version of Node.js
- Enable Corepack using
corepack enable - Install dependencies using
pnpm install - Run the browser playground using
pnpm dev - Run tests using
pnpm vitest - Run benchmarks against
oxc-transform/oxc-parser(napi and wasm) usingpnpm bench [filter](unfiltered runs savebench/results.json;pnpm bench:reportre-rendersbench/results.svgfrom it) and install sizes usingpnpm bench:size(rendersbench/size.svg) - Rebuild the wasm from oxc sources (committed as
src/_vendor/wasm.ts) usingpnpm vendor(requires Rust andrustup target add wasm32-wasip1-threads)
License
Published under the MIT license 💛.
Bundles oxc (MIT, VoidZero Inc. & Contributors). The N-API / WASI host (src/napi.ts) is derived from emnapi (MIT, Toyobayashi) and the napi-rs wasm runtime (MIT, LongYinan). See LICENSE for full license texts.
