improve keep_fargs & keep_fnames
- utilise in_use_ids instead of unreferenced() - drop_unused now up-to-date for subsequent passes
This commit is contained in:
parent
7f8d72d9d3
commit
cd167d112d
|
|
@ -1413,7 +1413,7 @@ merge(Compressor.prototype, {
|
||||||
&& !self.uses_with
|
&& !self.uses_with
|
||||||
) {
|
) {
|
||||||
var in_use = [];
|
var in_use = [];
|
||||||
var in_use_ids = {}; // avoid expensive linear scans of in_use
|
var in_use_ids = Object.create(null); // avoid expensive linear scans of in_use
|
||||||
var initializations = new Dictionary();
|
var initializations = new Dictionary();
|
||||||
// pass 1: find out which symbols are directly used in
|
// pass 1: find out which symbols are directly used in
|
||||||
// this scope (not in nested scopes).
|
// this scope (not in nested scopes).
|
||||||
|
|
@ -1477,11 +1477,17 @@ merge(Compressor.prototype, {
|
||||||
// pass 3: we should drop declarations not in_use
|
// pass 3: we should drop declarations not in_use
|
||||||
var tt = new TreeTransformer(
|
var tt = new TreeTransformer(
|
||||||
function before(node, descend, in_list) {
|
function before(node, descend, in_list) {
|
||||||
|
if (node instanceof AST_Function
|
||||||
|
&& node.name
|
||||||
|
&& !compressor.option("keep_fnames")
|
||||||
|
&& !(node.name.definition().id in in_use_ids)) {
|
||||||
|
node.name = null;
|
||||||
|
}
|
||||||
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
|
||||||
if (!compressor.option("keep_fargs")) {
|
if (!compressor.option("keep_fargs")) {
|
||||||
for (var a = node.argnames, i = a.length; --i >= 0;) {
|
for (var a = node.argnames, i = a.length; --i >= 0;) {
|
||||||
var sym = a[i];
|
var sym = a[i];
|
||||||
if (sym.unreferenced()) {
|
if (!(sym.definition().id in in_use_ids)) {
|
||||||
a.pop();
|
a.pop();
|
||||||
compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
compressor.warn("Dropping unused function argument {name} [{file}:{line},{col}]", {
|
||||||
name : sym.name,
|
name : sym.name,
|
||||||
|
|
@ -2102,16 +2108,6 @@ merge(Compressor.prototype, {
|
||||||
return self;
|
return self;
|
||||||
});
|
});
|
||||||
|
|
||||||
OPT(AST_Function, function(self, compressor){
|
|
||||||
self = AST_Lambda.prototype.optimize.call(self, compressor);
|
|
||||||
if (compressor.option("unused") && !compressor.option("keep_fnames")) {
|
|
||||||
if (self.name && self.name.unreferenced()) {
|
|
||||||
self.name = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return self;
|
|
||||||
});
|
|
||||||
|
|
||||||
OPT(AST_Call, function(self, compressor){
|
OPT(AST_Call, function(self, compressor){
|
||||||
if (compressor.option("unsafe")) {
|
if (compressor.option("unsafe")) {
|
||||||
var exp = self.expression;
|
var exp = self.expression;
|
||||||
|
|
|
||||||
|
|
@ -177,3 +177,37 @@ keep_fnames: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop_fargs: {
|
||||||
|
options = {
|
||||||
|
keep_fargs: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
var b = a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
drop_fnames: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: false,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
return function g() {
|
||||||
|
var a = g;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
return function() {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user