fix corner case in inline (#4007)

fixes #4006
This commit is contained in:
Alex Lam S.L
2020-06-29 02:06:23 +01:00
committed by GitHub
parent 58c24f8007
commit 3bf8699f95
3 changed files with 37 additions and 10 deletions

View File

@@ -6415,17 +6415,12 @@ merge(Compressor.prototype, {
function return_value(stat) {
if (!stat) return make_node(AST_Undefined, self);
if (stat instanceof AST_Return) {
if (!stat.value) return make_node(AST_Undefined, self);
return stat.value.clone(true);
}
if (stat instanceof AST_SimpleStatement) {
return make_node(AST_UnaryPrefix, stat, {
if (stat instanceof AST_Return) return stat.value || make_node(AST_Undefined, self);
if (stat instanceof AST_SimpleStatement) return make_node(AST_UnaryPrefix, stat, {
operator: "void",
expression: stat.body
});
}
}
function can_flatten_body(stat) {
var len = fn.body.length;

View File

@@ -4747,3 +4747,34 @@ issue_3929: {
}
expect_stdout: "function"
}
issue_4006: {
options = {
dead_code: true,
evaluate: true,
inline: true,
keep_fargs: "strict",
reduce_vars: true,
sequences: true,
side_effects: true,
unused: true,
}
input: {
var a = 0;
(function() {
(function(b, c) {
for (var k in console.log(c), 0)
return b += 0;
})(0, --a);
return a ? 0 : --a;
})();
}
expect: {
var a = 0;
(function(c) {
for (var k in console.log(c), 0)
return;
})(--a), a || --a;
}
expect_stdout: "-1"
}

View File

@@ -197,6 +197,7 @@ BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS = BINARY_OPS.concat(BINARY_OPS);
BINARY_OPS.push(" in ");
var ASSIGNMENTS = [