uiuniversal/ngu-carousel

Mixed string and dot references to properties causes problems with minification

plamoni opened this issue · 2 comments

I'm using nguCarousel in an environment where we compile code through the Google Closure Compiler with ADVANCED_OPTIMIZATIONS enabled.

Due to the mix of dot-references (e.g. breakpoints.xl) and string-references (e.g. breakpoints['xl']) to properties, it breaks in production mode (because the dot-references get re-written and the string references are left alone).

Working on determining a clean solution to this, though one option would be to use string-references (e.g. breakpoints['xl']) everywhere. Will add a pull request shortly.

Added a pull request that fixes the issue without any runtime side effects. Also tested locally and confirmed that the carousel now works nicely with optimizations enabled.

Please merge at your earliest convenience if appropriate.

Thank you!!!

Some clarifications:

Normal TypeScript code isn't really affected by this. But all code internally at Google needs to go through JSCompiler, and one of the optimizations is very aggressive property renaming. For example, this.myValue will get renamed to this.xa, and trying to access this['myValue'] will throw an error. declare interface is the trick that's used to tell the compiler to skip property renaming for that particular interface. And as the class implements the interface, the skip carries through.

This should be a no-op for a typical TypeScript user, only affecting our particular toolchain.