From 3bf8699f951c32a93414d1ac4c72364e2e282b33 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 29 Jun 2020 02:06:23 +0100 Subject: [PATCH] fix corner case in `inline` (#4007) fixes #4006 --- lib/compress.js | 15 +++++---------- test/compress/functions.js | 31 +++++++++++++++++++++++++++++++ test/ufuzz/index.js | 1 + 3 files changed, 37 insertions(+), 10 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index 0e11ba96..10a84c6b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -6415,16 +6415,11 @@ 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, { - operator: "void", - expression: stat.body - }); - } + 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) { diff --git a/test/compress/functions.js b/test/compress/functions.js index 1383dbe9..18f4f900 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -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" +} diff --git a/test/ufuzz/index.js b/test/ufuzz/index.js index 7fe35308..64ea805c 100644 --- a/test/ufuzz/index.js +++ b/test/ufuzz/index.js @@ -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 = [ -- 2.34.1