fix corner case in `collapse_vars` (#4071)
authorAlex Lam S.L <alexlamsl@gmail.com>
Tue, 25 Aug 2020 09:23:36 +0000 (10:23 +0100)
committerGitHub <noreply@github.com>
Tue, 25 Aug 2020 09:23:36 +0000 (17:23 +0800)
fixes #4070

lib/compress.js
test/compress/collapse_vars.js

index 4de587a..3f0ea21 100644 (file)
@@ -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) {
index c042f96..709fc6b 100644 (file)
@@ -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"
+}