{"id":24924,"library":"ast-transpiler","title":"AST Transpiler","description":"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.","status":"active","version":"0.0.85","language":"javascript","source_language":"en","source_url":"https://github.com/ccxt/ast-transpiler","tags":["javascript","transpiling","transpiler","ast","typescript","python","php","compiler"],"install":[{"cmd":"npm install ast-transpiler","lang":"bash","label":"npm"},{"cmd":"yarn add ast-transpiler","lang":"bash","label":"yarn"},{"cmd":"pnpm add ast-transpiler","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Parsing JavaScript/TypeScript source into AST","package":"@babel/parser","optional":false},{"reason":"Alternative JS parser for fallback or specific syntax support","package":"acorn","optional":true}],"imports":[{"note":"The package is ESM-only since v0.0.80; CommonJS require() is not supported.","wrong":"const transpile = require('ast-transpiler')","symbol":"transpile","correct":"import { transpile } from 'ast-transpiler'"},{"note":"parseSync is a named export, not a default export.","wrong":"import parseSync from 'ast-transpiler'","symbol":"parseSync","correct":"import { parseSync } from 'ast-transpiler'"},{"note":"TranspilerConfig is a TypeScript type and should be imported with `import type` to avoid runtime errors.","wrong":"import { TranspilerConfig } from 'ast-transpiler'","symbol":"TranspilerConfig","correct":"import type { TranspilerConfig } from 'ast-transpiler'"}],"quickstart":{"code":"import { transpile } from 'ast-transpiler';\n\nconst code = `\nfunction add(a: number, b: number): number {\n  return a + b;\n}\n`;\n\nasync function main() {\n  const result = await transpile({\n    source: code,\n    sourceLang: 'typescript',\n    targetLang: 'python',\n    options: { pythonVersion: 3.9 }\n  });\n  console.log(result.code);\n}\n\nmain().catch(console.error);","lang":"typescript","description":"Transpiles a TypeScript function to Python using the transpile API with target language options."},"warnings":[{"fix":"Update code to use nested `options.python.version` for Python target.","message":"Breaking change in v0.0.85: `options` parameter structure changed; `pythonVersion` moved from root to nested `options.python.version`.","severity":"breaking","affected_versions":">=0.0.85"},{"fix":"Replace `parseSync` with `parse` using `await`.","message":"Deprecated: `parseSync` is deprecated in favor of `parse` (async).","severity":"deprecated","affected_versions":">=0.0.83"},{"fix":"Use dynamic `import()` or migrate project to ESM.","message":"Breaking change in v0.0.80: Package switched to ESM-only. `require()` calls will fail.","severity":"breaking","affected_versions":">=0.0.80"},{"fix":"Import types exclusively from 'ast-transpiler' root.","message":"TypeScript types are exported only from the main entry; subpath exports do not include types.","severity":"gotcha","affected_versions":">=0.0.80"},{"fix":"Replace `language` with `targetLang` in options.","message":"Breaking change in v0.0.70: `targetLang` option renamed from `language`.","severity":"breaking","affected_versions":">=0.0.70"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Add `\"type\": \"module\"` to your package.json or use .mjs extension for import.","cause":"Package is ESM-only and may require `\"type\": \"module\"` in package.json or .mjs extension.","error":"Cannot find module 'ast-transpiler' or its corresponding type declarations."},{"fix":"Use `options: { python: { version: 3.9 } }` instead of `options: { pythonVersion: 3.9 }`.","cause":"Since v0.0.85, Python version must be nested under `options.python.version`.","error":"Error: `options.pythonVersion` is not a valid option. Did you mean `options.python.version`?"},{"fix":"Use `const result = await parse(...)` instead of `parseSync(...)`.","cause":"`parseSync` was removed in v0.0.83; use async `parse`.","error":"TypeError: parseSync is not a function"},{"fix":"Ensure your runtime supports ESM and that the package is resolved correctly.","cause":"Attempting to import from a CJS build; package is ESM-only but some environments may incorrectly detect as CJS.","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."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}