Google Closure and GWT both do exactly that - they use static analysis to cull code which never gets called. You can't use them with standard JS libs though - JS code needs to be specially marked up to use that feature in Closure, and GWT development is in Java.
GWT takes the idea one step further - the code splitting functionality lets you define split points, and code that only ever gets called behind the split point does not need to be downloaded on page load, but can instead be downloaded when that split point is first reached.