[Pkg-javascript-commits] [uglifyjs] 59/491: avoid `arguments` and `eval` in `reduce_vars` (#1924)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:21 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 ac73c5d4211b9ecff0f9650a032e964ef1cad585
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri May 12 12:34:55 2017 +0800

    avoid `arguments` and `eval` in `reduce_vars` (#1924)
    
    fixes #1922
---
 lib/compress.js              | 16 +++++++++----
 test/compress/reduce_vars.js | 57 ++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 63 insertions(+), 10 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index aff5c64..1ded032 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -354,10 +354,14 @@ merge(Compressor.prototype, {
                         // So existing transformation rules can work on them.
                         node.argnames.forEach(function(arg, i) {
                             var d = arg.definition();
-                            d.fixed = function() {
-                                return iife.args[i] || make_node(AST_Undefined, iife);
-                            };
-                            mark(d, true);
+                            if (!node.uses_arguments && d.fixed === undefined) {
+                                d.fixed = function() {
+                                    return iife.args[i] || make_node(AST_Undefined, iife);
+                                };
+                                mark(d, true);
+                            } else {
+                                d.fixed = false;
+                            }
                         });
                     }
                     descend();
@@ -491,7 +495,9 @@ merge(Compressor.prototype, {
 
         function reset_def(def) {
             def.escaped = false;
-            if (!def.global || def.orig[0] instanceof AST_SymbolConst || compressor.toplevel(def)) {
+            if (def.scope.uses_eval) {
+                def.fixed = false;
+            } else if (!def.global || def.orig[0] instanceof AST_SymbolConst || compressor.toplevel(def)) {
                 def.fixed = undefined;
             } else {
                 def.fixed = false;
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 5a79f57..d3b3d42 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -41,20 +41,20 @@ reduce_vars: {
         var A = 1;
         (function() {
             console.log(-3);
-            console.log(-4);
+            console.log(A - 5);
         })();
         (function f1() {
             var a = 2;
-            console.log(-3);
+            console.log(a - 5);
             eval("console.log(a);");
         })();
         (function f2(eval) {
             var a = 2;
-            console.log(-3);
+            console.log(a - 5);
             eval("console.log(a);");
         })(eval);
         "yes";
-        console.log(2);
+        console.log(A + 1);
     }
     expect_stdout: true
 }
@@ -1749,7 +1749,10 @@ redefine_arguments_3: {
         console.log(function() {
             var arguments;
             return typeof arguments;
-        }(), "number", "undefined");
+        }(), "number", function(x) {
+            var arguments = x;
+            return typeof arguments;
+        }());
     }
     expect_stdout: "object number undefined"
 }
@@ -2461,3 +2464,47 @@ issue_1865: {
     }
     expect_stdout: true
 }
+
+issue_1922_1: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function(a) {
+            arguments[0] = 2;
+            return a;
+        }(1));
+    }
+    expect: {
+        console.log(function(a) {
+            arguments[0] = 2;
+            return a;
+        }(1));
+    }
+    expect_stdout: "2"
+}
+
+issue_1922_2: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            var a;
+            eval("a = 1");
+            return a;
+        }(1));
+    }
+    expect: {
+        console.log(function() {
+            var a;
+            eval("a = 1");
+            return a;
+        }(1));
+    }
+    expect_stdout: "1"
+}

-- 
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