I'm working on an alternative compiler for Google Closure templates. I'm curious about whether others would be interested, and I'm also seeking feedback on my approach.
The compiler is two-part.
The first part uses PEG (Parsing Expression Grammar) and PEGJS to parse the template code and turn it into a Javascript/JSON object for later use in the compiler (or for providing immediate feedback/syntax highlighting/code assist).
The second part is a pure javascript implementation that outputs the code. I have a lot of work still, as it's basically a proof of concept at this point.. I've only implemented a tiny subset of the features of closure templates, but it's enough to get feedback on the approach. I plan to work around the inefficiencies of the output code by using an output buffer to combine multiple "print" commands, and some sort of ruleset for deciding whether to inline ifs as ternaries.
I'm undecided about using soyutils.js vs writing my own sanitation.
The perceived advantages of this approach are as follows:
- No reliance on Java for compiling
- Portable compiler (server, browser)
- Real-time feedback on parsing results, errors, warnings when writing soy templates
- Easier to extend the language (easy modular support for packaging and module definitions--requirejs, AMD, goog, YUI loaders, etc)
- Simpler, more modular, maintainable compiler (by separating and simplifying parsing and codebuilding)
Thanks in advance for any feedback. All feedback is welcome.
Jamon