简体   繁体   English

Google Closure编译器,某些属性将永远不会重命名?

[英]Google Closure Compiler, some properties will never be renamed?

today I've found an issue related with property rename by the Google Closure Compiler. 今天,我发现一个与Google Closure Compiler重命名属性有关的问题。 Would be happy if somebody could explain me why this code: 如果有人可以解释为什么我会很高兴这样的代码:

// ==ClosureCompiler==
// @compilation_level ADVANCED_OPTIMIZATIONS
// @output_file_name default.js
// ==/ClosureCompiler==

// ADD YOUR CODE HERE


console.info({
  foo: 'bar',
  index: 10,
  bla: 'x'
});

always compiles to: 始终编​​译为:

console.info({b:"bar",index:10,a:"x"});

property "index" will never be renamed to some different name. 属性“索引”将永远不会重命名为其他名称。 The question is why? 问题是为什么? And how to force it's rename? 以及如何强制将其重命名?

Generally, the Closure Compiler can rename based on types. 通常,Closure Compiler可以基于类型进行重命名。 However, it does back off in the face of loose types. 但是,面对松散类型,它确实会退后。 Object literals that are not directly assigned to prototype properties are one of those loose types. 没有直接分配给原型属性的对象文字是那些松散类型之一。 Here it is not renamed because an "index" property exists in the standard externs. 此处未重命名,因为标准extern中存在“ index”属性。 There are several definition but here is one: 有几种定义,但这是一种:

https://github.com/google/closure-compiler/blob/641cf61b99280b8bb4b62ecce873e51208501fec/externs/es3.js#L718 https://github.com/google/closure-compiler/blob/641cf61b99280b8bb4b62ecce873e51208501fec/externs/es3.js#L718

只是没有时间了解这个“非常聪明的逻辑”,我只是将此属性重命名为其他对象未使用的其他属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM