From: Mihai Bazon Date: Tue, 14 May 2013 15:36:31 +0000 (+0300) Subject: Only compress code in `new Function` if all arguments are strings. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=caa8896a8a9d619334c21e49964e4a6c1a1a15eb;p=UglifyJS.git Only compress code in `new Function` if all arguments are strings. --- diff --git a/lib/compress.js b/lib/compress.js index 56fb6851..57554fa5 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -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. diff --git a/lib/utils.js b/lib/utils.js index c95b9824..73964a09 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -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;