Rúnar Compiler
raw JSON → 0.4.6 verified Fri May 01 auth: no javascript
Rúnar reference compiler (TypeScript to Bitcoin Script) via a 6-pass nanopass pipeline. Version 0.4.6, actively developed. Key differentiators: supports multiple front-end languages (TypeScript, Solidity-like, Move-style, Python) via file extension dispatch; never throws, all errors returned as diagnostics; exports ANF IR and full artifact. Currently in beta.
Common errors
error SyntaxError: Unexpected token 'export' ↓
cause Source code is parsed as JavaScript without .runar.ts extension; export keyword not supported in older Node.js
fix
Rename file to end with .runar.ts, or pass fileName option with correct extension.
error ERR_REQUIRE_ESM ↓
cause Attempting to require() the ESM-only package from a CommonJS module
fix
Use import syntax (ESM) or dynamic import: const compile = (await import('runar-compiler')).compile;
error TypeError: CompileResult is not a constructor ↓
cause Importing CompileResult as a value instead of a type
fix
Use import type { CompileResult } from 'runar-compiler'; it is an interface, not a class.
Warnings
breaking Package is ESM-only; no CommonJS support. require() on the package will throw ERR_REQUIRE_ESM. ↓
fix Use import syntax or dynamic import().
gotcha The fileName option must include the correct extension to select the parser (e.g., .runar.ts, .runar.sol). Wrong extension leads to parse errors. ↓
fix Ensure fileName matches the source language extension, e.g., 'contract.runar.ts' for TypeScript, 'contract.runar.sol' for Solidity-like.
gotcha compile() never throws; all errors are returned as diagnostics in the CompileResult. Silently assuming success === true is dangerous. ↓
fix Always check result.success and inspect result.diagnostics for errors.
Install
npm install runar-compiler yarn add runar-compiler pnpm add runar-compiler Imports
- compile wrong
const compile = require('runar-compiler')correctimport { compile } from 'runar-compiler' - CompileResult wrong
import { CompileResult } from 'runar-compiler'correctimport type { CompileResult } from 'runar-compiler' - CompileOptions
import type { CompileOptions } from 'runar-compiler' - CompilerDiagnostic wrong
const CompilerDiagnostic = require('runar-compiler').CompilerDiagnosticcorrectimport type { CompilerDiagnostic } from 'runar-compiler' - Severity
import type { Severity } from 'runar-compiler'
Quickstart
import { compile } from 'runar-compiler';
const source = `
import { SmartContract, assert, PubKey, Sig, hash160, checkSig } from 'runar-lang';
export class P2PKH extends SmartContract {
readonly pubKeyHash: ByteString;
constructor(pubKeyHash: ByteString) {
super(pubKeyHash);
this.pubKeyHash = pubKeyHash;
}
public unlock(sig: Sig, pubKey: PubKey) {
assert(hash160(pubKey) === this.pubKeyHash);
assert(checkSig(sig, pubKey));
}
}
`;
const result = compile(source, { fileName: 'P2PKH.runar.ts' });
console.log(result.success);
console.log(result.scriptHex);
console.log(result.scriptAsm);