Cleaning up dead code is equivalent to the halting problem in JS
I am proposing to monitor code as it runs in production. This will allow us to be confident in which code is actually getting called, and the inverse: which code is called infrequently. Then we could install probes in code that is suspected to be dead. e.g. explicitly log when the code is called. Then after an appropriately generous period of time (a month or two), if the code still has yet to be called, then we can be more confident when removing it.