trastpiler
raw JSON → 1.0.2 verified Fri May 01 auth: no javascript
trastpiler is a lightweight, agnostic AST transpiler for JavaScript. Version 2.0.0 introduces breaking changes over 1.x, with a focus on plugin-based transformations and improved TypeScript support. It allows traversing and transforming Abstract Syntax Trees (ASTs) using a simple visitor pattern. Unlike Babel or jscodeshift, trastpiler is designed to be minimal and framework-agnostic, with no built-in parsing — you supply your own AST. Development appears intermittent; the latest release is 2.0.0, published roughly monthly during active phases. It targets Node >=8.6 and has no runtime dependencies.
Common errors
error The method 'traverse' does not exist on the default export ↓
cause In v2, traverse is a named export, not a property of the default export.
fix
Use named import: import { traverse } from 'trastpiler'
error Cannot find module 'trastpiler' ↓
cause Package not installed or wrong import path used.
fix
Run npm install trastpiler, then use correct import syntax.
error TypeError: path.replace is not a function ↓
cause transform expects a visitor with replace method; traverse does not have replace.
fix
Use transform instead of traverse if you need to replace nodes.
Warnings
breaking v2 changes the API from default export to named exports. ↓
fix Replace `require('trastpiler')` with `import { traverse, transform } from 'trastpiler'`.
breaking Version 2 drops support for Node <8.6. All previous versions supported Node >=6. ↓
fix Upgrade Node to >=8.6.
gotcha Package does not include type definitions in npm. You must add them manually or use @types/trastpiler if available. ↓
fix Create a declarations file or use skipLibCheck.
gotcha AST node objects are mutated in place by traverse; there is no clone by default. ↓
fix If you need immutability, deep clone the AST before passing to traverse.
Install
npm install trastpiler yarn add trastpiler pnpm add trastpiler Imports
- traverse wrong
const traverse = require('trastpiler').traverse;correctimport { traverse } from 'trastpiler' - transform wrong
import trastpiler from 'trastpiler'; trastpiler.transform(...)correctimport { transform } from 'trastpiler' - types
import type { ASTNode, Visitor } from 'trastpiler' - default import (v1 only) wrong
import * as trastpiler from 'trastpiler';correctconst trastpiler = require('trastpiler');
Quickstart
import { traverse, transform } from 'trastpiler';
// Example AST (simple binary expression)
const ast = {
type: 'Program',
body: [
{
type: 'BinaryExpression',
operator: '+',
left: { type: 'NumericLiteral', value: 1 },
right: { type: 'NumericLiteral', value: 2 }
}
]
};
// Visitor to transform numeric literals
traverse(ast, {
NumericLiteral(path) {
path.node.value = path.node.value * 2;
}
});
console.log(JSON.stringify(ast, null, 2));
// Output: left: 2, right: 4
// Using transform: returns a new AST
transform(ast, {
NumericLiteral(path) {
path.replace({ type: 'NumericLiteral', value: 0 });
}
});