Google Closure Compiler在声明时使用JSC_CONSTANT_REASSIGNED_VALUE_ERROR发出警告

问题描述 投票:1回答:1

我正在使用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,它不会这样做。

有什么想法在这里发生了什么?

javascript ecmascript-6 google-closure-compiler
1个回答
1
投票

这个问题已通过https://github.com/google/closure-compiler/commit/b3146ab187540c5bdf3b24f8ebf6ddede7fd63c5修复

它不再可以与当前版本(或webservice)重现。

© www.soinside.com 2019 - 2024. All rights reserved.