Google closure compiler doesn't remove unreachable code marked with @define annotation

久未见 提交于 2019-12-25 03:44:50

问题


Why this code doesn't result in an empty string after compilation with SIMPLE_OPTIMIZATIONS

/**
 * @define {boolean}
 */
var TEST = false;
(function() {
    if (TEST) {
        foo();
    }
})();

and instead I get the following?

var TEST=!1;(function(){TEST&&foo()})();

The if is unreachable but the closure compiler doesn't remove the code.
With "advanced optimizations" the result is what I expect (empty) but "simple optimizations" give the above result. Why this difference? The code will never be executed in both cases.

EDIT:
If I remove the closure, the if block is removed too. Why with closure this doesn't happen?


回答1:


I believe it would be removed if using "advanced optimizations"



来源:https://stackoverflow.com/questions/33241581/google-closure-compiler-doesnt-remove-unreachable-code-marked-with-define-anno

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!