Skip to content

decaffeinate/decaffeinate-parser

Folders and files

NameName
Last commit message
Last commit date
Jun 26, 2022
Jun 26, 2022
Jun 11, 2022
Jun 7, 2022
Jun 11, 2022
Jun 11, 2022
Jul 1, 2018
Sep 11, 2019
Oct 4, 2015
Jun 11, 2022
Jun 7, 2022
Jun 26, 2022
Jun 26, 2022
Jun 11, 2022
Jun 11, 2022

Repository files navigation

decaffeinate-parser CI package version

This project uses the official CoffeeScript parser to parse CoffeeScript source code, then maps the AST generated by the parser to one more suitable for the decaffeinate project (based on the AST generated by CoffeeScriptRedux).

This project might be useful to anyone who wants to work with a CoffeeScript AST and prefers working with a saner AST.

Install

# 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:

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' ]