AST Transpiler
raw JSON → 0.0.85 verified Fri May 01 auth: no javascript
ast-transpiler is a versatile source-to-source transpiler that converts code between JavaScript, TypeScript, Python, and PHP by operating on abstract syntax trees. Version 0.0.85, under active development, it provides a unified AST representation and supports transpilation of modern JavaScript (ESM/CJS) to multiple target languages. Key differentiators: single-pass transpilation, TypeScript-first with full type definitions, and extensible transpilation rules. Ideal for multi-language codebases and tooling that requires cross-language code generation.
Common errors
error Cannot find module 'ast-transpiler' or its corresponding type declarations. ↓
cause Package is ESM-only and may require `"type": "module"` in package.json or .mjs extension.
fix
Add
"type": "module" to your package.json or use .mjs extension for import. error Error: `options.pythonVersion` is not a valid option. Did you mean `options.python.version`? ↓
cause Since v0.0.85, Python version must be nested under `options.python.version`.
fix
Use
options: { python: { version: 3.9 } } instead of options: { pythonVersion: 3.9 }. error TypeError: parseSync is not a function ↓
cause `parseSync` was removed in v0.0.83; use async `parse`.
fix
Use
const result = await parse(...) instead of parseSync(...). error SyntaxError: Named export 'transpile' not found. The requested module 'ast-transpiler' is a CommonJS module which may not support all module.exports as named exports. ↓
cause Attempting to import from a CJS build; package is ESM-only but some environments may incorrectly detect as CJS.
fix
Ensure your runtime supports ESM and that the package is resolved correctly.
Warnings
breaking Breaking change in v0.0.85: `options` parameter structure changed; `pythonVersion` moved from root to nested `options.python.version`. ↓
fix Update code to use nested `options.python.version` for Python target.
deprecated Deprecated: `parseSync` is deprecated in favor of `parse` (async). ↓
fix Replace `parseSync` with `parse` using `await`.
breaking Breaking change in v0.0.80: Package switched to ESM-only. `require()` calls will fail. ↓
fix Use dynamic `import()` or migrate project to ESM.
gotcha TypeScript types are exported only from the main entry; subpath exports do not include types. ↓
fix Import types exclusively from 'ast-transpiler' root.
breaking Breaking change in v0.0.70: `targetLang` option renamed from `language`. ↓
fix Replace `language` with `targetLang` in options.
Install
npm install ast-transpiler yarn add ast-transpiler pnpm add ast-transpiler Imports
- transpile wrong
const transpile = require('ast-transpiler')correctimport { transpile } from 'ast-transpiler' - parseSync wrong
import parseSync from 'ast-transpiler'correctimport { parseSync } from 'ast-transpiler' - TranspilerConfig wrong
import { TranspilerConfig } from 'ast-transpiler'correctimport type { TranspilerConfig } from 'ast-transpiler'
Quickstart
import { transpile } from 'ast-transpiler';
const code = `
function add(a: number, b: number): number {
return a + b;
}
`;
async function main() {
const result = await transpile({
source: code,
sourceLang: 'typescript',
targetLang: 'python',
options: { pythonVersion: 3.9 }
});
console.log(result.code);
}
main().catch(console.error);