From: Alex Lam S.L Date: Mon, 5 Mar 2018 16:45:58 +0000 (+0800) Subject: handle negated constants correctly in `collapse_vars` (#2975) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=fe51a91395f3b0a6ab812f3f42746d39efd9e80c;p=UglifyJS.git handle negated constants correctly in `collapse_vars` (#2975) fixes #2974 --- diff --git a/lib/compress.js b/lib/compress.js index a63a5c66..2f109a17 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -778,8 +778,7 @@ merge(Compressor.prototype, { lhs = lhs.fixed_value(); } if (!lhs) return true; - if (lhs instanceof AST_RegExp) return false; - if (lhs instanceof AST_Constant) return true; + if (lhs.is_constant()) return true; return is_lhs_read_only(lhs); } return false; diff --git a/test/compress/collapse_vars.js b/test/compress/collapse_vars.js index 97efc21b..8b0f033a 100644 --- a/test/compress/collapse_vars.js +++ b/test/compress/collapse_vars.js @@ -5207,3 +5207,39 @@ collapse_rhs_undefined: { } expect_stdout: "true true true" } + +issue_2974: { + options = { + booleans: true, + collapse_vars: true, + evaluate: true, + loops: true, + passes: 2, + pure_getters: "strict", + reduce_vars: true, + sequences: true, + side_effects: true, + unused: true, + } + input: { + var c = 0; + (function f(b) { + var a = 2; + do { + b && b[b]; + b && (b.null = -4); + c++; + } while (b.null && --a > 0); + })(true); + console.log(c); + } + expect: { + var c = 0; + (function(b) { + var a = 2; + for (; b.null = -4, c++, b.null && --a > 0;); + })(!0), + console.log(c); + } + expect_stdout: "1" +}