@@ -8243,7 +8243,7 @@ merge(Compressor.prototype, {
|
||||
if (compressor.option("side_effects")
|
||||
&& can_drop
|
||||
&& all(fn.body, is_empty)
|
||||
&& (fn === exp ? fn_name_unused(fn, compressor) : !has_default && !has_destructured)
|
||||
&& (fn === exp ? fn_name_unused(fn, compressor) : !fn.rest && !has_default && !has_destructured)
|
||||
&& !(is_arrow(fn) && fn.value)) {
|
||||
return make_sequence(self, convert_args()).optimize(compressor);
|
||||
}
|
||||
@@ -8286,7 +8286,7 @@ merge(Compressor.prototype, {
|
||||
|
||||
function convert_args(value) {
|
||||
var args = self.args.slice();
|
||||
var destructured = has_default > 1 || has_destructured;
|
||||
var destructured = fn.rest || has_default > 1 || has_destructured;
|
||||
if (destructured || has_spread) args = [ make_node(AST_Array, self, { elements: args }) ];
|
||||
if (destructured) {
|
||||
var tt = new TreeTransformer(function(node, descend) {
|
||||
@@ -8332,10 +8332,15 @@ merge(Compressor.prototype, {
|
||||
argname = argname.transform(tt);
|
||||
if (argname) lhs[index] = argname;
|
||||
});
|
||||
var rest = fn.rest && fn.rest.transform(tt);
|
||||
if (rest) lhs.length = fn.argnames.length;
|
||||
fill_holes(fn, lhs);
|
||||
args[0] = make_node(AST_Assign, self, {
|
||||
operator: "=",
|
||||
left: make_node(AST_DestructuredArray, fn, { elements: lhs }),
|
||||
left: make_node(AST_DestructuredArray, fn, {
|
||||
elements: lhs,
|
||||
rest: rest,
|
||||
}),
|
||||
right: args[0],
|
||||
});
|
||||
} else fn.argnames.forEach(function(argname) {
|
||||
|
||||
@@ -600,3 +600,49 @@ issue_4538: {
|
||||
expect_stdout: "function"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_4544_1: {
|
||||
options = {
|
||||
keep_fnames: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
(function f(...[ {} ]) {})();
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
[ ...[ {} ] ] = [];
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
issue_4544_2: {
|
||||
options = {
|
||||
keep_fnames: true,
|
||||
side_effects: true,
|
||||
}
|
||||
input: {
|
||||
try {
|
||||
(function f(a, ...[ {} ]) {})([]);
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect: {
|
||||
try {
|
||||
[ , ...[ {} ] ] = [ [] ];
|
||||
} catch (e) {
|
||||
console.log("PASS");
|
||||
}
|
||||
}
|
||||
expect_stdout: "PASS"
|
||||
node_version: ">=6"
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user