gpt4 book ai didi

javascript - Google 的 Closure 编译器针对(输出)的 JavaScript 子集是什么?

转载 作者:行者123 更新时间:2023-11-30 08:23:35 24 4
gpt4 key购买 nike

为了进一步澄清,我的意思是 Closure 编译器正在输出 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,它们不保证输出代码中使用的实际功能。参见 "JavaScript supported by Closure Compiler"以获得确切的支持。

关于javascript - Google 的 Closure 编译器针对(输出)的 JavaScript 子集是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49563294/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com