Skip to content

Commit

Permalink
fix corner case in reduce_vars (#4802)
Browse files Browse the repository at this point in the history
fixes #4801
  • Loading branch information
alexlamsl committed Mar 18, 2021
1 parent 2508481 commit 3016a78
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/compress.js
Expand Up @@ -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);
Expand Down
30 changes: 30 additions & 0 deletions test/compress/bigint.js
Expand Up @@ -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"
}
12 changes: 6 additions & 6 deletions test/compress/let.js
Expand Up @@ -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 ]);
Expand Down

0 comments on commit 3016a78

Please sign in to comment.