以下代码:
function f(a) { a.a = 5; return a; }
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
f(function() {});
由 Closure 编译器对此进行了优化:
function a(){return function(){}}function b(c){c.a=5}b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());b(a());
(它留下了死代码。)
但是,如果我删除最后一行(仅重复调用 24 次),它会删除死代码。结果是空的。
如何强制 Closure 编译器在大型项目中也删除所有死代码?