This repository contains a collection of codemod scripts that should help you convert your CoffeeScript codebase to ES2015.
This project requires JSCodeshift to perform the transforms.
npm install -g jscodeshift
git clone https://github.com/Hacker0x01/coffee-to-es2015-codemod
jscodeshift -t <codemod-script> <file>
- Use the
-d
option for a dry-run and use-p
to print the output for comparison
Because of the nature of the transforms (reverse engineering CoffeeScript patterns from the ES5 output), I don't think that it would ever be wise to run all transforms at once without reviewing. There's simply too much assumptions in the transforms that can go wrong for other codebases. Because of this I decided to split off this repository from the espresso repository, and try very carefully to document all the specific assumptions. In the hope that these transforms can help other people as well.
At HackerOne we decided to convert our codebase through the following steps:
- Convert all CoffeeScript to ES5 by running the CoffeeScript compiler
- Replace the CoffeeScript with the ES5 output
- Run the first transform (TODO: define preferred order of transforms)
- Create a PR/diff for the code change
- After the change has been accepted go back to step 3 and start the next transformation
I know that it probably goes against the nature of a lot of people to review these changes (as they tend to get very big), but it's the only way I trust to make sure nothing gets lost. Once we completed the process @Hacker0x01 I will make sure to document how everything went, and what we've learned, but until then I suggest that everybody takes precaution in using these transforms.
A big thanks to @HipsterBrown for setting up espresso and writing the first set of transforms.
Another big thanks to @fkling for setting up JSCodeshift and to @cpojer for his awesome JSConf.EU talk.