问题描述
为什么用SIMPLE_OPTIMIZATIONS编译后此代码不会导致空字符串
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()})();
if
无法访问,但是闭包编译器不会删除代码.
使用高级优化",结果是我期望的(空),但是简单优化"给出了以上结果.为什么会有这种差异?两种情况下都永远不会执行该代码.
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.
编辑:
如果我删除了闭包,那么if
块也将被删除.为什么关闭时不会发生这种情况?
EDIT:
If I remove the closure, the if
block is removed too. Why with closure this doesn't happen?
推荐答案
我相信,如果使用高级优化",它将被删除.
I believe it would be removed if using "advanced optimizations"
这篇关于Google闭包编译器不会删除标有@define注释的无法访问的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!