fix crash in `may_throw()` (#2932)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sun, 18 Feb 2018 13:51:27 +0000 (21:51 +0800)
committerGitHub <noreply@github.com>
Sun, 18 Feb 2018 13:51:27 +0000 (21:51 +0800)
fixes #2931

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

index 2cc8282..f3770cc 100644 (file)
@@ -2864,7 +2864,7 @@ merge(Compressor.prototype, {
             return this.value.may_throw(compressor);
         });
         def(AST_Return, function(compressor){
-            return this.value.may_throw(compressor);
+            return this.value && this.value.may_throw(compressor);
         });
         def(AST_Sequence, function(compressor){
             return any(this.expressions, compressor);
index d0a5df8..688f54c 100644 (file)
@@ -4642,3 +4642,26 @@ issue_805: {
         }
     }
 }
+
+issue_2931: {
+    options = {
+        collapse_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            var a = function() {
+                return;
+            }();
+            return a;
+        }());
+    }
+    expect: {
+        console.log(function() {
+            return function() {
+                return;
+            }();
+        }());
+    }
+    expect_stdout: "undefined"
+}