Skip to content

@ic-reactor/parser

@ic-reactor/parser is the low-level WASM parser behind local Candid compilation in IC Reactor. It converts raw .did source into JavaScript IDL factories or TypeScript declaration strings.

  • Fast and local: Compile Candid without a remote didjs canister.
  • Tooling friendly: Used by @ic-reactor/codegen to turn .did files into generated declarations.
  • Runtime friendly: Can be loaded by @ic-reactor/candid for local CandidAdapter compilation.

Candid to JS

Returns JS source that exports idlFactory and init.

Candid to TS

Returns TypeScript declaration source for the same interface.

WASM Runtime

Implemented in Rust and compiled to WebAssembly.

Terminal window
pnpm add @ic-reactor/parser
import { didToJs, didToTs } from "@ic-reactor/parser"
const candid = `service : {
greet : (text) -> (text) query;
}`
const jsSource = didToJs(candid)
const tsSource = didToTs(candid)
import { CandidAdapter } from "@ic-reactor/candid"
import { ClientManager } from "@ic-reactor/core"
const adapter = new CandidAdapter({
clientManager: new ClientManager(),
})
await adapter.loadParser()
const jsSource = adapter.compileLocal(
"service : { greet : () -> (text) query }"
)