Skip to content

Commit ac945ca

Browse files
fix(minify): keep a self-naming call whose body reads a let in its dead zone
Whether its body runs nothing is now asked as dropping its values does, which keeps a read of a binding not yet initialized. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 5d7f942 commit ac945ca

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

‎lib/javascript/syntax-printer.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24618,8 +24618,9 @@ const installImprove = (modules) => {
2461824618
(statement) =>
2461924619
A.isReturnNode(statement)
2462024620
? !statement.argument ||
24621-
!A.hasSideEffects(statement.argument, compressor)
24622-
: !A.hasSideEffects(statement, compressor)
24621+
!A.dropSideEffectFree(statement.argument, compressor)
24622+
: A.isSimpleStatementNode(statement) &&
24623+
!A.dropSideEffectFree(statement.expression, compressor)
2462324624
);
2462424625
// terser keeps a call of a function naming itself, whose own calls may read
2462524626
// what it returns; a body running nothing calls nothing, itself included.

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9338,6 +9338,8 @@ describe("syntax-printer", () => {
93389338
}
93399339
for (const input of [
93409340
'(function foo() { console.log("r"); return foo; })(); console.log(1);',
9341+
"try { (function f() { return f && x; })(); } catch (e) { console.log(e.name); } let x = 1;",
9342+
"try { (function f() { f; x; })(); } catch (e) { console.log(e.name); } let x = 1;",
93419343
"console.log((function foo(n) { return n ? foo(n - 1).x.y : {}; })(2));",
93429344
"var a = 1; var x = /* @__PURE__ */ (() => { if (a) return 1; })(); console.log(x);",
93439345
'var x = /* @__PURE__ */ (() => {})(console.log("arg")); console.log(x);',

0 commit comments

Comments
 (0)