1 | # decaffeinate-parser [![CircleCI](https://circleci.com/gh/decaffeinate/decaffeinate-parser.svg?style=svg)](https://circleci.com/gh/decaffeinate/decaffeinate-parser) [![package version](https://badge.fury.io/js/decaffeinate-parser.svg)](https://badge.fury.io/js/decaffeinate-parser)
|
2 |
|
3 | This project uses the [official CoffeeScript
|
4 | parser](https://github.com/jashkenas/coffeescript) to parse CoffeeScript source
|
5 | code, then maps the AST generated by the parser to one more suitable for the
|
6 | [decaffeinate project](https://github.com/eventualbuddha/decaffeinate) (based on
|
7 | the AST generated by
|
8 | [CoffeeScriptRedux](https://github.com/michaelficarra/CoffeeScriptRedux)).
|
9 |
|
10 | This project might be useful to anyone who wants to work with a CoffeeScript
|
11 | AST and prefers working with a saner AST.
|
12 |
|
13 | ## Install
|
14 |
|
15 | ```bash
|
16 | # via yarn
|
17 | $ yarn add decaffeinate-parser
|
18 | # via npm
|
19 | $ npm install decaffeinate-parser
|
20 | ```
|
21 |
|
22 | ## Usage
|
23 |
|
24 | This example gets the names of the parameters in the `add` function:
|
25 |
|
26 | ```js
|
27 | import { parse } from 'decaffeinate-parser';
|
28 |
|
29 | const program = parse('add = (a, b) -> a + b');
|
30 | const assignment = program.body.statements[0];
|
31 | const fn = assignment.expression;
|
32 |
|
33 | console.log(fn.parameters.map(param => param.data)); // [ 'a', 'b' ]
|
34 | ```
|