XCompile

raw JSON →
0.6.1 verified Fri May 01 auth: no javascript

XCompile is a robust tokenizer, parser, and transpiler for translating between programming languages. Current stable version is 0.6.1, released in 2025 with improved Clang parsing, XIR JSON target, and TypeScript emitter enhancements. It uses a custom intermediate representation (XIR) and supports translating Clang AST JSON into TypeScript. Key differentiators include native Clang bindings, ESM-only support (Node >= 20), and built-in CLI. Release cadence is irregular with major features added incrementally.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Package is ESM-only; using CommonJS require()
fix
Use import syntax or set type: module in package.json
error TypeError: xcompile is not a function
cause Default import used when only named export exists
fix
Use named import: import { xcompile } from 'xcompile'
error Error: Cannot find module 'xcompile'
cause Package not installed or incorrect import path
fix
Run npm install xcompile and use correct import path 'xcompile'
error TypeError: clang.parse is not a function
cause API change in v0.5.0: clang.parse renamed to clang.parseRaw
fix
Use clang.parseRaw or upgrade to new clang.parse API
breaking Renamed clang.parse to clang.parseRaw and added new clang.parse in v0.5.0
fix Use clang.parseRaw for old behavior or update to new clang.parse API.
breaking Removed custom tokenizer and parser in v0.4.0; replaced with XIR and Clang AST JSON
fix Existing tokenizer/parser APIs are removed; use new XIR-based pipeline.
breaking Changed snake_case to camelCase in v0.3.0
fix Update API calls to use camelCase property names.
deprecated Options like config.compress are deprecated since v0.3.0; removed in v0.4.0
fix Avoid using deprecated options; check current API documentation.
gotcha ESM-only package; require() fails on Node < 20
fix Use ES modules or upgrade Node to >=20.
gotcha TypeScript types shipped but may not be stable across minor versions
fix Pin to a specific minor version if type stability is required.
npm install xcompile
yarn add xcompile
pnpm add xcompile

Shows basic C to TypeScript transpilation using XCompile class and transpile method.

import { xcompile, XCompile } from 'xcompile';

const xc = new XCompile();
const source = `int add(int a, int b) { return a + b; }`;
const result = xc.transpile(source, { from: 'c', to: 'ts' });
console.log(result.code);
// Expected output: function add(a: number, b: number): number { return a + b; }