简体   繁体   English

为什么Closure编译器重命名extern类型的属性?

[英]Why does Closure compiler rename properties of an extern type?

I put this in an externs file: 我把它放在externs文件中:

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

Then I have javascript: 然后我有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? 所以它仍然将'english'重命名为'a'等等。你如何阻止它? 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? John的回答引出了另一个问题: 我可以告诉Closure编译器,仅针对特定类型,停止重命名属性吗?

typedefs don't participate in the renaming calculation typedef不参与重命名计算

This type definition will: 此类型定义将:

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

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

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