blickly / closure-compiler-issues

0 stars 0 forks source link

Externs affecting unrelated code #120

Closed blickly closed 9 years ago

blickly commented 9 years ago
I've been trying to get ADVNACED_OPTIMIZATIONS on my libraries that uses 
jQuery, I don't wish to compile jQuery together (neither it works well) so 
I decided to use the extern file contanining all jQuery entries 
(http://code.google.com/p/closure-
compiler/source/browse/trunk/contrib/externs/jquery-1.3.2.externs.js)

It works as intended, with one problem. When I comoile this:

/** @constructor */
function LongNamedClass(longnamedparam, longnamedparam2) {
    this.longnamedfield = longnamedparam;
    this.longnamedfield2 = longnamedparam2;
}

LongNamedClass.prototype.addClass = function() {
    alert(this.longnamedfield + "x" + this.longnamedfield2);
}

var longnamedobject = new LongNamedClass(1,2);

longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();
longnamedobject.addClass();

with jQuery externs and advanced compilation, the output is:

function a(c,d){this.a=c;this.b=d}a.prototype.addClass=
function(){alert(this.a+"x"+this.b)};
var b=new a(1,2);
b.addClass();b.addClass();b.addClass();
b.addClass();b.addClass();b.addClass();
b.addClass();b.addClass();

LongNamedClass.prototype.addClass has been renamed to a.prototype.addClass, 
whay is it keeping addClass around in this one? It has nothing to do with 
jQuery.

I believe it is not possible to distinguish between types here so to be in 
the safe side, it just keeps all external symbols as they are. Is there any 
workaround?

Original issue reported on code.google.com by antimon on 2010-03-10 11:22:24

blickly commented 9 years ago
Thanks for the report, but this isn't a defect, just the the way things need to work
without type based property disambiguation enabled. 

Please read through this thread, and see if it answers your questions:
http://groups.google.com/group/closure-compiler-discuss/browse_thread/thread/7267e3857278dd2b/d023f23beeb2b5be?lnk=gst&q=disambiguate#d023f23beeb2b5be

Original issue reported on code.google.com by concavelenz on 2010-03-10 15:57:41