# trastpiler

> Agnostic transpiler for ASTs

Latest version **1.0.2** (published 2019-08-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install trastpiler
pnpm add trastpiler
yarn add trastpiler
bun add trastpiler
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2019-08-01 |
| First published | 2018-10-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Node | >=8.6 |
| Dependencies | 1 |
| Unpacked size | 14 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Agron Kabashi |
| Maintainers | agronkabashi |
| Keywords | transpiler, AST |

## Links

- npm: https://www.npmjs.com/package/trastpiler
- Repository: https://github.com/AgronKabashi/trastpiler
- Homepage: https://github.com/AgronKabashi/trastpiler#readme
- Issues: https://github.com/AgronKabashi/trastpiler/issues
- npm.io page: https://npm.io/package/trastpiler

## Dependencies (1)

- [deepmerge](https://npm.io/package/deepmerge.md) ^4.0.0

## Alternatives

- [update-check](https://npm.io/package/update-check.md) — 4.0M weekly downloads
- [react-native-onesignal](https://npm.io/package/react-native-onesignal.md) — 134.5K weekly downloads
- [react-redux-toastr](https://npm.io/package/react-redux-toastr.md) — 33.7K weekly downloads
- [@nocobase/plugin-notification-manager](https://npm.io/package/@nocobase/plugin-notification-manager.md) — 2.0K weekly downloads
- [react-simple-toasts](https://npm.io/package/react-simple-toasts.md) — 1.9K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2019-08-01
- 2.0.0 (next) — 2025-12-14
- 1.0.0 (beta) — 2018-10-12
- 1.0.1 — 2018-11-02

## README

# Trastpiler
Trastpiler is an agnostic transpiler for Abstract Syntax Trees.

## Installation
```
npm install trastpiler --save
```

## Basic Usage
```js
import createTranspiler from "trastpiler";

// Generate an AST using parser of choice
const tree = esprima.parse(javascriptCode);

// Create a <AST-type, callback> hashmap for the supported declarations, statements and expressions.
const mappers = {
  WhileStatement: ({ body, test }, { transpile }) =>
    `while ${transpile(test)} do
      ${transpile(body)}
    end`,

  // ...
};

// Create a transpiler and call it,
// supplying an AST node to start from
const transpile = createTranspiler({ mappers });
const transpiledCode = transpile(tree.body);
```

## Arguments
| Property              | Type                      | Description |
|-----------------------|---------------------------|-------------|
| configuration         | object                    |             |
| &nbsp;&nbsp;&nbsp;&nbsp;mappers       | HashMap<string, function> | Key-value pairs of a declaration/expression/statement type and function to process the AST node. |
| &nbsp;&nbsp;&nbsp;&nbsp;initialScope  | object                    | Initial data to use for the scope. |

## Declaration/Expression/Statement Interface
A declaration, expression or statement must have the following signature:
```js
/**
 * @param {object} node AST node. Nodes must atleast have a `type` property
 * @param {{ transpile, scope }} references References to the current scope and transpiler function - optional.
 * @return {string} transpiled node
 */
function expressionTypeName (node, { transpile, scope }) {
  // Do stuff relevant for this expression (transpile child nodes, add variables to scope etc)
  return transpiledCode;
}
```

## Examples
In the [examples](examples/) folder you may find some practical examples of how to build your own libraries on top of trastpiler.

## Showcases
* [jspicl](https://github.com/AgronKabashi/jspicl) - Transpiles JavaScript into a subset of LUA.

---
_Source: https://npm.io/package/trastpiler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
