Migrating from CoffeeScript to ES6

Updated . Posted . Visible to the public.

It is quite easy to migrate from CoffeeScript to ES6. You can use decaffeinate Show archive.org snapshot to convert your CoffeeScript source to modern JavaScript.

Install decaffeinate globally:

npm install -g decaffeinate

Call decaffeinate on each .coffee file, relaxing some options to get the most modern (and concise) JS:

decaffeinate file.coffee --use-cs2 --loose --optional-chaining --logical-assignment

Tip

If you use Babel Show archive.org snapshot and see errors while decaffeinating, try deleting your babel.config.js, run decaffeinate, then restore the babel config file.

If your project uses eslint, have it fix style issues (like semicolons):

npx eslint --fix file.js

Decaffeinate will add some suggestions Show archive.org snapshot to your newly generated JS file with advises that makes you JS cleaner. This action need to be done manually and carefully checked. In particular you will need to clean up a lot of unnecessary return statements.

Last edit
Henning Koch
License
Source code in this card is licensed under the MIT License.
Posted by Emanuel to makandra dev (2019-05-22 13:43)