https://github.com/decaffeinate/decaffeinate-parser
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
https://github.com/decaffeinate/decaffeinate-parser
ast coffeescript decaffeinate es2015 parse
Last synced: 11 months ago
JSON representation
A better AST for CoffeeScript, inspired by CoffeeScriptRedux.
- Host: GitHub
- URL: https://github.com/decaffeinate/decaffeinate-parser
- Owner: decaffeinate
- License: mit
- Created: 2015-09-29T03:36:04.000Z (over 10 years ago)
- Default Branch: main
- Last Pushed: 2023-03-03T23:58:52.000Z (over 3 years ago)
- Last Synced: 2025-05-02T08:45:41.110Z (about 1 year ago)
- Topics: ast, coffeescript, decaffeinate, es2015, parse
- Language: TypeScript
- Size: 3.01 MB
- Stars: 23
- Watchers: 2
- Forks: 12
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# decaffeinate-parser [](https://github.com/decaffeinate/decaffeinate-parser/actions/workflows/ci.yml) [](https://badge.fury.io/js/decaffeinate-parser)
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
[decaffeinate project](https://github.com/eventualbuddha/decaffeinate) (based on
the AST generated by
[CoffeeScriptRedux](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.
## Install
```bash
# via yarn
$ yarn add decaffeinate-parser
# via npm
$ npm install decaffeinate-parser
```
## Usage
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' ]
```