diff options
Diffstat (limited to 'lib/compress.js')
-rw-r--r-- | lib/compress.js | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/lib/compress.js b/lib/compress.js index fa684339..27fcacb0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -70,7 +70,7 @@ function Compressor(options, false_by_default) { hoist_funs : false, hoist_props : !false_by_default, hoist_vars : false, - ie8 : false, + ie : false, if_return : !false_by_default, imports : !false_by_default, inline : !false_by_default, @@ -206,7 +206,7 @@ merge(Compressor.prototype, { var passes = +this.options.passes || 1; var min_count = 1 / 0; var stopping = false; - var mangle = { ie8: this.option("ie8") }; + var mangle = { ie: this.option("ie") }; for (var pass = 0; pass < passes; pass++) { node.figure_out_scope(mangle); if (pass > 0 || this.option("reduce_vars")) @@ -513,7 +513,7 @@ merge(Compressor.prototype, { if (scope.uses_arguments) scope.each_argname(function(node) { node.definition().last_ref = false; }); - if (compressor.option("ie8")) scope.variables.each(function(def) { + if (compressor.option("ie")) scope.variables.each(function(def) { var d = def.orig[0].definition(); if (d !== def) d.fixed = false; }); @@ -2249,7 +2249,7 @@ merge(Compressor.prototype, { return side_effects || lhs instanceof AST_PropAccess || may_modify(lhs); } if (node instanceof AST_Function) { - return compressor.option("ie8") && node.name && lvalues.has(node.name.name); + return compressor.option("ie") && node.name && lvalues.has(node.name.name); } if (node instanceof AST_ObjectIdentity) return symbol_in_lvalues(node, parent); if (node instanceof AST_PropAccess) { @@ -4208,7 +4208,7 @@ merge(Compressor.prototype, { AST_Toplevel.DEFMETHOD("resolve_defines", function(compressor) { if (!compressor.option("global_defs")) return this; - this.figure_out_scope({ ie8: compressor.option("ie8") }); + this.figure_out_scope({ ie: compressor.option("ie") }); return this.transform(new TreeTransformer(function(node) { var def = node._find_defs(compressor, ""); if (!def) return; @@ -5672,7 +5672,7 @@ merge(Compressor.prototype, { if (node instanceof AST_Call) { var exp = node.expression; var tail = exp.tail_node(); - if (!(tail instanceof AST_LambdaExpression)) return; + if (!(tail instanceof AST_LambdaExpression)) return walk_node_with_expr(node); if (exp !== tail) exp.expressions.slice(0, -1).forEach(function(node) { node.walk(tw); }); @@ -5788,6 +5788,7 @@ merge(Compressor.prototype, { pop(); return true; } + if (node instanceof AST_Sub) return walk_node_with_expr(node); if (node instanceof AST_Switch) { node.expression.walk(tw); var save = segment; @@ -5886,6 +5887,15 @@ merge(Compressor.prototype, { pop(); return true; } + + function walk_node_with_expr(node) { + descend(); + if (compressor.option("ie")) { + var sym = root_expr(node.expression); + if (sym instanceof AST_SymbolRef) sym.walk(tw); + } + return true; + } }); tw.directives = Object.create(compressor.directives); self.walk(tw); @@ -6235,7 +6245,7 @@ merge(Compressor.prototype, { }); tw.directives = Object.create(compressor.directives); self.walk(tw); - var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie8") ? function(def) { + var drop_fn_name = compressor.option("keep_fnames") ? return_false : compressor.option("ie") ? function(def) { return !compressor.exposed(def) && def.references.length == def.replaced; } : function(def) { if (!(def.id in in_use_ids)) return true; @@ -6247,7 +6257,7 @@ merge(Compressor.prototype, { return !ref.in_arg; }); }; - if (compressor.option("ie8")) initializations.each(function(init, id) { + if (compressor.option("ie")) initializations.each(function(init, id) { if (id in in_use_ids) return; init.forEach(function(init) { init.walk(new TreeWalker(function(node) { @@ -6535,7 +6545,7 @@ merge(Compressor.prototype, { head.push(def); } } else if (compressor.option("functions") - && !compressor.option("ie8") + && !compressor.option("ie") && drop_sym && var_defs[sym.id] == 1 && sym.assignments == 0 @@ -7652,7 +7662,7 @@ merge(Compressor.prototype, { }); function fn_name_unused(fn, compressor) { - if (!fn.name || !compressor.option("ie8")) return true; + if (!fn.name || !compressor.option("ie")) return true; var def = fn.name.definition(); if (compressor.exposed(def)) return false; return all(def.references, function(sym) { @@ -7969,7 +7979,7 @@ merge(Compressor.prototype, { var alternative = this.alternative.drop_side_effect_free(compressor); if (consequent === this.consequent && alternative === this.alternative) return this; var exprs; - if (compressor.option("ie8")) { + if (compressor.option("ie")) { exprs = []; if (consequent instanceof AST_Function) { exprs.push(consequent); @@ -7998,7 +8008,7 @@ merge(Compressor.prototype, { node.consequent = consequent; node.alternative = alternative; } - if (!compressor.option("ie8")) return node; + if (!compressor.option("ie")) return node; if (node) exprs.push(node); return exprs.length == 0 ? null : make_sequence(this, exprs); }); @@ -9411,7 +9421,7 @@ merge(Compressor.prototype, { return arg.value; }).join() + "){" + self.args[self.args.length - 1].value + "})"; var ast = parse(code); - var mangle = { ie8: compressor.option("ie8") }; + var mangle = { ie: compressor.option("ie") }; ast.figure_out_scope(mangle); var comp = new Compressor(compressor.options); ast = ast.transform(comp); @@ -10465,7 +10475,7 @@ merge(Compressor.prototype, { && self.right.operator == "typeof") { var expr = self.right.expression; if (expr instanceof AST_SymbolRef ? expr.is_declared(compressor) - : !(expr instanceof AST_PropAccess && compressor.option("ie8"))) { + : !(expr instanceof AST_PropAccess && compressor.option("ie"))) { self.right = expr; self.left = make_node(AST_Undefined, self.left).optimize(compressor); if (self.operator.length == 2) self.operator += "="; @@ -11079,7 +11089,7 @@ merge(Compressor.prototype, { } OPT(AST_SymbolRef, function(self, compressor) { - if (!compressor.option("ie8") + if (!compressor.option("ie") && is_undeclared_ref(self) // testing against `self.scope.uses_with` is an optimization && !(self.scope.resolve().uses_with && compressor.find_parent(AST_With))) { @@ -11121,7 +11131,7 @@ merge(Compressor.prototype, { single_use = false; } else if (fixed.has_side_effects(compressor)) { single_use = false; - } else if (compressor.option("ie8") && fixed instanceof AST_Class) { + } else if (compressor.option("ie") && fixed instanceof AST_Class) { single_use = false; } if (single_use) fixed.parent_scope = self.scope; |