drop argument value after collapse_vars (#2190)

This commit is contained in:
Alex Lam S.L
2017-07-02 04:28:11 +08:00
committed by GitHub
parent d40950b741
commit 8b69a3d18e
3 changed files with 52 additions and 5 deletions

View File

@@ -902,6 +902,14 @@ merge(Compressor.prototype, {
} }
function remove_candidate(expr) { function remove_candidate(expr) {
if (expr.name instanceof AST_SymbolFunarg) {
var index = compressor.self().argnames.indexOf(expr.name);
var args = compressor.parent().args;
if (args[index]) args[index] = make_node(AST_Number, args[index], {
value: 0
});
return true;
}
var found = false; var found = false;
return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) { return statements[stat_index].transform(new TreeTransformer(function(node, descend, in_list) {
if (found) return node; if (found) return node;
@@ -3205,7 +3213,7 @@ merge(Compressor.prototype, {
var value = stat.value; var value = stat.value;
if (!value || value.is_constant_expression()) { if (!value || value.is_constant_expression()) {
var args = self.args.concat(value || make_node(AST_Undefined, self)); var args = self.args.concat(value || make_node(AST_Undefined, self));
return make_sequence(self, args).transform(compressor); return make_sequence(self, args).optimize(compressor);
} }
} }
if (exp instanceof AST_Function) { if (exp instanceof AST_Function) {
@@ -3246,12 +3254,12 @@ merge(Compressor.prototype, {
} }
if (value) { if (value) {
var args = self.args.concat(value); var args = self.args.concat(value);
return make_sequence(self, args).transform(compressor); return make_sequence(self, args).optimize(compressor);
} }
} }
if (compressor.option("side_effects") && all(exp.body, is_empty)) { if (compressor.option("side_effects") && all(exp.body, is_empty)) {
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).transform(compressor); return make_sequence(self, args).optimize(compressor);
} }
} }
if (compressor.option("drop_console")) { if (compressor.option("drop_console")) {

View File

@@ -2187,7 +2187,7 @@ compound_assignment: {
expect_stdout: "4" expect_stdout: "4"
} }
issue_2187: { issue_2187_1: {
options = { options = {
collapse_vars: true, collapse_vars: true,
unused: true, unused: true,
@@ -2217,3 +2217,42 @@ issue_2187: {
"2", "2",
] ]
} }
issue_2187_2: {
options = {
collapse_vars: true,
unused: true,
}
input: {
var b = 1;
console.log(function(a) {
return a && ++b;
}(b--));
}
expect: {
var b = 1;
console.log(function(a) {
return b-- && ++b;
}());
}
expect_stdout: "1"
}
issue_2187_3: {
options = {
collapse_vars: true,
inline: true,
unused: true,
}
input: {
var b = 1;
console.log(function(a) {
return a && ++b;
}(b--));
}
expect: {
var b = 1;
console.log(b-- && ++b);
}
expect_stdout: "1"
}

View File

@@ -1113,7 +1113,7 @@ issue_2105: {
options = { options = {
collapse_vars: true, collapse_vars: true,
inline: true, inline: true,
passes: 2, passes: 3,
reduce_vars: true, reduce_vars: true,
side_effects: true, side_effects: true,
unused: true, unused: true,