One of the primary complaints about the
Closure Library is
that the type annotations are verbose, so one way to address this problem is
to generate Closure-Library-style code using a more minimalistic
syntax (i.e. TypeScript). This makes it possible to leverage the
Advanced mode of the Closure Compiler (and the existing functions in the
Closure Library) while writing much less code.
This demo is powered by a
fork of the TypeScript codebase that adds a --google
option to
the tsc
executable to generate the Closure-style JavaScript.
Previously, I built a similar prototype for CoffeeScript,
which contains a more detailed explanation
of the motivation behind this approach. Unfortunately, my fork of CoffeeScript was hard to
maintain because it required making modifications to the CoffeeScript grammar. These changes then
had to be propagated all the way through the AST and code generation logic.
Given the high rate of change to CoffeeScript and the number of places I had to integrate into the
CoffeeScript codebase, I found it difficult to create clean, maintainable integration points.
By comparison, TypeScript already supports the primary language feature that I want (optional type annotations),
so I did not need to hack up the grammar as I did for CoffeeScript.
Most of my changes to TypeScript were made to the code generation logic in emitter.ts
; however,
they could be localized to a subclass of Emitter
. This would make it easier to maintain
my fork while continuing to pull in changes from the master branch.
(Though at the time of this writing, 2013-01-01, the TypeScript repository has not seen a
new commit in over a month, so incorporating upstream changes is not an issue.)
I am not sure how open the TypeScript team would be to adding hooks for this sort of thing in
TypeScript, but if they are, I would be happy to put together a pull request.