From 4f833937fea193e466a33e2f03f21d0b909a407d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 15 Oct 2020 14:52:40 +0100 Subject: [PATCH] fix corner case in `inline` (#4223) fixes #4222 --- lib/compress.js | 2 +- test/compress/const.js | 30 ++++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index e66331d4..504bf39b 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -7041,7 +7041,7 @@ merge(Compressor.prototype, { && fn.is_constant_expression(find_scope(compressor))) && (value = can_flatten_body(stat)) && !fn.contains_this()) { - var replacing = exp === fn || compressor.option("unused") && def.references.length - def.replaced == 1; + var replacing = exp === fn || def.single_use && def.references.length - def.replaced == 1; if (can_substitute_directly()) { var args = self.args.slice(); var refs = []; diff --git a/test/compress/const.js b/test/compress/const.js index cd951fff..ef5c9675 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -1104,3 +1104,33 @@ issue_4220: { } expect_stdout: true } + +issue_4222: { + options = { + inline: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + { + const a = function() { + return function() {}; + }; + var b = a(); + } + b(); + console.log(typeof a); + } + expect: { + { + const a = function() { + return function() {}; + }; + var b = a(); + } + b(); + console.log(typeof a); + } + expect_stdout: true +} -- 2.34.1