[Pkg-javascript-commits] [uglifyjs] 143/228: fix typeof side-effects (#1669)

Jonas Smedegaard dr at jones.dk
Sat Apr 15 14:25:25 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 6e86ee950d98ebacef7e02515e34d758c4f836a1
Author: Alex Lam S.L <alexlamsl at gmail.com>
Date:   Sat Mar 25 17:40:18 2017 +0800

    fix typeof side-effects (#1669)
    
    `has_side_effects()` does not take `typeof`'s magical power of not tripping over undeclared variable into account.
    
    fixes #1668
---
 lib/compress.js         |  4 ++--
 test/compress/typeof.js | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/lib/compress.js b/lib/compress.js
index 47eb4d7..e12c5eb 100644
--- a/lib/compress.js
+++ b/lib/compress.js
@@ -3013,10 +3013,10 @@ merge(Compressor.prototype, {
                 // typeof always returns a non-empty string, thus it's
                 // always true in booleans
                 compressor.warn("Boolean expression always true [{file}:{line},{col}]", self.start);
-                return make_node(AST_Seq, self, {
+                return (e instanceof AST_SymbolRef ? make_node(AST_True, self) : make_node(AST_Seq, self, {
                     car: e,
                     cdr: make_node(AST_True, self)
-                }).optimize(compressor);
+                })).optimize(compressor);
             }
         }
         // avoids infinite recursion of numerals
diff --git a/test/compress/typeof.js b/test/compress/typeof.js
index 7bf8e5e..60f3d1d 100644
--- a/test/compress/typeof.js
+++ b/test/compress/typeof.js
@@ -48,3 +48,15 @@ typeof_in_boolean_context: {
         foo();
     }
 }
+
+issue_1668: {
+    options = {
+        booleans: true,
+    }
+    input: {
+        if (typeof bar);
+    }
+    expect: {
+        if (!0);
+    }
+}

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