Goodbye CoffeeScript, hello JavaScript!
JavaScript is the future, in part thanks to CoffeeScript. Now that it has served its purpose, it's time to move on. Convert your CoffeeScript source to modern JavaScript with decaffeinate.
$ npm install -g decaffeinate
$ decaffeinate input.coffee
input.coffee → input.js
Alternatively, paste code into the online repl to immediately see the output.
For real-world use cases, you'll likely want to spend some time understanding the different options and nuances of the decaffeinate tool. You'll also likely want to run decaffeinate using the bulk-decaffeinate wrapper tool, or write your own wrapper script. See the Conversion Guide for more information and advice on running decaffeinate on real-world code.
Mostly complete. The project has been used to convert tens of thousands of lines of production code, and can be relied upon for production use, but no guarantees are made.
Here are some popular open source CoffeeScript projects and their current status when run through decaffeinate. Each project has a decaffeinate-specific fork that is re-run daily.
Project | Lines of CoffeeScript | Conversion status | Test status |
---|---|---|---|
hubot | 3.7K | ||
autoprefixer | 4.8K | ||
coffeelint | 8.8K | ||
coffeescript | 17K | ||
atom | 51K | ||
codecombat | 230K |
To contribute to this list, send a pull request to the decaffeinate-examples project.
Check the issues page for more specific details on outstanding bugs and incomplete features. And, of course, you're welcome to file issues for any problems you run into.
- Fully automated conversion of the CoffeeScript language to modern JavaScript.
- Preserve whitespace, formatting, and comments as much as possible to allow a full one-time conversion of your CoffeeScript source code.
- Focus on correctness as the first priority, with some options to generate nicer code at the expense of 100% correctness.
- Provide helpful error messages when it encounters an unsupported language construct.
--keep-commonjs
: Do not convertrequire
andmodule.exports
toimport
andexport
.--prefer-const
: Useconst
when possible in output code.--loose-default-params
: Convert CS default params to JS default params.--loose-for-expressions
: Do not wrap expression loop targets inArray.from
.--loose-for-of
: Do not wrap JSfor...of
loop targets inArray.from
.--loose-includes
: Do not wrap inArray.from
when convertingin
toincludes
.--allow-invalid-constructors
: Don't error when constructors usethis
before super or omit thesuper
call in a subclass.--enable-babel-constructor-workaround
: Use a hacky babel-specific workaround to allowthis
beforesuper
in constructors.
For more usage details, see the output of decaffeinate --help
.