Question: What impact does CoffeeScript 2 have on the decaffeinate project
See original GitHub issueFirst off, thanks so much for building this project! My team and I have recently just finished successfully decaffeinating all of our CoffeeScript code: ~200k lines of code, ~1400 files. So we appreciate this effort a lot.
I’m in the midst of writing a blog post detailing our process. One of the points I want to discuss is what the impact of CoffeeScript 2.x has. With the CS2 compiler outputting ES2016+/ES.next code, I was curious what your view is on how people should think about decaffeinate and the CS2 compiler.
Despite the output being somewhat comparable, the goals of the projects are of course completely different. One benefit of decaffeinate is the ability to preserve whitespace, formatting, etc. Another huge benefit is the tooling around with bulk-decaffeinate and integration with other tools like eslint, jscodeshift, etc.
Some differences I’ve taken note of so far:
- Project goals
- Decaffeinate: one-time full conversion into ES.next code
- CS2: Interoperability with ES.next code but still keeping CoffeeScript
- Maintaining whitespace, formatting
- Handling of bound subclasses
- Erroring/providing potential polyfill vs run-time error (in the latest coffeescript@2.0.0-beta3)
- Behavior with polyfilling
__guard__
,__guardMethod__
,__range__
vs inlining and declaring intermediary vars. - Other instances where I would argue that decaffeinate outputs code much more akin to what a human may have output.
- Code architecture of the decaffeinate vs coffeescript projects
- Multi-stage patchers vs compilation of AST
- No need for source maps since the purpose is doing a final conversion to ES code
- Probably many things I’m missing
Thoughts?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (3 by maintainers)
Top GitHub Comments
Hey @sudowork, thanks for sharing, really cool to hear that decaffeinate has been successfully used on such a big codebase!
Yeah, it’s certainly interesting to compare decaffeinate with CS2. CS2 is a language implementation and decaffeinate is a codebase conversion tool, so you can expect the objectives are different even if the tools are similar in what they do. As I understand things, CS2 wants to generate new-style JavaScript so that the languages can be closer aligned. If JS comes out with some fancy new feature, CS wants to just compile to that feature rather than needing to re-implementing it. And someone familiar with JavaScript who wants to try out CoffeeScript should find it familiar, but with a cleaner syntax, and not feel like there’s anything missing.
Your differences are pretty spot on. Some other things I might add:
--loose
option (really a family of options) that focuses on better code at the expense of 100% correctness, which wouldn’t make sense in CoffeeScript.Some other random thoughts:
__guard__
thing is annoying, and something I’m hoping to improve; see #336 and #1103. It’s mostly just the easiest thing I could do that works in all cases, rather than an intentional difference from CoffeeScript’s output. Arguably decaffeinate should focus on streamlining manual cleanup rather than generating nice-looking code. For example, even leaving a comment with the original?.
usages might be useful.Thanks! Some of the codemods were definitely targeted towards patterns we had in our CoffeeScript codebase, but I hope they’re helpful 😃.