[Pkg-javascript-commits] [uglifyjs] 166/491: improve `unsafe_Func` (#2171)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:32 UTC 2018


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/3.3.10-1
in repository uglifyjs.

commit f0a99125eef4a95a3c4bead81b3bf9a99b207019
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Jun 27 23:53:42 2017 +0800

    improve `unsafe_Func` (#2171)
    
    - minimise disturbance to `compute_char_frequency()`
    - remove extraneous quotation marks
---
 lib/compress.js            | 22 +++++++++++-----------
 test/compress/functions.js |  2 +-
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 0f00d09..352be28 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3120,7 +3120,7 @@ merge(Compressor.prototype, {
                 //   https://github.com/mishoo/UglifyJS2/issues/203
                 // if the code argument is a constant, then we can minify it.
                 try {
-                    var code = "NaN(function(" + self.args.slice(0, -1).map(function(arg) {
+                    var code = "n(function(" + self.args.slice(0, -1).map(function(arg) {
                         return arg.value;
                     }).join(",") + "){" + self.args[self.args.length - 1].value + "})";
                     var ast = parse(code);
@@ -3140,18 +3140,18 @@ merge(Compressor.prototype, {
                             return true;
                         }
                     }));
-                    var args = fun.argnames.map(function(arg, i) {
-                        return make_node(AST_String, self.args[i], {
-                            value: arg.print_to_string()
-                        });
-                    });
                     var code = OutputStream();
                     AST_BlockStatement.prototype._codegen.call(fun, fun, code);
-                    code = code.toString().replace(/^\{|\}$/g, "");
-                    args.push(make_node(AST_String, self.args[self.args.length - 1], {
-                        value: code
-                    }));
-                    self.args = args;
+                    self.args = [
+                        make_node(AST_String, self, {
+                            value: fun.argnames.map(function(arg) {
+                                return arg.print_to_string();
+                            }).join(",")
+                        }),
+                        make_node(AST_String, self.args[self.args.length - 1], {
+                            value: code.get().replace(/^\{|\}$/g, "")
+                        })
+                    ];
                     return self;
                 } catch (ex) {
                     if (ex instanceof JS_Parse_Error) {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index b5def8e..c8efc12 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -265,7 +265,7 @@ issue_203: {
     }
     expect: {
         var m = {};
-        var fn = Function("n", "o", "o.exports=42");
+        var fn = Function("n,o", "o.exports=42");
         fn(null, m, m.exports);
         console.log(m.exports);
     }

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/uglifyjs.git



More information about the Pkg-javascript-commits mailing list