decaffeinate-parser
Version:
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
35 lines (25 loc) • 1.26 kB
Markdown
This project uses the [official CoffeeScript
parser](https://github.com/jashkenas/coffeescript) to parse CoffeeScript source
code, then maps the AST generated by the parser to one more suitable for the
[](https://github.com/eventualbuddha/decaffeinate) (based on
the AST generated by
[](https://github.com/michaelficarra/CoffeeScriptRedux)).
This project might be useful to anyone who wants to work with a CoffeeScript
AST and prefers working with a saner AST.
```bash
$ yarn add decaffeinate-parser
$ npm install decaffeinate-parser
```
This example gets the names of the parameters in the `add` function:
```js
import { parse } from 'decaffeinate-parser';
const program = parse('add = (a, b) -> a + b');
const assignment = program.body.statements[0];
const fn = assignment.expression;
console.log(fn.parameters.map((param) => param.data)); // [ 'a', 'b' ]
```