本文介绍了为什么Closure编译器重命名extern类型的属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把它放在externs文件中:

I put this in an externs file:

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

然后我有javascript:

Then I have javascript:

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

编译为:

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

所以它仍然将'english'重命名为'a'等等。你如何阻止它?为什么它认为它可以重命名为extern的东西。

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

John的回答引发了另一个问题:

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

推荐答案

typedef不参与重命名计算

typedefs don't participate in the renaming calculation

此类型定义将:

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

这篇关于为什么Closure编译器重命名extern类型的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 21:37
查看更多