fix corner case in `reduce_vars` (#3332)
authorAlex Lam S.L <alexlamsl@gmail.com>
Wed, 13 Mar 2019 13:56:38 +0000 (21:56 +0800)
committerGitHub <noreply@github.com>
Wed, 13 Mar 2019 13:56:38 +0000 (21:56 +0800)
fixes #3267

lib/compress.js
test/compress/reduce_vars.js

index 75914b3..e6446fe 100644 (file)
@@ -5787,8 +5787,8 @@ merge(Compressor.prototype, {
             }
             if (single_use && fixed) {
                 def.single_use = false;
+                fixed._squeezed = true;
                 if (fixed instanceof AST_Defun) {
-                    fixed._squeezed = true;
                     fixed = make_node(AST_Function, fixed, fixed);
                     fixed.name = make_node(AST_SymbolLambda, fixed.name, fixed.name);
                 }
index 0bb682a..32a06b1 100644 (file)
@@ -6586,3 +6586,103 @@ issue_3240_4: {
         "1",
     ]
 }
+
+issues_3267_1: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        (function(x) {
+            x();
+        })(function() {
+            (function(i) {
+                if (i)
+                    return console.log("PASS");
+                throw "FAIL";
+            })(Object());
+        });
+    }
+    expect: {
+        !function(i) {
+            if (i)
+                return console.log("PASS");
+            throw "FAIL";
+        }(Object());
+    }
+    expect_stdout: "PASS"
+}
+
+issues_3267_2: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        keep_fargs: false,
+        passes: 2,
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        (function(x) {
+            x();
+        })(function() {
+            (function(i) {
+                if (i)
+                    return console.log("PASS");
+                throw "FAIL";
+            })(Object());
+        });
+    }
+    expect: {
+        !function() {
+            if (Object())
+                return console.log("PASS");
+            throw "FAIL";
+        }();
+    }
+    expect_stdout: "PASS"
+}
+
+issues_3267_3: {
+    options = {
+        collapse_vars: true,
+        conditionals: true,
+        dead_code: true,
+        evaluate: true,
+        inline: true,
+        keep_fargs: false,
+        passes: 2,
+        reduce_vars: true,
+        sequences: true,
+        side_effects: true,
+        unsafe: true,
+        unused: true,
+    }
+    input: {
+        (function(x) {
+            x();
+        })(function() {
+            (function(i) {
+                if (i)
+                    return console.log("PASS");
+                throw "FAIL";
+            })(Object());
+        });
+    }
+    expect: {
+        console.log("PASS");
+    }
+    expect_stdout: "PASS"
+}