How to prevent Closure Compiler from renaming any property or method of a specific object?
How to prevent Closure Compiler from renaming any property or method of a specific object?
I am working with a huge 3rdparty library (Babylon JS) that will be served from its own CDN and cannot be included in my Closure Compiler run.
The library contains one object and everything defined as parts of it.
It has no externs file available so I started to write one but it is growing quickly. It would be easier to just tell Closure Compiler to not mangle any properties I am setting, including the ones I am setting on objects created by constructors on the object.
EDIT:
Added the name of the library.
Unfortunately it just extracts the first level of methods and does not handle constructors well. By the way, I would like to use Babylon JS (added in the question).
– Gábor Héja
Sep 13 '18 at 2:12
1 Answer
1
The Closure Compiler has no feature that would allow you to say "don't rename any property on this object" except to disable property renaming entirely. The general idea is that it would be very easy for an "unrenamable object" to leak into a loosely typed value ('unknown', Object, etc) and disable renaming for the entire program. And that would make maintaining the expected optimizations for larger projects difficult. However, that is certainly something I would like the team to revisit at some point.
Thank you for your answer! This sounds reasonable, altough having an annotation for it with a "use this only if you know what you're doing" remark would be still useful.
– Gábor Héja
Sep 14 '18 at 13:57
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
How about using an externs generator? github.com/cljsjs/packages/wiki/… -> dotnetwise.com/Code/Externs/index.html
– Graham P Heath
Sep 4 '18 at 15:06