improve collapse_vars on side-effect-free replacements (#2583)
This commit is contained in:
@@ -893,10 +893,11 @@ merge(Compressor.prototype, {
|
|||||||
|| node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
|
|| node instanceof AST_Call && lhs instanceof AST_PropAccess && lhs.equivalent_to(node.expression)
|
||||||
|| node instanceof AST_Debugger
|
|| node instanceof AST_Debugger
|
||||||
|| node instanceof AST_IterationStatement && !(node instanceof AST_For)
|
|| node instanceof AST_IterationStatement && !(node instanceof AST_For)
|
||||||
|| node instanceof AST_SymbolRef && !node.is_declared(compressor)
|
|
||||||
|| node instanceof AST_Try
|
|| node instanceof AST_Try
|
||||||
|| node instanceof AST_With
|
|| node instanceof AST_With
|
||||||
|| parent instanceof AST_For && node !== parent.init) {
|
|| parent instanceof AST_For && node !== parent.init
|
||||||
|
|| (side_effects || !replace_all)
|
||||||
|
&& (node instanceof AST_SymbolRef && !node.is_declared(compressor))) {
|
||||||
abort = true;
|
abort = true;
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3805,3 +3805,51 @@ may_throw: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
side_effect_free_replacement: {
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
side_effects: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var b;
|
||||||
|
(function(a) {
|
||||||
|
x(a);
|
||||||
|
})(b);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var b;
|
||||||
|
x(b);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
recursive_function_replacement: {
|
||||||
|
rename = true
|
||||||
|
options = {
|
||||||
|
collapse_vars: true,
|
||||||
|
inline: true,
|
||||||
|
passes: 2,
|
||||||
|
reduce_funcs: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
mangle = {}
|
||||||
|
input: {
|
||||||
|
function f(a) {
|
||||||
|
return x(g(a));
|
||||||
|
}
|
||||||
|
function g(a) {
|
||||||
|
return y(f(a));
|
||||||
|
}
|
||||||
|
console.log(f(c));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f(n) {
|
||||||
|
return x(y(f(n)));
|
||||||
|
}
|
||||||
|
console.log(f(c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user