AFAIK Google Closure Compiler [1] does similar things automagically.
[1] https://github.com/google/closure-compiler