Skip to content

Commit

Permalink
fix corner case in reduce_vars (#3124)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlamsl authored May 6, 2018
1 parent f37b918 commit 6b91d12
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
10 changes: 9 additions & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,15 @@ merge(Compressor.prototype, {
}

function mark_defun(tw, def) {
if (def.id in tw.defun_ids) return def.fixed;
if (def.id in tw.defun_ids) {
var marker = tw.defun_ids[def.id];
if (!marker) return;
if (marker !== tw.safe_ids) {
tw.defun_ids[def.id] = undefined;
return;
}
return def.fixed;
}
if (!tw.in_loop) {
tw.defun_ids[def.id] = tw.safe_ids;
return def.fixed;
Expand Down
30 changes: 29 additions & 1 deletion test/compress/reduce_vars.js
Original file line number Diff line number Diff line change
Expand Up @@ -5999,7 +5999,7 @@ issue_3113_5: {
]
}

conditional_nested: {
conditional_nested_1: {
options = {
evaluate: true,
reduce_vars: true,
Expand Down Expand Up @@ -6030,3 +6030,31 @@ conditional_nested: {
}
expect_stdout: "2"
}

conditional_nested_2: {
options = {
evaluate: true,
reduce_vars: true,
}
input: {
var c = 0;
(function(a) {
function f() {
a && c++;
}
f(!c && f(), a = 1);
})();
console.log(c);
}
expect: {
var c = 0;
(function(a) {
function f() {
a && c++;
}
f(!c && f(), a = 1);
})();
console.log(c);
}
expect_stdout: "1"
}

0 comments on commit 6b91d12

Please sign in to comment.