Skip to content

Commit

Permalink
fix corner case in inline (#5896)
Browse files Browse the repository at this point in the history
fixes #5895
  • Loading branch information
alexlamsl authored Jul 30, 2024
1 parent 4b86eaf commit 4bf9a4f
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/compress.js
Original file line number Diff line number Diff line change
Expand Up @@ -4094,7 +4094,7 @@ Compressor.prototype.compress = function(node) {
changed = true;
}
}
var loop = in_loop && in_try && in_try.bfinally ? "try" : in_loop;
var loop = in_loop && in_try ? "try" : in_loop;
for (; index >= 0; index--) {
var inlined = statements[index].try_inline(compressor, block_scope, true, loop);
if (!inlined) continue;
Expand Down
79 changes: 79 additions & 0 deletions test/compress/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -8997,3 +8997,82 @@ issue_5885: {
}
expect_stdout: "NaNfoo"
}

issue_5895_1: {
options = {
inline: true,
unused: true,
}
input: {
(function() {
for (var a in [ 1, 2 ])
try {
return function() {
var b;
b[b = 42];
while (!console);
}();
} catch (e) {
console.log("foo");
}
})();
}
expect: {
(function() {
for (var a in [ 1, 2 ])
try {
b = void 0;
var b;
b[b = 42];
while (!console);
return;
} catch (e) {
console.log("foo");
}
})();
}
expect_stdout: [
"foo",
"foo",
]
}

issue_5895_2: {
options = {
inline: true,
unused: true,
}
input: {
(function() {
for (var a in [ 1, 2 ])
try {
return function() {
(function f(b) {
b[b = 42];
})();
while (!console);
}();
} catch (e) {
console.log("foo");
}
})();
}
expect: {
(function() {
for (var a in [ 1, 2 ])
try {
b = void 0;
void b[b = 42];
var b;
while (!console);
return;
} catch (e) {
console.log("foo");
}
})();
}
expect_stdout: [
"foo",
"foo",
]
}

0 comments on commit 4bf9a4f

Please sign in to comment.