MCPcopy Index your code
hub / github.com/decaffeinate/decaffeinate

github.com/decaffeinate/decaffeinate @v8.1.4

Chat with this repo
repository ↗ · DeepWiki ↗ · release v8.1.4 ↗ · + Follow
1,269 symbols 3,651 edges 297 files 346 documented · 27% 1 cross-repo links updated 2y agov8.1.4 · 2023-02-23★ 2,70932 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

decaffeinate npm Join the chat at https://gitter.im/decaffeinate

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.

Installation and usage

# via yarn
$ yarn global add decaffeinate
# via npm
$ npm install -g decaffeinate

$ decaffeinate input.coffee
input.coffee → input.js

# convert all files in directory and subdirectories
$ decaffeinate .
input.coffee → input.js
subfolder/input.coffee → subfolder/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, and see Cleanup suggestions after running decaffeinate for advice on cleaning up the converted JavaScript code and other things to keep in mind.

Questions and support

Feel free to join the gitter chat room to ask questions, or you can file an issue on the issues page:

Status

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
chroma.js 3.3K chromajs-conversion-status chromajs-test-status
hubot [1] 3.7K hubot-conversion-status hubot-test-status
autoprefixer [1] 4.8K autoprefixer-conversion-status autoprefixer-test-status
coffeelint 8.8K coffeelint-conversion-status coffeelint-test-status
vimium [2] 11K vimium-conversion-status vimium-test-status
coffeescript [2] 17K coffeescript-conversion-status coffeescript-test-status
coffeescript2 [2] 17K coffeescript2-conversion-status coffeescript2-test-status
atom [1] 51K atom-conversion-status atom-test-status
atom-org 170K atom-org-conversion-status atom-org-test-status
codecombat 230K codecombat-conversion-status codecombat-test-status

Project builder status: Build Status

Notes:

  1. Hubot and Autoprefixer have fully moved to JavaScript using decaffeinate. This build runs on the last commit before the switch to JS. Atom has mostly moved to JavaScript using decaffeinate, so this build runs on an earlier revision that was primarily CoffeeScript.
  2. 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:

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.

Goals

  • 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.

Common options

  • --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.
  • --use-js-modules: Convert require and module.exports to import and 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 useJSModules option.

Other options

  • --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.
  • --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.includes in generated code.
  • --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 requires from being converted to imports.
  • --prefer-let: Use let instead of const for most variables in output code.
  • --loose: Enable all --loose... options.
  • --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.
  • --loose-js-modules: Allow named exports when converting to JS modules.
  • --disallow-invalid-constructors: Give an error when constructors use this before super or omit the super call in a subclass.
  • --optional-chaining: Target JavaScript optional chaining. Note the semantics may not match exactly.
  • --nullish-coalescing: Target JavaScript nullish coalescing. Note the semantics may not match exactly.
  • --logical-assignment: Use the ES2021 logical assignment operators &&=, ||=, and ??=.

For more usage details, see the output of decaffeinate --help.

Extension points exported contracts — how you extend this code

IIFEPatcher (Interface)
(no doc) [7 implementers]
src/stages/main/patchers/BlockPatcher.ts
PatcherClass (Interface)
(no doc) [1 implementers]
src/patchers/NodePatcher.ts
Extra (Interface)
(no doc)
test/support/check.ts
ConversionResult (Interface)
(no doc)
src/index.ts
Suggestion (Interface)
(no doc)
src/suggestions.ts
Options (Interface)
(no doc)
src/options.ts
IO (Interface)
(no doc)
src/cli.ts
Indent (Interface)
(no doc)
src/types/detect-indent.d.ts

Core symbols most depended-on inside this repo

check
called by 1248
test/support/check.ts
insert
called by 313
src/patchers/NodePatcher.ts
patch
called by 141
src/stages/main/patchers/ClassBlockPatcher.ts
error
called by 131
src/patchers/NodePatcher.ts
overwrite
called by 124
src/patchers/NodePatcher.ts
notNull
called by 114
src/utils/notNull.ts
checkCS2
called by 109
test/support/check.ts
sourceTokenAtIndex
called by 80
src/patchers/NodePatcher.ts

Shape

Method 797
Class 298
Function 148
Interface 26

Languages

TypeScript100%

Modules by API surface

src/patchers/NodePatcher.ts104 symbols
src/stages/main/patchers/ForInPatcher.ts48 symbols
src/stages/main/patchers/ConditionalPatcher.ts25 symbols
src/utils/Scope.ts21 symbols
src/stages/normalize/patchers/ClassPatcher.ts21 symbols
src/stages/main/patchers/LoopPatcher.ts20 symbols
src/stages/main/patchers/BlockPatcher.ts19 symbols
src/stages/main/patchers/TryPatcher.ts17 symbols
src/stages/main/patchers/FunctionPatcher.ts17 symbols
src/stages/main/patchers/ForPatcher.ts17 symbols
src/stages/main/patchers/ClassPatcher.ts16 symbols
src/stages/main/patchers/SwitchPatcher.ts15 symbols

Used by 1 indexed graphs manifest dependencies, hub-wide

For agents

$ claude mcp add decaffeinate \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact

Ask about this repo answers extend the page