diff options
author | Mihai Bazon <mihai@bazon.net> | 2013-05-14 18:36:31 +0300 |
---|---|---|
committer | Mihai Bazon <mihai@bazon.net> | 2013-05-14 18:36:31 +0300 |
commit | caa8896a8a9d619334c21e49964e4a6c1a1a15eb (patch) | |
tree | 7811a6198187a0acf00ff1350c9e8a8e041ca751 /lib | |
parent | d13aa3954d2c0c5145b32c9623a05f383a93e0c3 (diff) | |
download | tracifyjs-caa8896a8a9d619334c21e49964e4a6c1a1a15eb.tar.gz tracifyjs-caa8896a8a9d619334c21e49964e4a6c1a1a15eb.zip |
Only compress code in `new Function` if all arguments are strings.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | lib/utils.js | 7 |
2 files changed, 8 insertions, 1 deletions
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; |