fix `unsafe` `evaluate` of `AST_Array` (#2825)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 20 Jan 2018 17:39:44 +0000 (01:39 +0800)
committerGitHub <noreply@github.com>
Sat, 20 Jan 2018 17:39:44 +0000 (01:39 +0800)
fixes #2822

lib/compress.js
test/compress/evaluate.js

index 49185ae..2803b85 100644 (file)
@@ -2240,7 +2240,10 @@ merge(Compressor.prototype, {
                 var elements = [];
                 for (var i = 0, len = this.elements.length; i < len; i++) {
                     var element = this.elements[i];
-                    if (element instanceof AST_Function) continue;
+                    if (element instanceof AST_Function) {
+                        elements.push(element);
+                        continue;
+                    }
                     var value = element._eval(compressor, depth);
                     if (element === value) return this;
                     elements.push(value);
index d40880f..0d26982 100644 (file)
@@ -1360,3 +1360,17 @@ issue_2535_3: {
         "WARN: Condition left of || always true [test/compress/evaluate.js:1341,20]",
     ]
 }
+
+issue_2822: {
+    options = {
+        evaluate: true,
+        unsafe: true,
+    }
+    input: {
+        console.log([ function() {}, "PASS", "FAIL" ][1]);
+    }
+    expect: {
+        console.log("PASS");
+    }
+    expect_stdout: "PASS"
+}