ColBeseder
ColBeseder

Reputation: 3669

How to make a plugin for Google Closure

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).

Upvotes: 1

Views: 78

Answers (2)

John
John

Reputation: 5468

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.

Upvotes: 1

Chad Killingsworth
Chad Killingsworth

Reputation: 14411

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.

Upvotes: 2

Related Questions