为什么Closure编译器重命名extern类型的属性? [英] Why does Closure compiler rename properties of an extern type?

查看:90
本文介绍了为什么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的回答引发了另一个问题:我可以告诉Closure编译器,仅针对特定类型,停止重命名属性吗?

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类型的属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆