decaffeinate / decaffeinate
- вторник, 20 июня 2017 г. в 03:12:18
JavaScript
Goodbye CoffeeScript, hello JavaScript!
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.
Complete. The project is stable enough for production use, and has been used to convert tens of thousands of lines of production code. The conversion process has been extensively tested and there are few or no known correctness bugs, although 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-created from the original repo once per day.
Project | Lines of CoffeeScript | Conversion status | Test status |
---|---|---|---|
chroma.js | 3.3K | ||
hubot [1] | 3.7K | ||
autoprefixer [1] | 4.8K | ||
coffeelint | 8.8K | ||
vimium | 11K | ||
coffeescript [2] | 17K | ||
atom | 51K | ||
atom-org | 170K | ||
codecombat | 230K |
Notes:
To contribute to this list, send a pull request to the decaffeinate-examples project.
In addition, decaffeinate has been used on private codebases within various companies, such as Square, Benchling, and Bugsnag. See this blog post from Bugsnag to read about their experiences using decaffeinate.
If you run into crashes or correctness issues, or you have suggestions on how decaffeinate could be improved, feel free to file an issue on the issues page.
--modernize-js
: Treat the input as JavaScript and only run the
JavaScript-to-JavaScript transforms, modifying the file(s) in-place.--literate
: Treat the input file as Literate CoffeeScript.--keep-commonjs
: Do not convert require
and module.exports
to import
and export
.--force-default-export
: When converting to export
, use a single
export default
rather than trying to generate named imports where possible.--safe-import-function-identifiers
: Comma-separated list of function names
that may safely be in the import
/require
section of the file. All other
function calls will disqualify later require
s from being converted to
import
s.--prefer-const
: Use const
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 in Array.from
.--loose-for-of
: Do not wrap JS for...of
loop targets in Array.from
.--loose-includes
: Do not wrap in Array.from
when converting in
to includes
.--loose-comparison-negation
: Allow unsafe simplifications like !(a > b)
to a <= b
.--allow-invalid-constructors
: Don't error when constructors use this
before super or omit the super
call in a subclass.--enable-babel-constructor-workaround
: Use a hacky Babel-specific workaround
to allow this
before super
in constructors. Also works when using
TypeScript.For more usage details, see the output of decaffeinate --help
.