簡體   English   中英

Google Closure編譯器,某些屬性將永遠不會重命名?

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

今天,我發現一個與Google Closure Compiler重命名屬性有關的問題。 如果有人可以解釋為什么我會很高興這樣的代碼:

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

// ADD YOUR CODE HERE


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

始終編​​譯為:

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

屬性“索引”將永遠不會重命名為其他名稱。 問題是為什么? 以及如何強制將其重命名?

通常,Closure Compiler可以基於類型進行重命名。 但是,面對松散類型,它確實會退后。 沒有直接分配給原型屬性的對象文字是那些松散類型之一。 此處未重命名,因為標准extern中存在“ index”屬性。 有幾種定義,但這是一種:

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