UNPKG

1.23 kBMarkdownView Raw
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
3This project uses the [official CoffeeScript
4parser](https://github.com/jashkenas/coffeescript) to parse CoffeeScript source
5code, then maps the AST generated by the parser to one more suitable for the
6[decaffeinate project](https://github.com/eventualbuddha/decaffeinate) (based on
7the AST generated by
8[CoffeeScriptRedux](https://github.com/michaelficarra/CoffeeScriptRedux)).
9
10This project might be useful to anyone who wants to work with a CoffeeScript
11AST 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
24This example gets the names of the parameters in the `add` function:
25
26```js
27import { parse } from 'decaffeinate-parser';
28
29const program = parse('add = (a, b) -> a + b');
30const assignment = program.body.statements[0];
31const fn = assignment.expression;
32
33console.log(fn.parameters.map(param => param.data)); // [ 'a', 'b' ]
34```