aboutsummaryrefslogtreecommitdiff
path: root/lib/compress.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/compress.js')
-rw-r--r--lib/compress.js84
1 files changed, 40 insertions, 44 deletions
diff --git a/lib/compress.js b/lib/compress.js
index c28305a4..364bd362 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -1264,6 +1264,9 @@ merge(Compressor.prototype, {
if (node instanceof AST_Exit) {
return side_effects || lhs instanceof AST_PropAccess || may_modify(lhs);
}
+ if (node instanceof AST_Function) {
+ return compressor.option("ie8") && node.name && node.name.name in lvalues;
+ }
if (node instanceof AST_PropAccess) {
return side_effects || node.expression.may_throw_on_access(compressor);
}
@@ -1610,10 +1613,7 @@ merge(Compressor.prototype, {
if (def.orig.length == 1 && def.orig[0] instanceof AST_SymbolDefun) return false;
if (def.scope !== scope) return true;
return !all(def.references, function(ref) {
- var s = ref.scope;
- // "block" scope within AST_Catch
- if (s.TYPE == "Scope") s = s.parent_scope;
- return s === scope;
+ return ref.scope.resolve() === scope;
});
}
@@ -2704,35 +2704,30 @@ merge(Compressor.prototype, {
if (right === this.right) return this;
var result;
switch (this.operator) {
- case "&&" : result = left && right; break;
- case "||" : result = left || right; break;
- case "|" : result = left | right; break;
- case "&" : result = left & right; break;
- case "^" : result = left ^ right; break;
- case "+" : result = left + right; break;
- case "*" : result = left * right; break;
- case "/" : result = left / right; break;
- case "%" : result = left % right; break;
- case "-" : result = left - right; break;
- case "<<" : result = left << right; break;
- case ">>" : result = left >> right; break;
- case ">>>" : result = left >>> right; break;
- case "==" : result = left == right; break;
- case "===" : result = left === right; break;
- case "!=" : result = left != right; break;
- case "!==" : result = left !== right; break;
- case "<" : result = left < right; break;
- case "<=" : result = left <= right; break;
- case ">" : result = left > right; break;
- case ">=" : result = left >= right; break;
- default:
- return this;
- }
- if (isNaN(result) && compressor.find_parent(AST_With)) {
- // leave original expression as is
- return this;
- }
- return result;
+ case "&&" : result = left && right; break;
+ case "||" : result = left || right; break;
+ case "|" : result = left | right; break;
+ case "&" : result = left & right; break;
+ case "^" : result = left ^ right; break;
+ case "+" : result = left + right; break;
+ case "*" : result = left * right; break;
+ case "/" : result = left / right; break;
+ case "%" : result = left % right; break;
+ case "-" : result = left - right; break;
+ case "<<" : result = left << right; break;
+ case ">>" : result = left >> right; break;
+ case ">>>": result = left >>> right; break;
+ case "==" : result = left == right; break;
+ case "===": result = left === right; break;
+ case "!=" : result = left != right; break;
+ case "!==": result = left !== right; break;
+ case "<" : result = left < right; break;
+ case "<=" : result = left <= right; break;
+ case ">" : result = left > right; break;
+ case ">=" : result = left >= right; break;
+ default : return this;
+ }
+ return isNaN(result) && compressor.find_parent(AST_With) ? this : result;
});
def(AST_Conditional, function(compressor, cached, depth) {
var condition = this.condition._eval(compressor, cached, depth);
@@ -3412,6 +3407,14 @@ merge(Compressor.prototype, {
init.walk(tw);
});
}
+ var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) {
+ return !compressor.exposed(def) && !def.references.length;
+ } : function(def) {
+ // any declarations with same name will overshadow
+ // name of this anonymous function and can therefore
+ // never be used anywhere
+ return !(def.id in in_use_ids) || def.orig.length > 1;
+ };
// pass 3: we should drop declarations not in_use
var tt = new TreeTransformer(function(node, descend, in_list) {
var parent = tt.parent();
@@ -3439,15 +3442,8 @@ merge(Compressor.prototype, {
}
}
if (scope !== self) return;
- if (node instanceof AST_Function
- && node.name
- && !compressor.option("ie8")
- && !compressor.option("keep_fnames")) {
- var def = node.name.definition();
- // any declarations with same name will overshadow
- // name of this anonymous function and can therefore
- // never be used anywhere
- if (!(def.id in in_use_ids) || def.orig.length > 1) node.name = null;
+ if (node instanceof AST_Function && node.name && drop_fn_name(node.name.definition())) {
+ node.name = null;
}
if (node instanceof AST_Lambda && !(node instanceof AST_Accessor)) {
var trim = !compressor.option("keep_fargs");
@@ -5726,10 +5722,10 @@ merge(Compressor.prototype, {
if (def) {
return def.optimize(compressor);
}
- // testing against !self.scope.uses_with first is an optimization
if (!compressor.option("ie8")
&& is_undeclared_ref(self)
- && (!self.scope.uses_with || !compressor.find_parent(AST_With))) {
+ // testing against `self.scope.uses_with` is an optimization
+ && !(self.scope.uses_with && compressor.find_parent(AST_With))) {
switch (self.name) {
case "undefined":
return make_node(AST_Undefined, self).optimize(compressor);