Google 的闭包编译器针对(输出)的 JavaScript 的子集是什么?

What is the subset of JavaScript that is targeted (output) by Google's Closure Compiler?

为了进一步澄清,我的意思是闭包编译器正在输出 JavaScript 的哪些部分?

我完全可以理解这是否是一个移动目标,因为游戏的名称是代码优化,所以如果是这种情况,参考相关的源代码可能是最有用的。

闭包编译器的限制are specified in the docs:

  • The Compiler only recognizes ECMAScript. ECMAScript 5 is the version of JavaScript supported almost everywhere. However the compiler also supports many of the features in ECMAScript 6. The compiler only supports official language features.

    • The Compiler does not preserve comments.
  • When you use with the Compiler can't distinguish between a local variable and an object property of the same name, and so it renames all instances of the name.
  • The Compiler doesn't parse the string argument of eval(), and so it won't rename any symbols within this argument.
  • The Compiler renames functions and function parameters but does not change any strings in your code that refer to functions or parameters by name.
  • In order to rename global variables, functions, and properties correctly, the Compiler must know about all references to those globals. You must tell the Compiler about symbols that are defined outside of the code being compiled. Advanced Compilation and Externs describes how to declare external symbols.
  • Compiled code must export any symbols that uncompiled code refers to. Advanced Compilation and Externs describes how to export symbols.
  • The Compiler renames properties in Advanced mode, but it never renames strings. If you need to refer to a property with a quoted string, always use a quoted string:
  • The Compiler renames properties and variables independently
  • When you compile functions without compiling the code that calls those functions, the Compiler assumes that the functions are never called and removes them.
  • Property flattening can change meaning of the keyword this within a function.
  • Using Object.defineProperties or ES6 getter/setters: The compiler does not understand these constructs well.

关于输出

如果您想使用结果检查语法树 - 但闭包编译器的输出是 ES5 或 ES3,它们不保证输出代码中使用的实际功能。请参阅 Closure Compiler 支持的 "JavaScript " 获得确切支持。