[Pkg-javascript-commits] [uglifyjs] 161/228: fix mangle for variable declared within catch block (#1706)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:26 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 984a21704e126616a74d65a1e8790aeccd02f548
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Tue Mar 28 03:26:35 2017 +0800

    fix mangle for variable declared within catch block (#1706)
    
    fixes #1704
---
 lib/scope.js                |   9 ++-
 test/compress/issue-1704.js | 175 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 182 insertions(+), 2 deletions(-)

diff --git a/lib/scope.js b/lib/scope.js
index b255032..c2d0b55 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -154,6 +154,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
         else if (node instanceof AST_SymbolVar
                  || node instanceof AST_SymbolConst) {
             defun.def_variable(node);
+            if (defun !== scope) node.mark_enclosed(options);
         }
         else if (node instanceof AST_SymbolCatch) {
             scope.def_variable(node);
@@ -262,9 +263,8 @@ AST_Lambda.DEFMETHOD("init_scope_vars", function(){
     }));
 });
 
-AST_SymbolRef.DEFMETHOD("reference", function(options) {
+AST_Symbol.DEFMETHOD("mark_enclosed", function(options) {
     var def = this.definition();
-    def.references.push(this);
     var s = this.scope;
     while (s) {
         push_uniq(s.enclosed, def);
@@ -278,6 +278,11 @@ AST_SymbolRef.DEFMETHOD("reference", function(options) {
     }
 });
 
+AST_SymbolRef.DEFMETHOD("reference", function(options) {
+    this.definition().references.push(this);
+    this.mark_enclosed(options);
+});
+
 AST_Scope.DEFMETHOD("find_variable", function(name){
     if (name instanceof AST_Symbol) name = name.name;
     return this.variables.get(name)
diff --git a/test/compress/issue-1704.js b/test/compress/issue-1704.js
new file mode 100644
index 0000000..3fa637f
--- /dev/null
+++ b/test/compress/issue-1704.js
@@ -0,0 +1,175 @@
+mangle_catch: {
+    options = {
+        screw_ie8: true,
+        toplevel: false,
+    }
+    mangle = {
+        screw_ie8: true,
+        toplevel: false,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var a="FAIL";try{throw 1}catch(o){a="PASS"}console.log(a);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_ie8: {
+    options = {
+        screw_ie8: false,
+        toplevel: false,
+    }
+    mangle = {
+        screw_ie8: false,
+        toplevel: false,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var a="FAIL";try{throw 1}catch(args){a="PASS"}console.log(a);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_var: {
+    options = {
+        screw_ie8: true,
+        toplevel: false,
+    }
+    mangle = {
+        screw_ie8: true,
+        toplevel: false,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            var a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var a="FAIL";try{throw 1}catch(o){var a="PASS"}console.log(a);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_var_ie8: {
+    options = {
+        screw_ie8: false,
+        toplevel: false,
+    }
+    mangle = {
+        screw_ie8: false,
+        toplevel: false,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            var a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var a="FAIL";try{throw 1}catch(args){var a="PASS"}console.log(a);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_toplevel: {
+    options = {
+        screw_ie8: true,
+        toplevel: true,
+    }
+    mangle = {
+        screw_ie8: true,
+        toplevel: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_ie8_toplevel: {
+    options = {
+        screw_ie8: false,
+        toplevel: true,
+    }
+    mangle = {
+        screw_ie8: false,
+        toplevel: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var o="FAIL";try{throw 1}catch(c){o="PASS"}console.log(o);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_var_toplevel: {
+    options = {
+        screw_ie8: true,
+        toplevel: true,
+    }
+    mangle = {
+        screw_ie8: true,
+        toplevel: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            var a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
+    expect_stdout: "PASS"
+}
+
+mangle_catch_var_ie8_toplevel: {
+    options = {
+        screw_ie8: false,
+        toplevel: true,
+    }
+    mangle = {
+        screw_ie8: false,
+        toplevel: true,
+    }
+    input: {
+        var a = "FAIL";
+        try {
+            throw 1;
+        } catch (args) {
+            var a = "PASS";
+        }
+        console.log(a);
+    }
+    expect_exact: 'var o="FAIL";try{throw 1}catch(r){var o="PASS"}console.log(o);'
+    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