[Pkg-javascript-commits] [uglifyjs] 04/49: Keep const in own scope while compressing

Jonas Smedegaard dr at jones.dk
Fri Dec 9 11:43:24 UTC 2016


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

js pushed a commit to branch master
in repository uglifyjs.

commit 7eb52d2837c9d77a389457ae84bfddd28f86cf27
Author: Anthony Van de Gejuchte <anthonyvdgent at gmail.com>
Date:   Thu Jul 14 18:43:50 2016 +0200

    Keep const in own scope while compressing
    
    - Fixes #1205
    - Fix provided by @kzc
---
 lib/compress.js        |  2 +-
 test/compress/loops.js | 44 +++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index f0f3d09..fd839fa 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -810,7 +810,7 @@ merge(Compressor.prototype, {
                     CHANGED = true;
                 }
                 else if (stat instanceof AST_For
-                         && prev instanceof AST_Definitions
+                         && prev instanceof AST_Var
                          && (!stat.init || stat.init.TYPE == prev.TYPE)) {
                     CHANGED = true;
                     a.pop();
diff --git a/test/compress/loops.js b/test/compress/loops.js
index 91aa1c5..78f618a 100644
--- a/test/compress/loops.js
+++ b/test/compress/loops.js
@@ -144,4 +144,46 @@ parse_do_while_without_semicolon: {
     expect: {
         do x(); while (false);y();
     }
-}
\ No newline at end of file
+}
+
+
+keep_collapse_const_in_own_block_scope: {
+    options = {
+        join_vars: true,
+        loops: true
+    }
+    input: {
+        var i=2;
+        const c=5;
+        while(i--)
+            console.log(i);
+        console.log(c);
+    }
+    expect: {
+        var i=2;
+        const c=5;
+        for(;i--;)
+            console.log(i);
+        console.log(c);
+    }
+}
+
+keep_collapse_const_in_own_block_scope_2: {
+    options = {
+        join_vars: true,
+        loops: true
+    }
+    input: {
+        const c=5;
+        var i=2; // Moves to loop, while it did not in previous test
+        while(i--)
+            console.log(i);
+        console.log(c);
+    }
+    expect: {
+        const c=5;
+        for(var i=2;i--;)
+            console.log(i);
+        console.log(c);
+    }
+}

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