[Pkg-javascript-commits] [uglifyjs] 114/228: fix chained evaluation (#1610)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:22 UTC 2017


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

js pushed a commit to branch master
in repository uglifyjs.

commit ac403018135b0ba700ef6223970c1bbc2a518107
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Fri Mar 17 00:26:48 2017 +0800

    fix chained evaluation (#1610)
    
    `reduce_vars` enables substitution of variables but did not clone the value's `AST_Node`.
    
    This confuses `collapse_vars` and result in invalid AST and subsequent crash.
    
    fixes #1609
---
 lib/compress.js             |  2 +-
 test/compress/issue-1609.js | 56 +++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 57 insertions(+), 1 deletion(-)

diff --git a/lib/compress.js b/lib/compress.js
index dac1f36..c3f1254 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3461,7 +3461,7 @@ merge(Compressor.prototype, {
                     }
                 }
                 if (d.should_replace) {
-                    return d.should_replace;
+                    return d.should_replace.clone(true);
                 }
             }
         }
diff --git a/test/compress/issue-1609.js b/test/compress/issue-1609.js
new file mode 100644
index 0000000..577a3ee
--- /dev/null
+++ b/test/compress/issue-1609.js
@@ -0,0 +1,56 @@
+chained_evaluation_1: {
+    options = {
+        collapse_vars: true,
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function() {
+            var a = 1;
+            (function() {
+                var b = a, c;
+                c = f(b);
+                c.bar = b;
+            })();
+        })();
+    }
+    expect: {
+        (function() {
+            (function() {
+                var c;
+                c = f(1);
+                c.bar = 1;
+            })();
+        })();
+    }
+}
+
+chained_evaluation_2: {
+    options = {
+        collapse_vars: true,
+        evaluate: true,
+        reduce_vars: true,
+        unused: true,
+    }
+    input: {
+        (function() {
+            var a = "long piece of string";
+            (function() {
+                var b = a, c;
+                c = f(b);
+                c.bar = b;
+            })();
+        })();
+    }
+    expect: {
+        (function() {
+            var a = "long piece of string";
+            (function() {
+                var c;
+                c = f(a);
+                c.bar = a;
+            })();
+        })();
+    }
+}

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