Skip to content

Commit fa162bc

Browse files
fix(minify): bound how often a switch's leftovers are dropped again
dropSideEffectFree can hand an IIFE back as a fresh copy each time, so waiting for the same node never ended and hung the fuzz suite. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent f414b73 commit fa162bc

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43993,10 +43993,12 @@ const installStatementOptimizers = (modules, helpers) => {
4399343993
/** @type {Node | null} */
4399443994
let kept = expression;
4399543995
if (modules.improvements !== undefined && modules.improvements.enabled) {
43996-
// A sequence drops only its last operand at a time.
43996+
// A sequence drops only its last operand at a time; a copy handed back
43997+
// unchanged would loop, so it gets one round per operand.
43998+
let rounds = A.isSequenceNode(kept) ? kept.expressions.length + 1 : 2;
4399743999
for (
4399844000
let next = ast.dropSideEffectFree(kept, compressor);
43999-
next !== kept;
44001+
next !== kept && rounds-- > 0;
4400044002
next = next && ast.dropSideEffectFree(next, compressor)
4400144003
) {
4400244004
kept = next;

‎test/unitCases/javascript/printer.unittest.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9690,6 +9690,15 @@ describe("syntax-printer", () => {
96909690
expect(runProgram(/** @type {string} */ (code))).toBe(runProgram(input));
96919691
});
96929692

9693+
it("should stop dropping what a `switch` leaves over once a call comes back as a copy", async () => {
9694+
const { minify } = await load();
9695+
const { code } = await minify(
9696+
"switch ((function () { var v = class { static { a; } }; f(function () { switch (b) { case 0: const {} = { a() {} }; } }); })()) { case {}: }",
9697+
{ compress: { unsafe: true }, toplevel: true, module: true }
9698+
);
9699+
expect(code).toContain("f(");
9700+
});
9701+
96939702
it("should keep a constructor's `this.x` read a getter may answer", async () => {
96949703
const { minify } = await load();
96959704
for (const input of [

0 commit comments

Comments
 (0)