0.0.2 • Published 9 years ago
decaffeinate-parser-classdojo-fork v0.0.2
decaffeinate-parser 
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 the AST generated by CoffeeScriptRedux, but wants to avoid the source compatibility issues introduced by using that project. Note that it is not 100% compatible with CoffeeScriptRedux:
- Single-line functions,
ifstatements, etc. have blocks for bodies. - String interpolation nodes are modeled after
TemplateLiteralfrom ES6 rather than being a series of nestedConcatOpnodes. - Triple-quoted strings have the node type
Herestringrather thanString. - Virtual nodes (such as the
LogicalNotOpgenerated by anunless) are marked as such with avirtual: trueproperty. dois handled with theDoOpnode type.for-inloops do not have an implicitstepproperty.- Ranges of programs with indented blocks are correct.
superis supported in classes.extendsis usable as a binary operator and in class declarations.//(floor division) is supported.
Install
$ npm install --save-dev decaffeinate-parserUsage
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' ]