Google Closure Compiler 在 let 声明时用 JSC_CONSTANT_REASSIGNED_VALUE_ERROR 警告
Google Closure Compiler warns with JSC_CONSTANT_REASSIGNED_VALUE_ERROR on let declarations
我正在使用 Google Closure Compiler 来缩小以下代码:
{
let x = 10,
y = 20;
console.log(y);
}
{
let x = 30,
y = 40;
console.log(y);
}
(另请参阅 Closure Compiler Web 应用程序的 this link。)
令我莫名其妙的是,编译器给出了以下警告:
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
称为 "constant"?我从未在此片段中的任何地方声明常量。
这是ES5语法的输出代码:
var x=10,y=20;console.log(y);var x[=14=]=30;y=40;console.log(y);
确实,Google Closure Compiler 重用了第一个块中的 y
变量。但是,它不会为 x
执行此操作。
知道这里发生了什么吗?
此问题已修复
https://github.com/google/closure-compiler/commit/b3146ab187540c5bdf3b24f8ebf6ddede7fd63c5
当前版本(或网络服务)不再可重现。
我正在使用 Google Closure Compiler 来缩小以下代码:
{
let x = 10,
y = 20;
console.log(y);
}
{
let x = 30,
y = 40;
console.log(y);
}
(另请参阅 Closure Compiler Web 应用程序的 this link。)
令我莫名其妙的是,编译器给出了以下警告:
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
称为 "constant"?我从未在此片段中的任何地方声明常量。
这是ES5语法的输出代码:
var x=10,y=20;console.log(y);var x[=14=]=30;y=40;console.log(y);
确实,Google Closure Compiler 重用了第一个块中的 y
变量。但是,它不会为 x
执行此操作。
知道这里发生了什么吗?
此问题已修复 https://github.com/google/closure-compiler/commit/b3146ab187540c5bdf3b24f8ebf6ddede7fd63c5
当前版本(或网络服务)不再可重现。