@@ -4368,6 +4368,7 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
return !(sym instanceof AST_Destructured);
|
return !(sym instanceof AST_Destructured);
|
||||||
})) return this;
|
})) return this;
|
||||||
|
if (fn.rest instanceof AST_Destructured) return this;
|
||||||
if (!args && !ignore_side_effects) return this;
|
if (!args && !ignore_side_effects) return this;
|
||||||
var stat = fn.first_statement();
|
var stat = fn.first_statement();
|
||||||
if (!(stat instanceof AST_Return)) {
|
if (!(stat instanceof AST_Return)) {
|
||||||
@@ -4394,18 +4395,8 @@ merge(Compressor.prototype, {
|
|||||||
if (!val) return;
|
if (!val) return;
|
||||||
var cached_args = [];
|
var cached_args = [];
|
||||||
if (!args || all(fn.argnames, function(sym, i) {
|
if (!args || all(fn.argnames, function(sym, i) {
|
||||||
if (sym instanceof AST_DefaultValue) sym = sym.name;
|
return assign(sym, args[i]);
|
||||||
var def = sym.definition();
|
}) && !(fn.rest && !assign(fn.rest, args.slice(fn.argnames.length))) || ignore_side_effects) {
|
||||||
if (def.orig[def.orig.length - 1] !== sym) return false;
|
|
||||||
var value = args[i];
|
|
||||||
def.references.forEach(function(node) {
|
|
||||||
node._eval = function() {
|
|
||||||
return value;
|
|
||||||
};
|
|
||||||
cached_args.push(node);
|
|
||||||
});
|
|
||||||
return true;
|
|
||||||
}) || ignore_side_effects) {
|
|
||||||
fn.evaluating = true;
|
fn.evaluating = true;
|
||||||
val = val._eval(compressor, ignore_side_effects, cached, depth);
|
val = val._eval(compressor, ignore_side_effects, cached, depth);
|
||||||
delete fn.evaluating;
|
delete fn.evaluating;
|
||||||
@@ -4450,6 +4441,20 @@ merge(Compressor.prototype, {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
|
|
||||||
|
function assign(sym, arg) {
|
||||||
|
if (sym instanceof AST_DefaultValue) sym = sym.name;
|
||||||
|
var def = sym.definition();
|
||||||
|
if (def.orig[def.orig.length - 1] !== sym) return false;
|
||||||
|
var value = arg;
|
||||||
|
def.references.forEach(function(node) {
|
||||||
|
node._eval = function() {
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
cached_args.push(node);
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
def(AST_New, return_this);
|
def(AST_New, return_this);
|
||||||
def(AST_Template, function(compressor, ignore_side_effects, cached, depth) {
|
def(AST_Template, function(compressor, ignore_side_effects, cached, depth) {
|
||||||
|
|||||||
@@ -714,3 +714,52 @@ issue_4621: {
|
|||||||
expect_stdout: "PASS"
|
expect_stdout: "PASS"
|
||||||
node_version: ">=6"
|
node_version: ">=6"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_4644_1: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
var a = "FAIL";
|
||||||
|
(function f(b, ...{
|
||||||
|
[a = "PASS"]: c,
|
||||||
|
}) {
|
||||||
|
return b;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
var a = "FAIL";
|
||||||
|
(function f(b, ...{
|
||||||
|
[a = "PASS"]: c,
|
||||||
|
}) {
|
||||||
|
return b;
|
||||||
|
})();
|
||||||
|
console.log(a);
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|
||||||
|
issue_4644_2: {
|
||||||
|
options = {
|
||||||
|
evaluate: true,
|
||||||
|
unsafe: true,
|
||||||
|
}
|
||||||
|
input: {
|
||||||
|
console.log(function(...a) {
|
||||||
|
return a[1];
|
||||||
|
}("FAIL", "PASS"), function(...b) {
|
||||||
|
return b.length;
|
||||||
|
}(), function(c, ...d) {
|
||||||
|
return d[0];
|
||||||
|
}("FAIL"));
|
||||||
|
}
|
||||||
|
expect: {
|
||||||
|
console.log("PASS", 0, function(c, ...d) {
|
||||||
|
return d[0];
|
||||||
|
}("FAIL"));
|
||||||
|
}
|
||||||
|
expect_stdout: "PASS 0 undefined"
|
||||||
|
node_version: ">=6"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user