Skip to content

Commit 0ce87af

Browse files
perf(javascript): one side-effects helper and more compression in the one-pass minifier (#22949)
* perf(javascript): one side-effects helper for the one-pass minifier Move the one pass's purity check into lib/javascript/side-effects.js, following terser's has_side_effects plus webpack's corrections: known globals and their members, conversions, member reads that may throw, pure annotations, classes and reads in the temporal dead zone. Fold an assignment into a call whose callee is a `let`, `const` or class an earlier statement of the same function declares. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * perf(javascript): conditionals, if_return and dead code in the one pass The one pass now prints an `if` of expressions as `t?a:b` and `if(t)return x;return y` as `return t?x:y`. It drops an `if` whose test is known false, a statement that runs nothing, and the side a known test or left operand of `?:`, `&&`, `||` and `??` does not pick. An `if` without `else` stays: printing it as `t&&e` measured larger once gzipped on every fixture. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * perf(javascript): fold values further in the one pass's collapse_vars A value now folds past what reads the same after it runs: a global callee or constructor, for a local the value does not assign, `await`, and a literal, `this` or a name nothing writes before the read, in arguments, elements, property values, a binary's left side or a computed member's object. Each declarator folds into the next value after it, past declarators without one. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * perf(javascript): drop else after leaving, tail breaks, fold into members In the one pass, after a body that always leaves, what the `else` holds prints after the `if` where a list holds it; a `switch` drops the `break` ending it and a `default` doing nothing last; and a value folds into a member assignment whose object and key are stable, and into `import()`. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep `await using` and throwing bigint operations The one pass folded an `await using` declaration's value into its read, so the resource was never disposed: only `using` was excluded. A bigint division by `0n` or negative exponent throws, so `/`, `%` and `**` on bigints now count as effects unless the right side is a literal that cannot throw. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * refactor(javascript): one purity helper for the parser and the minifier `JavascriptParser.isPure` now reads its ESTree expression through `EstreeView`, `toEstreeObject`'s way back, and asks `side-effects.js`, the rules the one-pass minifier uses. Its hooks answer first, and the evaluator confirms only where the rules themselves find an effect. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep isPure's verdicts while it shares the side-effects rules The shared rules found more expressions pure than `isPure` did, which grew bundles: a pure binary expression with an import cost a kept `#__PURE__` comment, and one bailed module concatenation. `isPure` now leaves conversions, member reads and derived classes with a constructor to the evaluator as before, so `1n / 0n` stays impure too. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * perf(javascript): fold booleans, returns, infinities and unread writes in the one pass In the one pass, `!!x` read for its truth prints as `x`, `c?true:false` as `!!c` and `x==true` as `x==1`; a chain of `if (a) return x;` before a `return` prints as one `return a?x:…`; `Infinity` and the `Number` infinities print as `1/0` and `-1/0`; a name only ever written goes with its writes; and a loop body holding one `if` without `else` loses its braces, which `liftsElse` kept for want of an `else`. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * chore: restore the oxc and swc corpus submodules to main's commits They moved with an earlier commit by accident; the oxc corpus must match the oxc-minify it is compared with. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent c93aa8f commit 0ce87af

7 files changed

Lines changed: 2546 additions & 453 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Fold conditionals, returns and values further in the one-pass JavaScript minifier.

0 commit comments

Comments
 (0)