[Pkg-javascript-commits] [uglifyjs] 154/491: ensure mangling works if catch reuses a scope variable (#2123)

Jonas Smedegaard dr at jones.dk
Wed Feb 14 19:51:31 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 343ea326c217b9c1dbaf098a2def96df2b0b818c
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Jun 20 02:14:05 2017 +0800

    ensure mangling works if catch reuses a scope variable (#2123)
    
    fixes #2120
---
 lib/scope.js               | 15 +++++++++-
 test/compress/screw-ie8.js | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 84 insertions(+), 1 deletion(-)

diff --git a/lib/scope.js b/lib/scope.js
index 82a935a..c147ce0 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -79,7 +79,7 @@ SymbolDef.prototype = {
             if (options.ie8 && sym instanceof AST_SymbolLambda)
                 s = s.parent_scope;
             var def;
-            if (this.defun && (def = this.defun.variables.get(this.name))) {
+            if (def = this.redefined()) {
                 this.mangled_name = def.mangled_name || def.name;
             } else
                 this.mangled_name = s.next_mangled(options, this);
@@ -87,6 +87,9 @@ SymbolDef.prototype = {
                 cache.set(this.name, this.mangled_name);
             }
         }
+    },
+    redefined: function() {
+        return this.defun && this.defun.variables.get(this.name);
     }
 };
 
@@ -206,6 +209,16 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
             node.reference(options);
             return true;
         }
+        // ensure mangling works if catch reuses a scope variable
+        var def;
+        if (node instanceof AST_SymbolCatch && (def = node.definition().redefined())) {
+            var s = node.scope;
+            while (s) {
+                push_uniq(s.enclosed, def);
+                if (s === def.scope) break;
+                s = s.parent_scope;
+            }
+        }
     });
     self.walk(tw);
 
diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js
index a9fbeb5..5d6f1e2 100644
--- a/test/compress/screw-ie8.js
+++ b/test/compress/screw-ie8.js
@@ -255,3 +255,73 @@ issue_1586_2: {
     }
     expect_exact: "function f(){try{x()}catch(c){console.log(c.message)}}"
 }
+
+issue_2120_1: {
+    mangle = {
+        ie8: false,
+    }
+    input: {
+        "aaaaaaaa";
+        var a = 1, b = "FAIL";
+        try {
+            throw 1;
+        } catch (c) {
+            try {
+                throw 0;
+            } catch (a) {
+                if (c) b = "PASS";
+            }
+        }
+        console.log(b);
+    }
+    expect: {
+        "aaaaaaaa";
+        var a = 1, b = "FAIL";
+        try {
+            throw 1;
+        } catch (t) {
+            try {
+                throw 0;
+            } catch (a) {
+                if (t) b = "PASS";
+            }
+        }
+        console.log(b);
+    }
+    expect_stdout: "PASS"
+}
+
+issue_2120_2: {
+    mangle = {
+        ie8: true,
+    }
+    input: {
+        "aaaaaaaa";
+        var a = 1, b = "FAIL";
+        try {
+            throw 1;
+        } catch (c) {
+            try {
+                throw 0;
+            } catch (a) {
+                if (c) b = "PASS";
+            }
+        }
+        console.log(b);
+    }
+    expect: {
+        "aaaaaaaa";
+        var a = 1, b = "FAIL";
+        try {
+            throw 1;
+        } catch (c) {
+            try {
+                throw 0;
+            } catch (a) {
+                if (c) b = "PASS";
+            }
+        }
+        console.log(b);
+    }
+    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