From a31c27c7cf0c1543305c7710b139201850132e15 Mon Sep 17 00:00:00 2001 From: "Alex Lam S.L" Date: Tue, 25 Aug 2020 10:23:36 +0100 Subject: [PATCH] fix corner case in `collapse_vars` (#4071) fixes #4070 --- lib/compress.js | 2 +- test/compress/collapse_vars.js | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/compress.js b/lib/compress.js index 4de587ae..3f0ea219 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -1286,7 +1286,7 @@ merge(Compressor.prototype, { col: node.start.col }); if (candidate instanceof AST_UnaryPostfix) { - lhs.definition().fixed = false; + if (lhs instanceof AST_SymbolRef) lhs.definition().fixed = false; return make_node(AST_UnaryPrefix, candidate, candidate); } if (candidate instanceof AST_VarDef) { diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index c042f969..709fc6b7 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -8538,3 +8538,25 @@ issue_4051: { } expect_stdout: "undefined" } + +issue_4070: { + options = { + collapse_vars: true, + pure_getters: "strict", + reduce_vars: true, + } + input: { + console.log(function f() { + function g() {} + g.p++; + return f.p = g.p; + }()); + } + expect: { + console.log(function f() { + function g() {} + return f.p = ++g.p; + }()); + } + expect_stdout: "NaN" +} -- 2.34.1