Note that there are some explanatory texts on larger screens.

plurals
  1. POCan I tell the Closure compiler to, for specific types only, stop renaming properties?
    primarykey
    data
    text
    <p>This question follows: <a href="https://stackoverflow.com/questions/8196243/why-does-closure-compiler-rename-properties-of-an-extern-type/8198809#8198809">Why does Closure compiler rename properties of an extern type?</a> John's answer to that question brings up this second question.</p> <p>If I declare the extern type as suggested:</p> <pre><code>/** @interface */ function SpanishNoun() {} /** @type {string} */ SpanishNoun.prototype.english; /** @type {string} */ SpanishNoun.prototype.spanish; </code></pre> <p>then Javascript like:</p> <pre><code>/** * @param {SpanishNoun} n */ exp.foo = function (n) { console.log(n.english, n.spanish, n['english'], n['spanish']); } </code></pre> <p>will compile, as desired, to:</p> <pre><code>function(a){console.log(a.english,a.spanish,a.english,a.spanish)}; </code></pre> <p>The properties are not renamed as usual. Without the extern declaration, the compiled code would look like:</p> <pre><code>function(a){console.log(a.a,a.c,a.english,a.spanish) </code></pre> <p>That's all good. The problem is that the compiler has stopped renaming 'english' and 'spanish' in <em>all</em> places. Even if they are not on the extern type.</p> <pre><code>/** * @param {AnotherType} */ exp.bar = function (c) { c.other = c.english; } </code></pre> <p>compiles to...</p> <pre><code>function(a){a.b=a.english}; </code></pre> <p>Is there a way to stop this? If not, is there a reason for this behavior? </p> <p>I wanted to use extern types to handle things like JSON objects that originate from the server and do not have renamed properties. But if every time I declare an extern I'm eating away at the compiler's ability to rename and shrink the code, I will find another way. Perhaps I will take the property renaming map generated by the compiler (<code>--property_map_output_file</code>) and use it on the server when generating JSON responses.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload