Skip to content

Commit 6c822b0

Browse files
feat(javascript): fold assignments, inline conditional callees, flatten name-passing calls and fold literal built-ins in the minifier (#22584)
* feat(javascript): fold assignments to locals into their first read in the minifier Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(javascript): read a copied binding in place of a copy written through in the minifier Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(javascript): fold `RegExp` of literals, `Object.keys` of object literals and unsafe-math `+` and `Math.pow` in the minifier Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(javascript): inline functions a conditional callee chooses and flatten calls passed their parameters' own names in the minifier Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): record a copied binding as captured where its read replaces a copy in the minifier A function reading `y` in place of a `let` copy never listed `y` among the bindings it captures, so inlining it into a function declaring that name again read the inner binding instead. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): stop at a conditional's test when inlining a function into a callee it chooses in the minifier The guard read `parent.condition`, which conditional nodes do not have, so a function read as a conditional's test in another function was inlined there too. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): keep built-in rewrites off assigned globals and BigInt operands in the minifier The `RegExp`, `Object.keys` and `Math.pow` rewrites now skip a global the program assigns, and dropping a unary `+` under `unsafe_math` keeps the left one so two BigInts still throw. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): keep the JSDoc of `globalMayBeRebound` on its function in the minifier Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): keep the minifier's new folds where they pay and off patched built-ins Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(javascript): keep a `let` assignment before its own declaration Folding an assignment to a function's `let` into a later read could move it past `let x;` in the same block, so `{ x = 1; let x; return x; }` no longer threw. The collapse scan now stops at the target's own `let`. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent 0027179 commit 6c822b0

6 files changed

Lines changed: 912 additions & 63 deletions

File tree

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,6 +1644,8 @@ class CompressorVariable extends MinifierVariable {
16441644
this.references = [];
16451645
/** @type {number} the last `drop_unused` run to find it in use, 0 for none */
16461646
this.inUseRun = 0;
1647+
/** @type {CompressorNode | undefined} the name a copy of it was set from, kept where a write through the copy dropped `fixed` */
1648+
this.copyOf = undefined;
16471649
}
16481650
}
16491651

0 commit comments

Comments
 (0)