UNPKG

1.34 kBMarkdownView Raw
1# decaffeinate-parser [![Build Status](https://travis-ci.org/decaffeinate/decaffeinate-parser.svg?branch=master)](https://travis-ci.org/decaffeinate/decaffeinate-parser) [![package version](https://badge.fury.io/js/decaffeinate-parser.svg)](https://badge.fury.io/js/decaffeinate-parser) [![Greenkeeper badge](https://badges.greenkeeper.io/decaffeinate/decaffeinate-parser.svg)](https://greenkeeper.io/)
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
29let program = parse('add = (a, b) -> a + b');
30let assignment = program.body.statements[0];
31let fn = assignment.expression;
32
33console.log(fn.parameters.map(param => param.data)); // [ 'a', 'b' ]
34```