3 ms·
I'm assuming "modern JavaScript" means ES6. Has anyone used this, and does it produce readable code?
by tyrw 9y ago
I'm assuming "modern JavaScript" means ES6. Has anyone used this, and does it produce readable code?
- alangpierce 9y agoYeah, "modern JS" is meant to be the catch-all term for ES6/ES7/ES2015/ES2016/ES2017. In this case, you need ES2016 to run code produced by decaffeinate, but anything in the latest language version or at stage 4 is fair game and might be added in the future. Producing readable code is certainly the intent! Realistically, you need to clean some things up by hand to make it pass lint and look nice, but I think overall it does a pretty good job, certainly much better than the CoffeeScript compiler. You can always play around with it by typing/pasting code into the online repl: http://decaffeinate-project.org/repl/ http://decaffeinate-project.org/repl/
- uranian 9y agoYou mean only ES2016 from that list? > Producing readable code is certainly the intent! This is hilarious! Transpiling from the most readable JS alternative to ES6? Then you need to clean up some things, making it ready for yet another transpiler called Babel? And then everything is OK? Show me how you are going to make this pretty: if does.that?.prop?.exist then console.log 'yes, no crash!'
- alangpierce 9y ago> You mean only ES2016 from that list? No, I was intentional about my description. People tend to be informal when talking about JS versions, and all five of those terms might be used to describe decaffeinate's output. IMO it's best to just say that decaffeinate produces JavaScript, and not any particular old version of JavaScript. > Show me how you are going to make this pretty Soak operations (anything with a question mark) are probably the hardest to convert to JavaScript, especially when they're chained. Here's what decaffeinate gives today: http://decaffeinate-project.org/repl/#?evaluate=true&stage=full&code=if%20does.that%3F.prop%3F.exist%20then%20console.log%20'yes%2C%20no%20crash!' http://decaffeinate-project.org/repl/#?evaluate=true&stage=f... And here's an open bug with thoughts on making those look better: https://github.com/decaffeinate/decaffeinate/issues/336 https://github.com/decaffeinate/decaffeinate/issues/336 But many people have still found decaffeinate useful since the vast majority of real-world CoffeeScript (at least from what I've seen) tends to convert pretty well, and even in difficult cases, it's better to safely get it in JavaScript first and then clean it up than to rewrite everything by hand.
- uranian 9y agoif (__guard__(does.that != null ? does.that.prop : undefined, x => x.exist)) { console.log('yes, no crash!'); } function __guard__(value, transform) { return (typeof value !== 'undefined' && value !== null) ? transform(value) : undefined; } oh my.. This was 1 line of CS, how to clean this up without a chance of creating bugs? How on earth is ESxxx an improvement on CS anyways? It's just not true, it's a leap back.
- Grue3 9y agoIt produces Javascript, so by definition it cannot produce readable code.