compress arguments[index] (#2967)
- always replace with existing parameter - only introduce new parameter if `keep_fargs` is disabled
This commit is contained in:
@@ -48,6 +48,7 @@ function Compressor(options, false_by_default) {
|
||||
return new Compressor(options, false_by_default);
|
||||
TreeTransformer.call(this, this.before, this.after);
|
||||
this.options = defaults(options, {
|
||||
arguments : !false_by_default,
|
||||
booleans : !false_by_default,
|
||||
collapse_vars : !false_by_default,
|
||||
comparisons : !false_by_default,
|
||||
@@ -3551,7 +3552,7 @@ merge(Compressor.prototype, {
|
||||
|
||||
AST_Scope.DEFMETHOD("make_var_name", function(prefix) {
|
||||
var var_names = this.var_names();
|
||||
prefix = prefix.replace(/[^a-z_$]+/ig, "_");
|
||||
prefix = prefix.replace(/(?:^[^a-z_$]|[^a-z0-9_$])/ig, "_");
|
||||
var name = prefix;
|
||||
for (var i = 0; var_names[name]; i++) name = prefix + "$" + i;
|
||||
var_names[name] = true;
|
||||
@@ -5954,6 +5955,31 @@ merge(Compressor.prototype, {
|
||||
});
|
||||
}
|
||||
}
|
||||
var fn;
|
||||
if (compressor.option("arguments")
|
||||
&& expr instanceof AST_SymbolRef
|
||||
&& expr.name == "arguments"
|
||||
&& expr.definition().orig.length == 1
|
||||
&& (fn = expr.scope) instanceof AST_Lambda
|
||||
&& prop instanceof AST_Number) {
|
||||
var index = prop.getValue();
|
||||
var argname = fn.argnames[index];
|
||||
if (!argname && !compressor.option("keep_fargs")) {
|
||||
while (index >= fn.argnames.length) {
|
||||
argname = make_node(AST_SymbolFunarg, fn, {
|
||||
name: fn.make_var_name("argument_" + fn.argnames.length),
|
||||
scope: fn
|
||||
});
|
||||
fn.argnames.push(argname);
|
||||
fn.enclosed.push(fn.def_variable(argname));
|
||||
}
|
||||
}
|
||||
if (argname) {
|
||||
var sym = make_node(AST_SymbolRef, self, argname);
|
||||
sym.reference({});
|
||||
return sym;
|
||||
}
|
||||
}
|
||||
var ev = self.evaluate(compressor);
|
||||
if (ev !== self) {
|
||||
ev = make_node_from_constant(ev, self).optimize(compressor);
|
||||
|
||||
Reference in New Issue
Block a user