From 4984bc4414ff35ef8d338cf8aa69cfbc833dcab8 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 12 May 2020 16:52:20 +0800 Subject: [PATCH] fix corner case in `evaluate` fixes #3887 --- lib/compress.js | 2 +- test/compress/evaluate.js | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 415f9bdb654..e4f75899460 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3368,7 +3368,7 @@ merge(Compressor.prototype, { }); def(AST_UnaryPostfix, function(compressor, ignore_side_effects, cached, depth) { var e = this.expression; - if (!(e instanceof AST_SymbolRef)) return this; + if (!e.fixed) return this; var refs = e.definition().references; if (!ignore_side_effects && refs[refs.length - 1] !== e) return this; var v = e._eval(compressor, ignore_side_effects, cached, depth + 1); diff --git a/test/compress/evaluate.js b/test/compress/evaluate.js index 60f059a8519..8425abe2fae 100644 --- a/test/compress/evaluate.js +++ b/test/compress/evaluate.js @@ -2395,3 +2395,26 @@ issue_3882: { "NaN", ] } + +issue_3887: { + options = { + evaluate: true, + reduce_vars: true, + unused: true, + } + input: { + (function(b) { + try { + b-- && console.log("PASS"); + } catch (a_2) {} + })(1); + } + expect: { + (function(b) { + try { + b-- && console.log("PASS"); + } catch (a_2) {} + })(1); + } + expect_stdout: "PASS" +}