[Pkg-javascript-commits] [uglifyjs] 152/491: make defensive copies when `inline` (#2116)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:30 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 0a0f4f55912fed32b09c93a2a1efa19edce24e28
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Jun 17 14:32:37 2017 +0800

    make defensive copies when `inline` (#2116)
    
    fixes #2114
---
 lib/compress.js            |  7 +++--
 test/compress/functions.js | 67 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 309b87c..aa7affc 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3177,16 +3177,19 @@ merge(Compressor.prototype, {
                     if (exp.argnames.length > 0) {
                         fn.body.push(make_node(AST_Var, self, {
                             definitions: exp.argnames.map(function(sym, i) {
+                                var arg = self.args[i];
                                 return make_node(AST_VarDef, sym, {
                                     name: sym,
-                                    value: self.args[i] || make_node(AST_Undefined, self)
+                                    value: arg ? arg.clone(true) : make_node(AST_Undefined, self)
                                 });
                             })
                         }));
                     }
                     if (self.args.length > exp.argnames.length) {
                         fn.body.push(make_node(AST_SimpleStatement, self, {
-                            body: make_sequence(self, self.args.slice(exp.argnames.length))
+                            body: make_sequence(self, self.args.slice(exp.argnames.length).map(function(node) {
+                                return node.clone(true);
+                            }))
                         }));
                     }
                     fn.body.push(make_node(AST_Return, self, {
diff --git a/test/compress/functions.js b/test/compress/functions.js
index dc430d1..d2640bb 100644
--- a/test/compress/functions.js
+++ b/test/compress/functions.js
@@ -443,3 +443,70 @@ issue_2107: {
     }
     expect_stdout: "5"
 }
+
+issue_2114_1: {
+    options = {
+        collapse_vars: true,
+        if_return: true,
+        inline: true,
+        keep_fargs: false,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        var c = 0;
+        !function(a) {
+            a = 0;
+        }([ {
+            0: c = c + 1,
+            length: c = 1 + c
+        }, typeof void function a() {
+            var b = function f1(a) {
+            }(b && (b.b += (c = c + 1, 0)));
+        }() ]);
+        console.log(c);
+    }
+    expect: {
+        var c = 0;
+        !function() {
+            0;
+        }((c += 1, c = 1 + c, function() {
+            var b = void (b && (b.b += (c += 1, 0)));
+        }()));
+        console.log(c);
+    }
+    expect_stdout: "2"
+}
+
+issue_2114_2: {
+    options = {
+        collapse_vars: true,
+        if_return: true,
+        inline: true,
+        keep_fargs: false,
+        passes: 2,
+        side_effects: true,
+        unused: true,
+    }
+    input: {
+        var c = 0;
+        !function(a) {
+            a = 0;
+        }([ {
+            0: c = c + 1,
+            length: c = 1 + c
+        }, typeof void function a() {
+            var b = function f1(a) {
+            }(b && (b.b += (c = c + 1, 0)));
+        }() ]);
+        console.log(c);
+    }
+    expect: {
+        var c = 0;
+        c = 1 + (c += 1), function() {
+            var b = void (b && (b.b += (c += 1, 0)));
+        }();
+        console.log(c);
+    }
+    expect_stdout: "2"
+}

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