Recently I have started to use Google Closure Tools for my javascript development. Until now, I have used to write my code in CoffeeScript, however, the javascript generated by CoffeeScript seems to be incompatible with Google Closure Compiler's advanced mode.
Is there any extension to the CoffeeScript compiler adding Google Closure support?
1 – WHAT IS COFFEESCRIPT Basically, CoffeeScript was made by people who hate JavaScript syntax, intended to be used by other people who hate JavaScript syntax.
The Closure Compiler is a tool for making JavaScript download and run faster. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left.
There are various tools that aiming to make CoffeeScript usable with Google Closure Tools. I will describe three of them:
Features:
in
operator and various other incompatibilities@constructor
and @extends
annotationsgoog.provide
statement for each class declaredinclude namespace as alias
support translated to goog.require
and goog.scope
Drawbacks:
My.Long.Named.Car
cannot be refered as Car
in class definition as pure CoffeeScript allows)provide
equivalent for include
Read more at http://bolinfest.com/coffee/
Disclaimer: I am the author of this solution
This solution is inspired by the Bolinfest's work and extends it in these ways:
goog.scope
@constructor
and @extends
annotations are replaced by generatedprovide
cast<typeToCastTo>(valueToBeCast)
syntaxRead more at https://github.com/hleumas/coffee-script/wiki
Unlike the two solutions above, Steida's Coffee2Closure is postprocessor of javascript code generated by upstream nontweaked CoffeeScript. This approach has a one major advantage, that it will need no or only slight updates with continued development of CoffeeScript and still be actual. However, by the very nature of this approach, some of the features cannot be delivered. Currently it fixes only classes and bindings, loops, in
operator and few other incompatibilities. It has no support for automatic annotation generation, type casting or custom keywords.
https://github.com/Steida/coffee2closure
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With