# transpilation-ts

> Ce projet permet de générer du code dans n'importe quel langage à partir d'un AST

Latest version **0.0.2** (published 2023-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install transpilation-ts
pnpm add transpilation-ts
yarn add transpilation-ts
bun add transpilation-ts
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.2 |
| Published | 2023-05-17 |
| First published | 2023-05-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 94.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | seboran |

## Links

- npm: https://www.npmjs.com/package/transpilation-ts
- npm.io page: https://npm.io/package/transpilation-ts

## Dependencies (1)

- [prettier](https://npm.io/package/prettier.md) ^2.8.7

## Recent versions

- 0.0.2 (latest) — 2023-05-17
- 0.0.1 — 2023-05-17

## README

# Transpilation

Ce projet permet de générer du code dans n'importe quel langage à partir d'un AST

## Comment lancer ce projet ?

```bash
yarn run start
```

## Comment créer son propre code

On veut représenter avec des nodes l'instruction suivante en pseudo code :

```pseudo
si X > Y:
  2 + (5 * 3)
sinon:
  2 + (5 - 3)
```

Pour cela on peut identifier que l'instruction est un bloc if, portant une condition, et une expression si vraie et une expression si faux.

Cela se représente ainsi :

```typescript
new SiNode(
  new ConditionNode(
    new SuperieurNode(new LitteralNode('X'), new LitteralNode('Y'))
  ),
  new AdditionNode(
    new NumberNode(2),
    new MultiplicationNode(new NumberNode(5), new NumberNode(3))
  ),
  new AdditionNode(
    new NumberNode(2),
    new SoustractionNode(new NumberNode(5), new NumberNode(3))
  )
)
```

Pour parcourir cet arbre, chaque node implémente la méthode `accept` qui prend un `VisiteurNode` en argument. Voir par exemple `JavascriptGenerator`.

Exemple d'utilisation :

```typescript
const javascriptGenerator = new JavascriptGenerator()
const code = instructions.accept(javascriptGenerator)
```

Et notre instance de JavascriptGenerator parcoure toute la node automatiquement.

Ce pattern est appelé "Visitor pattern double dispatch"

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