我正在使用Google Closure Compiler来缩小以下代码:
{
let x = 10,
y = 20;
console.log(y);
}
{
let x = 30,
y = 40;
console.log(y);
}
(另请参阅this link到Closure Compiler Web应用程序。)
令我感到不安的是,编译器发出以下警告:
JSC_CONSTANT_REASSIGNED_VALUE_ERROR: constant y assigned a value more than once.
Original definition at Input_0:4 at line 10 character 6
y = 40;
^
这提出了多个问题:
let
声明的任何内容都无效吗?y
而不针对x
?y
称为“常数”?我从未在这个片段中的任何地方声明过常量。这是ES5语法中的输出代码:
var x=10,y=20;console.log(y);var x$0=30;y=40;console.log(y);
实际上,Google Closure Compiler重用了第一个块中的y
变量。但是,对于x
,它不会这样做。
有什么想法在这里发生了什么?
这个问题已通过https://github.com/google/closure-compiler/commit/b3146ab187540c5bdf3b24f8ebf6ddede7fd63c5修复
它不再可以与当前版本(或webservice)重现。