Skip to content

Commit f0ca9cf

Browse files
authoredJan 16, 2023
fix corner case in collapse_vars (#5780)
fixes #5779
1 parent a437a61 commit f0ca9cf

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed
 

‎lib/compress.js

+5
Original file line numberDiff line numberDiff line change
@@ -1761,6 +1761,11 @@ Compressor.prototype.compress = function(node) {
17611761

17621762
var identifier_atom = makePredicate("Infinity NaN undefined");
17631763
function is_lhs_read_only(lhs, compressor) {
1764+
if (lhs instanceof AST_Assign) {
1765+
if (lhs.operator != "=") return true;
1766+
if (lhs.right.tail_node().is_constant()) return true;
1767+
return is_lhs_read_only(lhs.left, compressor);
1768+
}
17641769
if (lhs instanceof AST_Atom) return true;
17651770
if (lhs instanceof AST_ObjectIdentity) return true;
17661771
if (lhs instanceof AST_PropAccess) {

‎test/compress/collapse_vars.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -9864,7 +9864,8 @@ issue_5276: {
98649864
}
98659865
expect: {
98669866
var a = A = "PASS";
9867-
a.p = a.p + null - 42;
9867+
a.p += null;
9868+
a.p -= 42;
98689869
console.log(a);
98699870
}
98709871
expect_stdout: "PASS"
@@ -10148,3 +10149,26 @@ issue_5719: {
1014810149
}
1014910150
expect_stdout: "PASS"
1015010151
}
10152+
10153+
issue_5779: {
10154+
options = {
10155+
collapse_vars: true,
10156+
evaluate: true,
10157+
pure_getters: "strict",
10158+
reduce_vars: true,
10159+
toplevel: true,
10160+
}
10161+
input: {
10162+
var a = A = "foo";
10163+
a.p = 42;
10164+
if (a && !a.p)
10165+
console.log("PASS");
10166+
}
10167+
expect: {
10168+
var a = A = "foo";
10169+
a.p = 42;
10170+
if (a, !a.p)
10171+
console.log("PASS");
10172+
}
10173+
expect_stdout: "PASS"
10174+
}

0 commit comments

Comments
 (0)
Please sign in to comment.