From 7f35d9cee05528574a24cbdad5593403db07cbf0 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Wed, 14 Oct 2020 00:58:04 +0100 Subject: [PATCH] fix corner case in `reduce_vars` (#4219) fixes #4218 --- lib/compress.js | 1 + test/compress/const.js | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/lib/compress.js b/lib/compress.js index b2ed17cf..3e6218a0 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -993,6 +993,7 @@ merge(Compressor.prototype, { return node.value; }; d.fixed.assigns = [ node ]; + if (node.name instanceof AST_SymbolConst && d.redefined()) d.single_use = false; } else { d.fixed = false; } diff --git a/test/compress/const.js b/test/compress/const.js index 27c55ddb..8c04c6b1 100644 --- a/test/compress/const.js +++ b/test/compress/const.js @@ -931,6 +931,30 @@ issue_4207: { expect_stdout: "0" } +issue_4218: { + options = { + reduce_funcs: true, + reduce_vars: true, + toplevel: true, + unused: true, + } + input: { + { + const a = function() {}; + var b = 0 * a; + } + console.log(typeof a, b); + } + expect: { + { + const a = function() {}; + var b = 0 * a; + } + console.log(typeof a, b); + } + expect_stdout: true +} + issue_4210: { options = { reduce_vars: true, -- 2.34.1