improve reduce_vars (#2592)

- account for hoisting nature of `var`
This commit is contained in:
Alex Lam S.L
2017-12-14 15:32:13 +08:00
committed by GitHub
parent 738fd52bc4
commit 02a6ce07eb
2 changed files with 61 additions and 4 deletions

View File

@@ -381,7 +381,10 @@ merge(Compressor.prototype, {
&& node.operator == "="
&& node.left instanceof AST_SymbolRef) {
var d = node.left.definition();
if (safe_to_assign(d, node.right)) {
if (safe_to_assign(d, node.right)
|| d.fixed === undefined && all(d.orig, function(sym) {
return sym instanceof AST_SymbolVar;
})) {
d.references.push(node.left);
d.fixed = function() {
return node.right;
@@ -561,9 +564,9 @@ merge(Compressor.prototype, {
if (!safe_to_read(def)) return false;
if (def.fixed === false) return false;
if (def.fixed != null && (!value || def.references.length > 0)) return false;
return !def.orig.some(function(sym) {
return sym instanceof AST_SymbolDefun
|| sym instanceof AST_SymbolLambda;
return all(def.orig, function(sym) {
return !(sym instanceof AST_SymbolDefun
|| sym instanceof AST_SymbolLambda);
});
}