From 72844eb5a4508d2e8fe43a4038983c382708d1e6 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Thu, 17 Sep 2020 16:08:36 +0100 Subject: [PATCH] improve fix for #4119 (#4121) --- lib/compress.js | 7 +---- test/compress/evaluate.js | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/lib/compress.js b/lib/compress.js index f59cc4d4..4c070f9c 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3362,7 +3362,6 @@ merge(Compressor.prototype, { cached.forEach(function(node) { delete node._eval; }); - if (cached.unsafe) return this; if (ignore_side_effects) return val; if (!val || val instanceof RegExp) return val; if (typeof val == "function" || typeof val == "object") return this; @@ -3429,12 +3428,8 @@ merge(Compressor.prototype, { }); } var value = node._eval(compressor, ignore_side_effects, cached, depth); - if (value === node) return this; + if (typeof value == "object") return this; modified(lhs); - if (Array.isArray(value)) value.toString = function() { - cached.unsafe = true; - return "[]"; - }; return value; }); def(AST_Sequence, function(compressor, ignore_side_effects, cached, depth) { diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 5cf3fb1c..9504afb5 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -2960,3 +2960,57 @@ issue_4119_2: { } expect_stdout: "PASS" } + +issue_4119_3: { + options = { + conditionals: true, + evaluate: true, + reduce_vars: true, + toplevel: true, + unsafe: true, + } + input: { + var a, b; + b = a = { + p: 42, + }; + delete a.p; + console.log(b.p ? "FAIL" : "PASS"); + } + expect: { + var a, b; + b = a = { + p: 42, + }; + delete a.p; + console.log(b.p ? "FAIL" : "PASS"); + } + expect_stdout: "PASS" +} + +issue_4119_4: { + options = { + booleans: true, + conditionals: true, + evaluate: true, + reduce_vars: true, + toplevel: true, + } + input: { + var a, b; + b = a = { + p: 42, + }; + delete a.p; + console.log(!b ? "FAIL" : "PASS"); + } + expect: { + var a, b; + b = a = { + p: 42, + }; + delete a.p; + console.log((b, 0, "PASS")); + } + expect_stdout: "PASS" +} -- 2.34.1