Repository navigation
Commit f9705a6
authored
fix(minifier): keep switch dead zones and string joins, write private top-level const as let (#22754)
* fix(javascript): keep a switch's lets for the cases that read them and string joins as strings
- a constant `switch` keeps its branches where one case reads a `let`,
`const` or class another declares, whose dead zone the fold dropped
- `(x + "s") + c` regroups its constants only where one is a string:
terser folded `"s" + true + 2` to `"s3"`
- `void x ?? y` is written `(x, y)`
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minifier): write a private top-level `const` as `let`
Where a module or `toplevel` keeps the top level from other code, a
`const` nothing writes is `let` there too; exported ones stay.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minifier): read a case's class by its id when keeping a `switch`
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): merge calls through a member path and read `null != a && a.b` as `a?.b` for truth
Two calls differing in one argument merge where reading the callee first
cannot be seen by the test. The merged conditional is no longer optimized
in the context of the one it replaces, which read a value as a truth, and
a `const` exported by name stays `const`.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minifier): keep two `new` apart and bring the rival lists up to date
Merging two `new` of one class gzipped worse across test262's repeated
error constructions while saving the bundles almost nothing.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minifier): keep two calls apart where the test reads a parameter `arguments` maps
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minifier): cover a case label reading a dropped case's `let` in its dead zone
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): write a `var`'s first value into its bare declaration and let `export default` names be `let`
`var a; a = b, c()` becomes `var a = b; c()`, moving the bare name last
where another declarator holds a value. A name `export default` reads
exports a value, so it may be `let` like any private one.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minifier): keep a `var`'s first write apart when it is written again
Folding `var a; a = b` into `var a = b` broke the repeated `a = …` text that
gzip reads cheaply, so files assigning one name several times came out
smaller raw but bigger gzipped.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minifier): record the cases a declared first write grows gzipped
Retire the rival entries the shorter output now matches.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): drop a loop's calls to a local function with an empty body
terser's loop guard keeps every call in a loop from inlining, which also kept
calls to an empty function that make no closure. A function with a parameter
default or pattern still runs, so its calls stay.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): fold a value past an outer `var` it calls or a loop writes
A settled `var` was read only where reduce_vars still marked it fixed, which
calling its value or a loop head undoes though nothing writes it again. A
parameter of a function reading `arguments` stays apart.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test(minifier): retire the rival entries the empty-call and settled-var folds match
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): unpack a name read once by the pattern after it in its place
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): inline a call passing a variable its own function writes again
A function written in place reads the variable passed for its parameter in
its place only when nothing wrote the variable. A write in the variable's own
function runs around the body, never in it, so only a closure's write, or one
seen by a closure the body makes, keeps the call.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): keep a `switch` its conditional would write longer
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): fold a value calling a method on a name past a bare read of it
terser stops a moved value at any read of a name it calls a method on, as the
call may change the object; a read of the bare name still yields the binding,
which only an assignment changes.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): merge a conditional whose nested alternative repeats its consequent
`a ? A : (s, b ? X : A)` writes A once as `a || (s, !b) ? A : X`, kept only
when the merged form is shorter.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* feat(minifier): run a function called in place where it is passed variables
`!function(y){if(1===y)throw Error()}(x)` writes its body in place, each
parameter read as the variable passed for it, where nothing writes that
variable. Copies of one helper stay, as they gzip as one repeat.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* test: retire the destructuring declaration cases oxc no longer writes smaller
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
* fix(minifier): keep a method call before an operator reading its object
A value calling a method on a name moved past a read of the name only where
an argument or array element collects the object: `o + ""` and a template
convert it first, so `var p = o.pop(); return o + "" + p` printed the
array before `pop` ran. Retire the cases now no bigger than the rivals'.
Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD1 parent 7455053 commit f9705a6
5 files changed
Lines changed: 902 additions & 97 deletions
File tree
- lib/javascript
- test
- helpers
- specCases
- unitCases
0 commit comments