diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-07-04 06:45:09 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-07-04 13:45:09 +0800 |
commit | f4ae2679202ff9d8edd6a0d7c13cf756e5096a96 (patch) | |
tree | d6a1baa192f56ae6d18f169064e1d99ff5bb85e2 | |
parent | 972b9f0bef90844a522f777610e88bf113309025 (diff) | |
download | tracifyjs-f4ae2679202ff9d8edd6a0d7c13cf756e5096a96.tar.gz tracifyjs-f4ae2679202ff9d8edd6a0d7c13cf756e5096a96.zip |
fix corner case in `reduce_vars` (#5047)
fixes #5046
-rw-r--r-- | lib/compress.js | 8 | ||||
-rw-r--r-- | test/compress/functions.js | 31 |
2 files changed, 32 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index 8045cecf..2530ec9f 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1000,11 +1000,7 @@ merge(Compressor.prototype, { arg.walk(tw); if (arg instanceof AST_Spread) iife = false; }); - if (iife) { - exp.reduce_vars = reduce_iife; - } else { - exp.safe_ids = tw.safe_ids; - } + if (iife) exp.reduce_vars = reduce_iife; exp.walk(tw); if (iife) delete exp.reduce_vars; return true; @@ -1299,9 +1295,7 @@ merge(Compressor.prototype, { node.expressions.forEach(function(exp) { exp.walk(tw); }); - tag.safe_ids = tw.safe_ids; tag.walk(tw); - delete tag.reduce_vars; return true; } tag.walk(tw); diff --git a/test/compress/functions.js b/test/compress/functions.js index cad6e5e4..6e75e8fb 100644 --- a/test/compress/functions.js +++ b/test/compress/functions.js @@ -6285,3 +6285,34 @@ issue_5036: { } expect_stdout: "PASS" } + +issue_5046: { + options = { + conditionals: true, + evaluate: true, + keep_fnames: true, + passes: 2, + reduce_vars: true, + side_effects: true, + toplevel: true, + } + input: { + var a = 0; + if (a) + 0(); + else + (function f() { + f; + return a = "PASS"; + })(); + console.log(a); + } + expect: { + var a = 0; + (a ? 0 : function f() { + return a = "PASS"; + })(); + console.log(a); + } + expect_stdout: "PASS" +} |