@@ -4167,6 +4167,15 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function safe_to_drop(fn, compressor) {
|
||||||
|
if (!fn.name || !compressor.option("ie8")) return true;
|
||||||
|
var def = fn.name.definition();
|
||||||
|
if (compressor.exposed(def)) return false;
|
||||||
|
return all(def.references, function(sym) {
|
||||||
|
return !(sym instanceof AST_SymbolRef);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// drop_side_effect_free()
|
// drop_side_effect_free()
|
||||||
// remove side-effect-free parts which only affects return value
|
// remove side-effect-free parts which only affects return value
|
||||||
(function(def) {
|
(function(def) {
|
||||||
@@ -4284,7 +4293,7 @@ merge(Compressor.prototype, {
|
|||||||
return expr.drop_side_effect_free(compressor, first_in_statement);
|
return expr.drop_side_effect_free(compressor, first_in_statement);
|
||||||
});
|
});
|
||||||
def(AST_Function, function(compressor) {
|
def(AST_Function, function(compressor) {
|
||||||
return this.name && compressor.option("ie8") ? this : null;
|
return safe_to_drop(this, compressor) ? null : this;
|
||||||
});
|
});
|
||||||
def(AST_Object, function(compressor, first_in_statement) {
|
def(AST_Object, function(compressor, first_in_statement) {
|
||||||
var values = trim(this.properties, compressor, first_in_statement);
|
var values = trim(this.properties, compressor, first_in_statement);
|
||||||
@@ -5170,7 +5179,9 @@ merge(Compressor.prototype, {
|
|||||||
fn._squeezed = true;
|
fn._squeezed = true;
|
||||||
return make_sequence(self, flatten_fn()).optimize(compressor);
|
return make_sequence(self, flatten_fn()).optimize(compressor);
|
||||||
}
|
}
|
||||||
if (compressor.option("side_effects") && all(fn.body, is_empty)) {
|
if (compressor.option("side_effects")
|
||||||
|
&& all(fn.body, is_empty)
|
||||||
|
&& (fn !== exp || safe_to_drop(fn, compressor))) {
|
||||||
var args = self.args.concat(make_node(AST_Undefined, self));
|
var args = self.args.concat(make_node(AST_Undefined, self));
|
||||||
return make_sequence(self, args).optimize(compressor);
|
return make_sequence(self, args).optimize(compressor);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -202,7 +202,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options) {
|
|||||||
if (node instanceof AST_SymbolLambda) {
|
if (node instanceof AST_SymbolLambda) {
|
||||||
var def = node.thedef;
|
var def = node.thedef;
|
||||||
redefine(node, node.scope.parent_scope.resolve());
|
redefine(node, node.scope.parent_scope.resolve());
|
||||||
node.thedef.init = def.init;
|
if (def.init) node.thedef.init = def.init;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
|
|||||||
@@ -1683,3 +1683,161 @@ issue_3482_2_ie8: {
|
|||||||
}
|
}
|
||||||
expect_stdout: "NaN NaN NaN"
|
expect_stdout: "NaN NaN NaN"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_3484_1: {
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {})();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_1_ie8: {
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {})();
|
||||||
|
// IE8: function
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function f() {})();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_1_toplevel: {
|
||||||
|
options = {
|
||||||
|
ie8: false,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {})();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_1_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
ie8: true,
|
||||||
|
side_effects: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function f() {})();
|
||||||
|
// IE8: function
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function f() {})();
|
||||||
|
console.log(typeof f);
|
||||||
|
}
|
||||||
|
expect_stdout: "undefined"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
ie8: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log(typeof (1 / 0), typeof Infinity);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log("number", "number");
|
||||||
|
}
|
||||||
|
expect_stdout: "number number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_2_ie8: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
ie8: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: false,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
// IE8: number function
|
||||||
|
console.log(typeof (1 / 0), typeof Infinity);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log("number", typeof Infinity);
|
||||||
|
}
|
||||||
|
expect_stdout: "number number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_2_toplevel: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
ie8: false,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log(typeof (1 / 0), typeof Infinity);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log("number", "number");
|
||||||
|
}
|
||||||
|
expect_stdout: "number number"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_3484_2_ie8_toplevel: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
ie8: true,
|
||||||
|
reduce_vars: true,
|
||||||
|
toplevel: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
// IE8: number function
|
||||||
|
console.log(typeof (1 / 0), typeof Infinity);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
(function Infinity() {
|
||||||
|
var Infinity;
|
||||||
|
})();
|
||||||
|
console.log("number", typeof Infinity);
|
||||||
|
}
|
||||||
|
expect_stdout: "number number"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user