Code Monkey home page Code Monkey logo

decaffeinate-parser's Introduction

decaffeinate-parser Build Status

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, if statements, etc. have blocks for bodies.
  • String interpolation nodes are modeled after TemplateLiteral from ES6 rather than being a series of nested ConcatOp nodes.
  • Triple-quoted strings have the node type Herestring rather than String.
  • Virtual nodes (such as the LogicalNotOp generated by an unless) are marked as such with a virtual: true property.
  • do is handled with the DoOp node type.
  • for-in loops do not have an implicit step property.
  • Ranges of programs with indented blocks are correct.
  • super is supported in classes.
  • extends is usable as a binary operator and in class declarations.
  • // (floor division) is supported.

Install

$ npm install --save-dev 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' ]

decaffeinate-parser's People

Contributors

eventualbuddha avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.