From 87b99162fb124bb2a12a3a5babbce27096977d14 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Fri, 1 Oct 2021 23:54:42 +0100 Subject: [PATCH] fix corner case in `inline` (#5141) fixes #5140 --- lib/compress.js | 7 ++++++- test/compress/functions.js | 26 ++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 2aa2bca4..3c0bf537 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -9582,7 +9582,12 @@ merge(Compressor.prototype, { }); return node; } else if (!node.has_side_effects(compressor)) { - self.drop_side_effect_free = return_null; + self.drop_side_effect_free = function(compressor, first_in_statement) { + var self = this; + var exprs = self.args.slice(); + exprs.unshift(self.expression); + return make_sequence(self, exprs).drop_side_effect_free(compressor, first_in_statement); + }; } } var arg_used, insert, in_loop, scope; diff --git a/test/compress/functions.js b/test/compress/functions.js index 6f596662..d5687a1c 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -6629,3 +6629,29 @@ issue_5120: { } expect_stdout: "PASS" } + +issue_5140: { + options = { + collapse_vars: true, + inline: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + A = 42; + function f(b) { + return b >> 0; + } + var a = f(42 in []); + console.log(f(A)); + } + expect: { + function f(b) { + return b >> 0; + } + A = 42; + console.log(A >> 0); + } + expect_stdout: "42" +}