1

I am currently using Closure/Plovr advanced mode to compile javascript.

I want to add some custom functionality, such as string replacements and variable renaming. The important thing is that it requires parsed syntax.

Is it possible to add this functionality? Is there an API for this or do I have to dive into the Closure code (which I don't really want to do).

ColBeseder
  • 3,579
  • 3
  • 28
  • 45

2 Answers2

2

There are no plugins for Closure-compiler. If the optimization does not exist, you would need to write it as a custom pass for the compiler.

Chad Killingsworth
  • 14,360
  • 2
  • 34
  • 57
  • It seems like a compiler pass is what I was looking for. I'll start searching for docs on how to implement one. If you have any tips, I'd appreciate them. – ColBeseder Oct 15 '13 at 05:47
  • I recommend posting specifics of what you are after as there are quite a few compiler passes/options that are not enabled by default. You can ask such questions here: https://groups.google.com/forum/#!forum/closure-compiler-discuss – Chad Killingsworth Oct 15 '13 at 13:29
1

Mike Bolin's book the Closure Definitive Guide has a chapter on this but it is a little dated. Adding a custom compiler pass is done via the Java API. Beware however, while the internal AST is stable it is subject to change without notice and when ES6 support is added you can certainly expect changes.

However, if you pass is generally useful, you might consider contributing it to the main tree.

John
  • 5,443
  • 15
  • 21
  • I doubt my pass will be generally useful. But I also doubt that it wil be a priority for us to update to a closure that supports ES6. – ColBeseder Oct 17 '13 at 06:30