[Pkg-javascript-commits] [uglifyjs] 438/491: fix `AST_Scope.clone()` (#2803)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:52:02 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 07e4b64f3a8439a9491cc7a277872e0a5d79a29b
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Wed Jan 17 21:33:13 2018 +0800

    fix `AST_Scope.clone()` (#2803)
    
    fixes #2799
---
 lib/ast.js                   |  7 ++++++
 lib/utils.js                 |  7 ++++++
 test/compress/reduce_vars.js | 58 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 72 insertions(+)

diff --git a/lib/ast.js b/lib/ast.js
index 4e41659..19f6bfb 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -308,6 +308,13 @@ var AST_Scope = DEFNODE("Scope", "variables functions uses_with uses_eval parent
         enclosed: "[SymbolDef*/S] a list of all symbol definitions that are accessed from this scope or any subscopes",
         cname: "[integer/S] current index for mangling variables (used internally by the mangler)",
     },
+    clone: function(deep) {
+        var node = this._clone(deep);
+        if (this.variables) node.variables = this.variables.clone();
+        if (this.functions) node.functions = this.functions.clone();
+        if (this.enclosed) node.enclosed = this.enclosed.slice();
+        return node;
+    }
 }, AST_Block);
 
 var AST_Toplevel = DEFNODE("Toplevel", "globals", {
diff --git a/lib/utils.js b/lib/utils.js
index dab7f56..9121fa9 100644
--- a/lib/utils.js
+++ b/lib/utils.js
@@ -303,6 +303,13 @@ Dictionary.prototype = {
             ret.push(f(this._values[i], i.substr(1)));
         return ret;
     },
+    clone: function() {
+        var ret = new Dictionary();
+        for (var i in this._values)
+            ret._values[i] = this._values[i];
+        ret._size = this._size;
+        return ret;
+    },
     toObject: function() { return this._values }
 };
 Dictionary.fromObject = function(obj) {
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index ec0471a..33175d1 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -5302,3 +5302,61 @@ issue_2774: {
     }
     expect_stdout: "undefined"
 }
+
+issue_2799_1: {
+    options = {
+        reduce_funcs: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        console.log(function() {
+            return f;
+            function f(n) {
+                function g(i) {
+                    return i && i + g(i - 1);
+                }
+                function h(j) {
+                    return g(j);
+                }
+                return h(n);
+            }
+        }()(5));
+    }
+    expect: {
+        console.log(function() {
+            return function(n) {
+                return function(j) {
+                    return function g(i) {
+                        return i && i + g(i - 1);
+                    }(j);
+                }(n);
+            }
+        }()(5));
+    }
+    expect_stdout: "15"
+}
+
+issue_2799_2: {
+    options = {
+        reduce_vars: true,
+        unsafe_proto: true,
+        unused: true,
+    }
+    input: {
+        (function() {
+            function foo() {
+                Function.prototype.call.apply(console.log, [ null, "PASS" ]);
+            }
+            foo();
+        })();
+    }
+    expect: {
+        (function() {
+            (function() {
+                (function() {}).call.apply(console.log, [ null, "PASS" ]);
+            })();
+        })();
+    }
+    expect_stdout: "PASS"
+}

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