scan assignment value in drop_unused() (#1578)
those were not optimised for `unused` before, which made it necessary for `reduce_vars` to have separate steps for `keep_fnames` docs update by @kzc closes #1577
This commit is contained in:
@@ -391,11 +391,11 @@ to set `true`; it's effectively a shortcut for `foo=true`).
|
|||||||
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
|
- `cascade` -- small optimization for sequences, transform `x, x` into `x`
|
||||||
and `x = something(), x` into `x = something()`
|
and `x = something(), x` into `x = something()`
|
||||||
|
|
||||||
- `collapse_vars` -- default `false`. Collapse single-use `var` and `const`
|
- `collapse_vars` -- Collapse single-use `var` and `const` definitions
|
||||||
definitions when possible.
|
when possible.
|
||||||
|
|
||||||
- `reduce_vars` -- default `false`. Improve optimization on variables assigned
|
- `reduce_vars` -- Improve optimization on variables assigned with and
|
||||||
with and used as constant values.
|
used as constant values.
|
||||||
|
|
||||||
- `warnings` -- display warnings when dropping unreachable code or unused
|
- `warnings` -- display warnings when dropping unreachable code or unused
|
||||||
declarations etc.
|
declarations etc.
|
||||||
|
|||||||
@@ -1840,6 +1840,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) {
|
if (drop_vars && node instanceof AST_Definitions && !(tt.parent() instanceof AST_ForIn)) {
|
||||||
var def = node.definitions.filter(function(def){
|
var def = node.definitions.filter(function(def){
|
||||||
|
if (def.value) def.value = def.value.transform(tt);
|
||||||
if (def.name.definition().id in in_use_ids) return true;
|
if (def.name.definition().id in in_use_ids) return true;
|
||||||
var w = {
|
var w = {
|
||||||
name : def.name.name,
|
name : def.name.name,
|
||||||
@@ -2611,10 +2612,6 @@ merge(Compressor.prototype, {
|
|||||||
if (compressor.option("unused")
|
if (compressor.option("unused")
|
||||||
&& def.references.length == 1
|
&& def.references.length == 1
|
||||||
&& compressor.find_parent(AST_Scope) === def.scope) {
|
&& compressor.find_parent(AST_Scope) === def.scope) {
|
||||||
if (!compressor.option("keep_fnames")
|
|
||||||
&& exp.name && exp.name.definition() === def) {
|
|
||||||
exp.name = null;
|
|
||||||
}
|
|
||||||
self.expression = exp;
|
self.expression = exp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -700,3 +700,28 @@ issue_1539: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vardef_value: {
|
||||||
|
options = {
|
||||||
|
keep_fnames: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
unused: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
function f() {
|
||||||
|
function g(){
|
||||||
|
return x();
|
||||||
|
}
|
||||||
|
var a = g();
|
||||||
|
return a(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
function f() {
|
||||||
|
var a = function(){
|
||||||
|
return x();
|
||||||
|
}();
|
||||||
|
return a(42);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user