js2coffee

JavaScript to CoffeeScript compiler

MIT 30 个版本
安装
npm install js2coffee
yarn add js2coffee
pnpm add js2coffee
bun add js2coffee
README

js2coffee

Compile JavaScript into CoffeeScript.

Status

This 2.0 release is a complete rewrite featuring a better parser (Esprima). See what's new in 2.0 for an overview of new features and consult the migration guide for info on updating from 0.x.


Install

Available on npm and bower.

npm install --global js2coffee
js2coffee --help

npm version

Also available via CDN (window.js2coffee):

https://cdn.rawgit.com/js2coffee/js2coffee/v2.1.0/dist/js2coffee.js


Command line

The command line utility accepts both filenames or stdin.

$ js2coffee file.js [file2.js ...]
$ cat file.js | js2coffee

JavaScript API

Available via npm (require('js2coffee')), or via CDN in the browser (as window.js2coffee):

result = js2coffee.build(source);

result.code     // code string
result.ast      // transformed AST
result.map      // source map
result.warnings // array of warnings

Errors are in this format:

catch (e) {
  e.message       // "index.js:3:1: Unexpected INDENT\n\n   3   var\n   ---^"
  e.description   // "Unexpected INDENT"
  e.start         // { line: 1, column: 4 }
  e.end           // { line: 1, column: 10 }
  e.sourcePreview // '...'
}

Warnings are in this format:

result.warnings.forEach((warn) => {
  warn.description   // "Variable 'x' defined twice
  warn.start         // { line: 1, column: 4 }
  warn.end           // { line: 1, column: 9 }
  warn.filename      // "index.js"
})

Docs

  • Migration guide - guide for migrating from 0.x.

  • Hacking guide - want to contribute? here are tips to get you started.

  • AST format - technical description of the CoffeeScript AST format.

  • Special cases - a list of edge cases that js2coffee accounts for.

  • Compatibility mode - list of tweaks that compatibility mode (--compat) addresses.

  • Goals - outline of the project's goals.

  • Specs - examples of how JavaScript compiles to CoffeeScript.


Thanks

js2coffee © 2012+, Rico Sta. Cruz. Released under the MIT License.
Authored by Rico Sta. Cruz with help from co-maintainers and contributors (list).

Maintainers:

版本列表
2.2.0 2016-04-02
2.1.0 2015-07-03
2.0.4 2015-05-05
2.0.3 2015-02-14
2.0.2 2015-02-13
2.0.1 2015-02-10
2.0.0 2015-01-31
0.3.5 2014-12-11
0.3.4 2014-12-01
0.3.3 2014-08-23
0.3.2 2014-08-23
0.3.1 2014-07-10
0.3.0 2014-05-17
0.2.7 2014-02-07
0.2.6 2014-01-31
0.2.5 2014-01-20
0.2.4 2014-01-03
0.2.3 2013-10-19
0.2.1 2013-10-14
0.2.0 2013-10-10
0.1.4 2013-06-07
0.1.3 2012-01-08
0.1.2 2012-01-06
0.1.1 2011-07-09
0.1.0 2011-06-12
0.0.5 2011-06-09
0.0.4 2011-06-08
0.0.3 2011-06-05
0.0.2 2011-06-03
0.0.1 2011-06-03