diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2021-03-18 15:58:35 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-18 23:58:35 +0800 |
commit | 3016a78d85025e435c55565e645835986db8c98f (patch) | |
tree | 177c1e617858b9085d7377811aa3a4bed230632a | |
parent | 2508481e33271cb9a402401eecd6a51b2701c265 (diff) | |
download | tracifyjs-3016a78d85025e435c55565e645835986db8c98f.tar.gz tracifyjs-3016a78d85025e435c55565e645835986db8c98f.zip |
fix corner case in `reduce_vars` (#4802)
fixes #4801
-rw-r--r-- | lib/compress.js | 2 | ||||
-rw-r--r-- | test/compress/bigint.js | 30 | ||||
-rw-r--r-- | test/compress/let.js | 12 |
3 files changed, 37 insertions, 7 deletions
diff --git a/lib/compress.js b/lib/compress.js index 81298cb6..d920bc11 100644 --- a/lib/compress.js +++ b/lib/compress.js @@ -10436,7 +10436,7 @@ merge(Compressor.prototype, { } else { value = fixed.optimize(compressor); } - if (value === fixed) value = value.transform(new TreeTransformer(function(node, descend) { + value = value.transform(new TreeTransformer(function(node, descend) { if (node instanceof AST_Scope) return node; node = node.clone(); descend(node, this); diff --git a/test/compress/bigint.js b/test/compress/bigint.js index 9c21d083..b417268c 100644 --- a/test/compress/bigint.js +++ b/test/compress/bigint.js @@ -60,3 +60,33 @@ issue_4590: { expect_stdout: "PASS" node_version: ">=10" } + +issue_4801: { + options = { + booleans: true, + collapse_vars: true, + reduce_vars: true, + unused: true, + } + input: { + try { + (function(a) { + A = 42; + a || A; + })(!(0 == 42 >> 0o644n)); + } catch (e) { + console.log("PASS"); + } + } + expect: { + try { + (function(a) { + 0 != (A = 42) >> 0o644n || A; + })(); + } catch (e) { + console.log("PASS"); + } + } + expect_stdout: "PASS" + node_version: ">=10" +} diff --git a/test/compress/let.js b/test/compress/let.js index 3f42dd10..90d99524 100644 --- a/test/compress/let.js +++ b/test/compress/let.js @@ -419,36 +419,36 @@ reduce_vars_3: { } input: { "use strict"; - (function(scope) { + (function(a) { let i = 1; function f() { i = 0; } - for (let i = 0, x = 0; i < scope.length; i++, x++) { + for (let i = 0, x = 0; i < a.length; i++, x++) { if (x != i) { console.log("FAIL"); break; } f(); - console.log(scope[i]); + console.log(a[i]); } console.log(i); })([ 4, 2 ]); } expect: { "use strict"; - (function(scope) { + (function(a) { let i = 1; function f() { i = 0; } - for (let i = 0, x = 0; i < scope.length; i++, x++) { + for (let i = 0, x = 0; i < a.length; i++, x++) { if (x != i) { console.log("FAIL"); break; } f(); - console.log(scope[i]); + console.log(a[i]); } console.log(i); })([ 4, 2 ]); |