[Pkg-javascript-commits] [uglifyjs] 77/228: handle variable declaration within catch blocks (#1546)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:18 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 b70591be1a603d3c1728e6563691c3a192023d3f
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sun Mar 5 13:13:44 2017 +0800

    handle variable declaration within catch blocks (#1546)
    
    accounts for IE8- scoping
---
 lib/ast.js                   |  3 ---
 lib/compress.js              | 12 +++++++++++-
 lib/scope.js                 |  3 +--
 test/compress/reduce_vars.js | 23 +++++++++++++++++++++++
 test/compress/screw-ie8.js   | 34 ++++++++++++++++++++++++++++++++++
 5 files changed, 69 insertions(+), 6 deletions(-)

diff --git a/lib/ast.js b/lib/ast.js
index f3df78f..1f16330 100644
--- a/lib/ast.js
+++ b/lib/ast.js
@@ -812,9 +812,6 @@ var AST_SymbolAccessor = DEFNODE("SymbolAccessor", null, {
 
 var AST_SymbolDeclaration = DEFNODE("SymbolDeclaration", "init", {
     $documentation: "A declaration symbol (symbol in var/const, function name or argument, symbol in catch)",
-    $propdoc: {
-        init: "[AST_Node*/S] array of initializers for this declaration."
-    }
 }, AST_Symbol);
 
 var AST_SymbolVar = DEFNODE("SymbolVar", null, {
diff --git a/lib/compress.js b/lib/compress.js
index f2269a2..1a54c75 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -223,6 +223,7 @@ merge(Compressor.prototype, {
 
     AST_Node.DEFMETHOD("reset_opt_flags", function(compressor, rescan){
         var reduce_vars = rescan && compressor.option("reduce_vars");
+        var ie8 = !compressor.option("screw_ie8");
         var safe_ids = [];
         push();
         var suppressor = new TreeWalker(function(node) {
@@ -232,7 +233,7 @@ merge(Compressor.prototype, {
                 d.fixed = false;
             }
         });
-        var tw = new TreeWalker(function(node){
+        var tw = new TreeWalker(function(node, descend){
             if (!(node instanceof AST_Directive || node instanceof AST_Constant)) {
                 node._squeezed = false;
                 node._optimized = false;
@@ -247,6 +248,9 @@ merge(Compressor.prototype, {
                         d.fixed = false;
                     }
                 }
+                if (ie8 && node instanceof AST_SymbolCatch) {
+                    node.definition().fixed = false;
+                }
                 if (node instanceof AST_VarDef) {
                     var d = node.name.definition();
                     if (d.fixed === undefined) {
@@ -301,6 +305,12 @@ merge(Compressor.prototype, {
                     pop();
                     return true;
                 }
+                if (node instanceof AST_Catch) {
+                    push();
+                    descend();
+                    pop();
+                    return true;
+                }
             }
         });
         this.walk(tw);
diff --git a/lib/scope.js b/lib/scope.js
index b00fcb4..f23c8fe 100644
--- a/lib/scope.js
+++ b/lib/scope.js
@@ -154,8 +154,7 @@ AST_Toplevel.DEFMETHOD("figure_out_scope", function(options){
         }
         else if (node instanceof AST_SymbolVar
                  || node instanceof AST_SymbolConst) {
-            var def = defun.def_variable(node);
-            def.init = tw.parent().value;
+            defun.def_variable(node);
         }
         else if (node instanceof AST_SymbolCatch) {
             scope.def_variable(node);
diff --git a/test/compress/reduce_vars.js b/test/compress/reduce_vars.js
index 557631b..70e915d 100644
--- a/test/compress/reduce_vars.js
+++ b/test/compress/reduce_vars.js
@@ -605,6 +605,29 @@ inner_var_for_in_2: {
     }
 }
 
+inner_var_catch: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+    }
+    input: {
+        try {
+            a();
+        } catch (e) {
+            var b = 1;
+        }
+        console.log(b);
+    }
+    expect: {
+        try {
+            a();
+        } catch (e) {
+            var b = 1;
+        }
+        console.log(b);
+    }
+}
+
 issue_1533_1: {
     options = {
         collapse_vars: true,
diff --git a/test/compress/screw-ie8.js b/test/compress/screw-ie8.js
index 51379b1..36eb4d3 100644
--- a/test/compress/screw-ie8.js
+++ b/test/compress/screw-ie8.js
@@ -148,3 +148,37 @@ dont_screw_try_catch_undefined: {
         }
     }
 }
+
+reduce_vars: {
+    options = {
+        evaluate: true,
+        reduce_vars: true,
+        screw_ie8: false,
+        unused: true,
+    }
+    mangle = {
+        screw_ie8: false,
+    }
+    input: {
+        function f() {
+            var a;
+            try {
+                x();
+            } catch (a) {
+                y();
+            }
+            alert(a);
+        }
+    }
+    expect: {
+        function f() {
+            var t;
+            try {
+                x();
+            } catch (t) {
+                y();
+            }
+            alert(t);
+        }
+    }
+}

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