From: Alex Lam S.L Date: Wed, 19 Feb 2020 00:41:10 +0000 (+0000) Subject: fix corner case in `evaluate` (#3729) X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=6092bf23de6608ad225cad61b934570604a5d3a4;p=UglifyJS.git fix corner case in `evaluate` (#3729) --- diff --git a/lib/compress.js b/lib/compress.js index 23c73048..e455ea8d 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -3416,6 +3416,8 @@ merge(Compressor.prototype, { line: this.start.line, col: this.start.col }); + } finally { + if (val instanceof RegExp) val.lastIndex = 0; } } return this; @@ -6866,7 +6868,7 @@ merge(Compressor.prototype, { if (node.truthy) return true; if (node.falsy) return false; if (node.is_truthy()) return true; - return node.evaluate(compressor); + return node.evaluate(compressor, true); } function is_indexFn(node) { diff --git a/test/compress/conditionals.js b/test/compress/conditionals.js index 8044489e..c4ae9095 100644 --- a/test/compress/conditionals.js +++ b/test/compress/conditionals.js @@ -1240,11 +1240,11 @@ issue_2535_1: { expect: { y(); x() && y(); - (x(), 1) && y(); + x(), y(); x() && y(); x() && y(); x() && y(); - (x(), 0) && y(); + x(); } } diff --git a/test/compress/issue-637.js b/test/compress/issue-637.js index 64978bb0..e39c69fa 100644 --- a/test/compress/issue-637.js +++ b/test/compress/issue-637.js @@ -16,7 +16,6 @@ wrongly_optimized: { function func() { foo(); } - // TODO: optimize to `func(), bar()` - (func(), 1) && bar(); + func(), 1, bar(); } } diff --git a/test/compress/issue-640.js b/test/compress/issue-640.js index 394d6ba2..b0a165f5 100644 --- a/test/compress/issue-640.js +++ b/test/compress/issue-640.js @@ -84,6 +84,7 @@ wrongly_optimized: { options = { booleans: true, conditionals: true, + dead_code: true, evaluate: true, expression: true, } @@ -99,8 +100,8 @@ wrongly_optimized: { function func() { foo(); } - // TODO: optimize to `func(), bar()` - if (func(), 1) bar(); + func(), 1; + bar(); } } diff --git a/test/compress/regexp.js b/test/compress/regexp.js index e8b2da73..3194d38e 100644 --- a/test/compress/regexp.js +++ b/test/compress/regexp.js @@ -423,3 +423,53 @@ var_test_global: { "PASS", ] } + +lazy_boolean: { + options = { + evaluate: true, + passes: 2, + side_effects: true, + unsafe: true, + } + input: { + /b/.exec({}) && console.log("PASS"); + /b/.test({}) && console.log("PASS"); + /b/g.exec({}) && console.log("PASS"); + /b/g.test({}) && console.log("PASS"); + } + expect: { + console.log("PASS"); + console.log("PASS"); + console.log("PASS"); + console.log("PASS"); + } + expect_stdout: [ + "PASS", + "PASS", + "PASS", + "PASS", + ] +} + +reset_state_between_evaluate: { + options = { + evaluate: true, + passes: 2, + unsafe: true, + } + input: { + console.log(function() { + for (var a in /[abc4]/g.exec("a")) + return "PASS"; + return "FAIL"; + }()); + } + expect: { + console.log(function() { + for (var a in /[abc4]/g.exec("a")) + return "PASS"; + return "FAIL"; + }()); + } + expect_stdout: "PASS" +}