From 28bcdbd7df403a4dca8bd2b7f327b65c8491235d Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Mon, 28 Dec 2020 02:05:59 +0000 Subject: [PATCH] fix corner case in `inline` (#4472) fixes #4471 --- lib/compress.js | 6 +++++- test/compress/functions.js | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 58e0d785..c556c492 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -8039,7 +8039,11 @@ merge(Compressor.prototype, { refs.forEach(function(ref) { var def = ref.definition(); def.references.push(ref); - if (replacing) def.replaced++; + if (replacing) { + def.replaced++; + } else { + def.single_use = false; + } }); return node; } diff --git a/test/compress/functions.js b/test/compress/functions.js index 066bc3ca..af99467a 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -5249,3 +5249,37 @@ issue_4451: { } expect_stdout: "function" } + +issue_4471: { + options = { + inline: true, + reduce_funcs: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + f(f()); + function f() { + return g(); + } + function g() { + { + console.log("PASS"); + } + } + } + expect: { + f(g()); + function f() { + return g(); + } + function g() { + console.log("PASS"); + } + } + expect_stdout: [ + "PASS", + "PASS", + ] +} -- 2.34.1