Registry / web-framework / ast-transpiler

ast-transpiler

JSON →
library0.0.85jsnpmunverified

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.

npm install ast-transpiler
INSTALL
IMPORT
SIG · AST-TRANSPILER
A
ast-transpiler
web-frameworkjavascriptv0.0.85
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

transpile
import { transpile } from 'ast-transpiler'
const transpile = require('ast-transpiler')
The package is ESM-only since v0.0.80; CommonJS require() is not supported.
parseSync
import { parseSync } from 'ast-transpiler'
import parseSync from 'ast-transpiler'
parseSync is a named export, not a default export.
TranspilerConfig
import type { TranspilerConfig } from 'ast-transpiler'
import { TranspilerConfig } from 'ast-transpiler'
TranspilerConfig is a TypeScript type and should be imported with `import type` to avoid runtime errors.

Transpiles a TypeScript function to Python using the transpile API with target language options.

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);
ast-transpiler --version
Debug
Known issues
breakingBreaking 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.
affects: >=0.0.85
deprecatedDeprecated: `parseSync` is deprecated in favor of `parse` (async).
fix
Replace `parseSync` with `parse` using `await`.
affects: >=0.0.83
breakingBreaking change in v0.0.80: Package switched to ESM-only. `require()` calls will fail.
fix
Use dynamic `import()` or migrate project to ESM.
affects: >=0.0.80
gotchaTypeScript types are exported only from the main entry; subpath exports do not include types.
fix
Import types exclusively from 'ast-transpiler' root.
affects: >=0.0.80
breakingBreaking change in v0.0.70: `targetLang` option renamed from `language`.
fix
Replace `language` with `targetLang` in options.
affects: >=0.0.70
Errors
Common errors & fixes
Cannot find module 'ast-transpiler' or its corresponding type declarations.
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: `options.pythonVersion` is not a valid option. Did you mean `options.python.version`?
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 }`.
TypeError: parseSync is not a function
`parseSync` was removed in v0.0.83; use async `parse`.
fix
Use `const result = await parse(...)` instead of `parseSync(...)`.
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.
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.
Upgrade
Version history
0.0.85latest on npm
Audit
Dependencies
@babel/parserrequiredParsing JavaScript/TypeScript source into AST
acornoptionalAlternative JS parser for fallback or specific syntax support
Agent activity
21 hits · last 30 days
node
18
OpenAI (training)
1
Resources
ast-transpiler — npm install ast-transpiler · libregistry