js2coffee

Compile JavaScript to CoffeeScript

Github星跟踪图

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:

主要指标

概览
名称与所有者js2coffee/js2coffee
主编程语言CoffeeScript
编程语言Makefile (语言数: 3)
平台
许可证MIT License
所有者活动
创建于2011-06-03 18:18:04
推送于2023-11-13 19:44:31
最后一次提交2017-01-05 13:36:23
发布数34
最新版本名称v2.2.0 (发布于 2016-04-02 17:08:52)
第一版名称v0.0.2 (发布于 )
用户参与
星数2.1k
关注者数35
派生数200
提交数532
已启用问题?
问题数379
打开的问题数87
拉请求数54
打开的拉请求数9
关闭的拉请求数76
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?