From 6b91d12ec352ad0494752aa6a74ee16cc99b5158 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Sun, 6 May 2018 16:42:35 +0800 Subject: [PATCH] fix corner case in `reduce_vars` (#3124) --- lib/compress.js | 10 +++++++++- test/compress/reduce_vars.js | 30 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index bdce24bc..03fb1c11 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -383,7 +383,15 @@ merge(Compressor.prototype, { } function mark_defun(tw, def) { - if (def.id in tw.defun_ids) return def.fixed; + if (def.id in tw.defun_ids) { + var marker = tw.defun_ids[def.id]; + if (!marker) return; + if (marker !== tw.safe_ids) { + tw.defun_ids[def.id] = undefined; + return; + } + return def.fixed; + } if (!tw.in_loop) { tw.defun_ids[def.id] = tw.safe_ids; return def.fixed; diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js index 14b6a46f..e47b96b5 100644 --- a/test/compress/reduce_vars.js +++ b/test/compress/reduce_vars.js @@ -5999,7 +5999,7 @@ issue_3113_5: { ] } -conditional_nested: { +conditional_nested_1: { options = { evaluate: true, reduce_vars: true, @@ -6030,3 +6030,31 @@ conditional_nested: { } expect_stdout: "2" } + +conditional_nested_2: { + options = { + evaluate: true, + reduce_vars: true, + } + input: { + var c = 0; + (function(a) { + function f() { + a && c++; + } + f(!c && f(), a = 1); + })(); + console.log(c); + } + expect: { + var c = 0; + (function(a) { + function f() { + a && c++; + } + f(!c && f(), a = 1); + })(); + console.log(c); + } + expect_stdout: "1" +} -- 2.34.1