@eco-incorp/sauce-compiler is the SauceScript compiler compiled to WebAssembly: a thin wasm-bindgen marshalling layer over the Rust compiler core, with no compiler logic of its own. The core is I/O-free, so the JS host supplies a synchronous resolver. One package ships two builds of the same wasm and picks between them by exports condition.
The package ships its own TypeScript types, so a consumer does not declare them.
Reproduced from
web/sauce_wasm.d.ts and web/ready.d.ts in @eco-incorp/sauce-compiler 2.3.0. The Node build shares the same declarations. The SDK’s @eco-incorp/sauce/compiler export re-exports compile and its types and adds the compact-argument codec; ready, clearFunctionCache and functionCacheStats are available only from this package.Functions
compile
Compile a SauceScript program to Sauce bytecode. The option and result shapes are CompileOptions and CompileResult below. Validation, compile and resolve failures throw a JS Error. Source diagnostics include the rule that was broken, the source line and a caret under the span; option and resolver errors may have no span. A host callback’s thrown message is preserved in the chain.
ready
Get the compiler, initialising the wasm if this environment needs it. The same call in Node and in the browser: the CommonJS build is already initialised by the time it resolves, and the browser build is initialised by it. Safe to call as often as you like: initialisation happens at most once, concurrent callers share the one attempt, and a failed attempt is not cached, so a retry is a real retry. The first successful source is the one used; a later one is ignored, because wasm initialisation is global to the module. At run time use Node or a bundler that supports package exports subpaths; TypeScript’s moduleResolution controls type lookup only.
init (default export) and initSync
The ESM build’s initializers. init makes a request when given a RequestInfo or URL and otherwise calls WebAssembly.instantiate directly; initSync instantiates bytes or a precompiled WebAssembly.Module. Passing the input directly rather than wrapped in an object is deprecated.
clearFunctionCache
Empty this WASM instance’s per-function lowering cache and reset its counters. The store persists across compile calls, is bounded and empties automatically when full. Changed source or consulted bindings invalidate reuse automatically, so clearing is for releasing cached lowerings or measuring a cold compile; it does not clear a file-content cache maintained by your resolver.
functionCacheStats
Read the per-function IR-lowering cache’s counters, { hits, misses, inserts }, for measuring warm reuse across a route sweep. Counters are cumulative until clearFunctionCache() resets them.
Types
SauceTarget
The engine a program is compiled for.
ResolveModule
Fetch a module’s bytes. A Node Buffer is a Uint8Array. Returning undefined or null means nothing at this path, which is the signal the per-target arm probe relies on to fall back to a module’s neutral arm (token.ts after token.evm.ts misses). A throw means the path names something that could not be read: it propagates rather than falling back, so a miss must not throw. Any other return type is a resolve error. A .json path is asked for either as a contract ABI or as a document the source imports as data (with { type: "json" }); both are bytes here, so serve any .json the program names.
ResolvePackage
Map a bare specifier ("@sauce/token") to a path resolve accepts. undefined or null declines, falling back to using the specifier as a path; a throw means the package is not installed. importer is the resolved path of the importing module.
CompileOptions
CompileResult
bytecode is the reusable program without the caller’s argument values. isaRevision is the instruction-set compatibility identifier, independent of the npm version. entryEncoding is the encoding the program expects for entry arguments; entrySchema is present only with compact encoding and is the exact schema to pass to the compact codec. manifest is the SVM account manifest; undefined on the EVM, which has no such concept.
AccountRole
What a caller’s account must satisfy at a declared slot: the four values of Solana’s own AccountRole, so an SDK maps one onto an AccountMeta directly. It is the program author’s assertion, with the trust model of an ABI declaration: the compiler cannot know what a program invoked by CPI does with the accounts it is handed, so nothing here is inferred. A bare Account is "readonly".
AccountEntry
One entry in the attach contract. A slot is an Account parameter of main, read by the engine at index, carrying the source parameter’s name and the role it requires of whatever account is attached there. remaining is not an account but a position: it marks where the caller’s own variable-length accounts begin, and from is the index the first of them lands at. It appears only when the program reads that tail (svm.remainingAccount or svm.remainingAccounts), and it is always last.
AccountManifest
The index-to-account contract a caller attaches accounts against. SVM only.
FnCacheStats
The per-function IR-lowering cache’s counters, from functionCacheStats().
WasmSource and SauceCompiler (from /ready)
What compile needs before it can run, where that differs by environment. Omit it and the browser build resolves the wasm next to its own module, which is what a bundler rewrites to an asset URL. Pass bytes or a URL when that does not apply. The Node build ignores it. Deliberately spelled without DOM types so the Node build typechecks for a consumer with no DOM lib; { href: string } is how a URL is accepted structurally. A Response still works at run time in a browser; widen it locally if you need one: ready(response as unknown as WasmSource).
InitOutput
The raw wasm-bindgen instance returned by init and initSync. Consumers use compile, clearFunctionCache and functionCacheStats from the module instead of the fields on this object.
Complete example in Node
Createsrc/main.ts with this program:
main.ts
@eco-incorp/sauce-compiler@2.3.0, then run the following with Node 24 or later. If you typecheck with tsc, install typescript and @types/node as development dependencies.
compile.ts
