Skip to content

Commit 23f98ba

Browse files
authoredAug 14, 2024··
improve fix for #5917 (#5921)
1 parent abefd94 commit 23f98ba

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed
 

‎lib/compress.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,19 @@ Compressor.prototype.compress = function(node) {
601601
fn.enclosed.forEach(function(d) {
602602
if (fn.variables.get(d.name) === d) return;
603603
if (safe_to_read(tw, d)) return;
604+
d.single_use = false;
605+
var fixed = d.fixed;
606+
if (typeof fixed == "function") fixed = fixed();
607+
if (fixed instanceof AST_Lambda) {
608+
var safe_ids = fixed.safe_ids;
609+
switch (safe_ids) {
610+
case null:
611+
case false:
612+
return;
613+
default:
614+
if (safe_ids && safe_ids.seq !== tw.safe_ids.seq) return;
615+
}
616+
}
604617
d.fixed = false;
605618
});
606619
}
@@ -648,6 +661,7 @@ Compressor.prototype.compress = function(node) {
648661
tw.defined_ids = defined_ids;
649662
var safe_ids = Object.create(tw.safe_ids);
650663
if (!sequential) safe_ids.seq = {};
664+
if (conditional) safe_ids.cond = true;
651665
tw.safe_ids = safe_ids;
652666
}
653667

@@ -1009,7 +1023,7 @@ Compressor.prototype.compress = function(node) {
10091023
walk_assign();
10101024
right.parent_scope.resolve().fn_defs.push(right);
10111025
right.safe_ids = null;
1012-
if (!ld.fixed || !node.write_only) mark_fn_def(tw, ld, right);
1026+
if (!ld.fixed || !node.write_only || tw.safe_ids.cond) mark_fn_def(tw, ld, right);
10131027
return true;
10141028
}
10151029
if (scan) {

‎test/compress/pure_getters.js

+44-1
Original file line numberDiff line numberDiff line change
@@ -1716,7 +1716,7 @@ issue_5856: {
17161716
expect_stdout: "PASS"
17171717
}
17181718

1719-
issue_5917: {
1719+
issue_5917_1: {
17201720
options = {
17211721
pure_getters: "strict",
17221722
reduce_vars: true,
@@ -1751,3 +1751,46 @@ issue_5917: {
17511751
}
17521752
expect_stdout: "PASS"
17531753
}
1754+
1755+
issue_5917_2: {
1756+
options = {
1757+
passes: 2,
1758+
pure_getters: "strict",
1759+
reduce_vars: true,
1760+
side_effects: true,
1761+
toplevel: true,
1762+
}
1763+
input: {
1764+
var b;
1765+
if (!console) {
1766+
b = function() {};
1767+
FAIL(f);
1768+
}
1769+
function f() {
1770+
b.p;
1771+
}
1772+
try {
1773+
f();
1774+
console.log("FAIL");
1775+
} catch (e) {
1776+
console.log("PASS");
1777+
}
1778+
}
1779+
expect: {
1780+
var b;
1781+
if (!console) {
1782+
b = function() {};
1783+
FAIL(f);
1784+
}
1785+
function f() {
1786+
b.p;
1787+
}
1788+
try {
1789+
f();
1790+
console.log("FAIL");
1791+
} catch (e) {
1792+
console.log("PASS");
1793+
}
1794+
}
1795+
expect_stdout: "PASS"
1796+
}

0 commit comments

Comments
 (0)
Please sign in to comment.