Only compress code in `new Function` if all arguments are strings.
authorMihai Bazon <mihai@bazon.net>
Tue, 14 May 2013 15:36:31 +0000 (18:36 +0300)
committerMihai Bazon <mihai@bazon.net>
Tue, 14 May 2013 15:36:31 +0000 (18:36 +0300)
lib/compress.js
lib/utils.js

index 56fb685..57554fa 100644 (file)
@@ -1590,7 +1590,7 @@ merge(Compressor.prototype, {
                         right: make_node(AST_String, self, { value: "" })
                     });
                   case "Function":
-                    if (self.args[self.args.length - 1] instanceof AST_String) {
+                    if (all(self.args, function(x){ return x instanceof AST_String })) {
                         // quite a corner-case, but we can handle it:
                         //   https://github.com/mishoo/UglifyJS2/issues/203
                         // if the code argument is a constant, then we can minify it.
index c95b982..73964a0 100644 (file)
@@ -245,6 +245,13 @@ function makePredicate(words) {
     return new Function("str", f);
 };
 
+function all(array, predicate) {
+    for (var i = array.length; --i >= 0;)
+        if (!predicate(array[i]))
+            return false;
+    return true;
+};
+
 function Dictionary() {
     this._values = Object.create(null);
     this._size = 0;