Why does Closure compiler rename properties of an extern type?

被刻印的时光 ゝ 提交于 2019-12-18 19:09:24

问题


I put this in an externs file:

/** @typedef {{english: string, spanish: string}} */
var SpanishNoun;

Then I have javascript:

/**
 * @param {SpanishNoun} n 
 */
exp1.processData3 = function (n) {
    console.log("pd3:", n.english, n.spanish, n['english'], n['spanish']);
}

Which compiles to:

function(a){console.log("pd3:",a.a,a.c,a.english,a.spanish)};

So it still renamed 'english' to 'a', etc. How do you stop that? Why does it think it can rename something that is "extern".

Rob

Follow-up Question

John's answer led to another question: Can I tell the Closure compiler to, for specific types only, stop renaming properties?


回答1:


typedefs don't participate in the renaming calculation

This type definition will:

/** @interface */
function SpanishNoun() {}
/** @type {string} */
SpanishNoun.prototype.english;
/** @type {string} */
SpanishNoun.prototype.spanish;


来源:https://stackoverflow.com/questions/8196243/why-does-closure-compiler-rename-properties-of-an-extern-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!