closure-compiler
closure-compiler copied to clipboard
Not removing or renaming unused portions of Closure Library
This is a simple example.
goog.require('goog.math.Coordinate');
goog.require('goog.math.Vec2');
var a = new goog.math.Coordinate(4, 7);
var b = new goog.math.Vec2(0, -1);
var c = goog.math.Coordinate.sum(a, b);
alert(c);
Everything works fine with advanced optimization, except that unused functions, like translate
and scale
are not removed or even renamed.
Can you share what compiler options you're using?
The repro link you have is using "Simple" optimization flags. In "Simple" mode, unused prototype properties are not removed; you need to use "Advanced" mode for that (though be aware that that comes with a number of caveats/requirements).
It was supposed to be Advanced mode, I think switching it is not reflected in the URL.
I see, and I can reproduce. The compilation result is:
/*
Copyright The Closure Library Authors.
SPDX-License-Identifier: Apache-2.0
*/
var c;
function d(a, b) {
function e() {
}
e.prototype = b.prototype;
a.b = b.prototype;
a.prototype = new e;
a.prototype.constructor = a;
a.a = function(n, p, q) {
for (var h = Array(arguments.length - 2), f = 2; f < arguments.length; f++) {
h[f - 2] = arguments[f];
}
return b.prototype[p].apply(n, h);
};
}
;function g(a, b) {
this.x = void 0 !== a ? a : 0;
this.y = void 0 !== b ? b : 0;
}
c = g.prototype;
c.clone = function() {
return new g(this.x, this.y);
};
c.toString = function() {
return "(" + this.x + ", " + this.y + ")";
};
c.ceil = function() {
this.x = Math.ceil(this.x);
this.y = Math.ceil(this.y);
return this;
};
c.floor = function() {
this.x = Math.floor(this.x);
this.y = Math.floor(this.y);
return this;
};
c.round = function() {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
return this;
};
c.translate = function(a, b) {
a instanceof g ? (this.x += a.x, this.y += a.y) : (this.x += Number(a), "number" === typeof b && (this.y += b));
return this;
};
c.scale = function(a, b) {
this.x *= a;
this.y *= "number" === typeof b ? b : a;
return this;
};
function k(a, b) {
this.x = a;
this.y = b;
}
d(k, g);
c = k.prototype;
c.clone = function() {
return new k(this.x, this.y);
};
c.scale = g.prototype.scale;
c.normalize = function() {
return this.scale(1 / Math.sqrt(this.x * this.x + this.y * this.y));
};
c.add = function(a) {
this.x += a.x;
this.y += a.y;
return this;
};
c.rotate = function(a) {
var b = Math.cos(a);
a = Math.sin(a);
var e = this.y * b + this.x * a;
this.x = this.x * b - this.y * a;
this.y = e;
return this;
};
var l = new g(4, 7), m = new k(0, -1);
alert(new g(l.x + m.x, l.y + m.y));