Installation and usage
# via yarn$ yarn global add decaffeinate# via npm$ npm install -g decaffeinate$ decaffeinate input.coffeeinput.coffee → input.js# convert all files in directory and subdirectories$ decaffeinate .input.coffee → input.jssubfolder/input.coffee → subfolder/input.js
Alternatively, paste code into the online repl to immediately see the output.
Questions and support
Complete. The project is stable enough for production use, and has been used to convert hundreds of thousands (probably millions) 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|
- Some CoffeeScript tests are disabled because they are difficult to fix and test situations that do not seem to come up in real-world code. The Vimium test suite has also been modified slightly to work around a correctness issue. See How decaffeinate approaches correctness for full details.
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, Bugsnag, and DataFox.
Some blog posts on using decaffeinate:
- From 200K lines of CoffeeScript to zero: making decaffeinate super-stable
- Converting a large React Codebase from Coffeescript to ES6
- Decaffeinating a Large CoffeeScript Codebase Without Losing Sleep
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.
- 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.
--use-cs2: Treat the input as CoffeeScript 2 code. CoffeeScript 2 has some small breaking changes and differences in behavior compared with CS1, so decaffeinate assumes CS1 by default and allows CS2 via this flag.
export. Note that this may result in incorrect import statements because decaffeinate does not know the export style used by the other file. To generate correct imports, use bulk-decaffeinate and enable the
--literate: Treat the input file as Literate CoffeeScript.
--disable-suggestion-comment: Do not include a comment with followup suggestions at the top of the output file.
--no-array-includes: Do not use
Array.prototype.includesin generated code.
--use-optional-chaining: Use the upcoming optional chaining syntax for operators like
--safe-import-function-identifiers: Comma-separated list of function names that may safely be in the
requiresection of the file. All other function calls will disqualify later
requires from being converted to
constfor most variables in output code.
--loose: Enable all
--loose-default-params: Convert CS default params to JS default params.
--loose-for-expressions: Do not wrap expression loop targets in
--loose-for-of: Do not wrap JS
for...ofloop targets in
--loose-includes: Do not wrap in
--loose-comparison-negation: Allow unsafe simplifications like
!(a > b)to
a <= b.
--loose-js-modules: Allow named exports when converting to JS modules.
--disable-babel-constructor-workaround: Never include the Babel/TypeScript workaround code to allow
--disallow-invalid-constructors: Give an error when constructors use
superor omit the
supercall in a subclass.
For more usage details, see the output of