Skip to content

Commit 6b91d12

Browse files
authored
fix corner case in reduce_vars (#3124)
1 parent f37b918 commit 6b91d12

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/compress.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,15 @@ merge(Compressor.prototype, {
383383
}
384384

385385
function mark_defun(tw, def) {
386-
if (def.id in tw.defun_ids) return def.fixed;
386+
if (def.id in tw.defun_ids) {
387+
var marker = tw.defun_ids[def.id];
388+
if (!marker) return;
389+
if (marker !== tw.safe_ids) {
390+
tw.defun_ids[def.id] = undefined;
391+
return;
392+
}
393+
return def.fixed;
394+
}
387395
if (!tw.in_loop) {
388396
tw.defun_ids[def.id] = tw.safe_ids;
389397
return def.fixed;

test/compress/reduce_vars.js

+29-1
Original file line numberDiff line numberDiff line change
@@ -5999,7 +5999,7 @@ issue_3113_5: {
59995999
]
60006000
}
60016001

6002-
conditional_nested: {
6002+
conditional_nested_1: {
60036003
options = {
60046004
evaluate: true,
60056005
reduce_vars: true,
@@ -6030,3 +6030,31 @@ conditional_nested: {
60306030
}
60316031
expect_stdout: "2"
60326032
}
6033+
6034+
conditional_nested_2: {
6035+
options = {
6036+
evaluate: true,
6037+
reduce_vars: true,
6038+
}
6039+
input: {
6040+
var c = 0;
6041+
(function(a) {
6042+
function f() {
6043+
a && c++;
6044+
}
6045+
f(!c && f(), a = 1);
6046+
})();
6047+
console.log(c);
6048+
}
6049+
expect: {
6050+
var c = 0;
6051+
(function(a) {
6052+
function f() {
6053+
a && c++;
6054+
}
6055+
f(!c && f(), a = 1);
6056+
})();
6057+
console.log(c);
6058+
}
6059+
expect_stdout: "1"
6060+
}

0 commit comments

Comments
 (0)