Skip to content

Commit cbe037d

Browse files
feat(javascript): close most of the one-pass minify size gap (#23027)
* feat(javascript): negate called function expressions and move named functions A statement calling a function expression, or a sequence opening with one, prints the call after `!` instead of parenthesizing the function, terser's `negate_iife`. Under `keep_fnames`, a function declaration read once still moves to its read, as a function expression keeping its name. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): drop unread private members, empty calls and alike branches The one pass drops a class's private methods, accessors and fields of a value that runs nothing where no name in the class reads them and no direct `eval` may. An empty function called where nothing reads it prints as the array of its arguments, and a conditional whose branches print alike prints as that branch, after its test where the test runs anything. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): drop what a function called where its value is unread returns A `return` in a function expression called where nothing reads the call drops a value that runs nothing, as `finally{return 2}` prints `finally{return}`; a method's own value is never so dropped. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): print a program only calling a function as its statements A program whose one statement calls a function with nothing prints that function's statements, where they declare nothing that stays, return nothing, hold no directive and read no `this`, `arguments` or direct `eval` the call gives them; a `wrap` or `enclose` wrapper stays. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): join a declaration and the statement setting its name terser's `join_vars`: before the scopes are read, `var a; a = b;` and `let a; a = b;` in a body read as `var a = b;` and an empty statement, where `b` names no `a`, so every rule a declarator's value folds by holds. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): fold values into what a `yield` hands over and literals of functions A value folds into a `yield`'s argument as into an `await`'s, both read before they suspend, and an object or array literal of functions and constants is made where its one read is. A joined declaration's assignment statement leaves its list, so the statement after it is next. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): drop a `let`'s writes from closures made once it is set A `let` nothing reads loses the writes of function expressions its function makes after the name's declarator ran, which cannot set it in its dead zone; a `let` counts as set once its own declarator ran. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): fold a value running nothing past what runs nothing A declarator's value that runs nothing, a `/*#__PURE__*/` call among them, folds into its one read past the arguments and elements before it that run nothing either, as `jsx("i")` past `jsx("b")`. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * test(javascript): restore the collapse-suspend assertions the one pass now meets Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): inline constants passed once, unread calls and drop dead code A constant passed to a function called once, in place or moved to its call, is its parameter's value, parameter and argument gone. A function called where nothing reads the call prints as what it runs, `t || (a, b)`, each parameter the name passed. Statements after one that always leaves their list go, but declarations. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): fold conditionals to logicals, array picks and in-order declarators - `a?!1:x` prints `!a&&x`; where only truth is read, `a?!0:x` prints `a||x`. - `[a,b][1]` prints `b`, and folds as a constant and a computed key. - Several declarators fold in order into the statement after them. - A collapsed assignment whose name nothing else reads sets nothing. - Constants passed on as names fold through nested calls and `new`. - What follows an `if` always returning once folded goes. - `+"1"` and `typeof 1` print their values where no longer. - Strings print as templates again where every one can, and a bare `return` after a lifted `else` at a function's end goes. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): merge `if`s returning alike values and print unread calls bare - `if(a)return X;if(b)return X` prints `if(a||b)return X` where both values are written alike, a key quoted or not alike where quotes go. - A call printing as what it runs, last in a sequence or under `void` or `!` in a statement, prints bare. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): fold `Object.keys` of object literals and `.join` of constants `Object.keys({a:1})` prints `["a"]`, array indices first, and `.join` of constants or of the keys `Object.keys` gives prints the string. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * feat(javascript): join declarations of one kind before folding their values `const a=f();const b=g();return[a,b]` reads as one declaration, so its declarators fold in order into the statement after it. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * chore: fold the one-pass size changes into the pending JavaScript minify changeset Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * style(javascript): drop two redundant type casts Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep `.join` of an unknown separator, large keys and `let` dead zones - `.join(s)` folds only where `s` is a known string or `undefined`. - Only array indices, below 2 ** 32 - 1, sort first in `Object.keys`. - `let a; a = v` joins only where `v` runs no code, so no read of `a` can see its dead zone. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep `-0`, `this` of a collapsed member and derived private members - `+(-0)` no longer folds to `0`. - A collapsed `undefined` read as an object or callee prints `(void 0)`. - An assignment of a member collapsed into its call keeps the name, so the member is not called as a method. - A derived class keeps unread private members: a base constructor returning an object makes installing them again throw. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep the order of folded values, `const` writes and self-calls - A value folds past no read folded already, so `x=i++;y=i++;f(y,x)` runs its increments in order. - An assignment to a `const` or class name keeps its name and throws. - A named function or one reading `arguments` keeps its `return`, which a call of itself may read. - An unread call whose body opens with a function stays a call, which otherwise would open a statement. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep an assignment of a name folded where it is called or `typeof` reads it A name printed alone there would make an indirect `eval` direct or hide the `ReferenceError` of a name nothing declares. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC * fix(javascript): keep a folded write to a `let` in its dead zone The write throws there, so it keeps its name where its value folds. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC --------- Co-authored-by: Claude Opus 5.5 <[email protected]>
1 parent a11411a commit cbe037d

13 files changed

Lines changed: 2315 additions & 104 deletions

File tree

‎.changeset/074-javascript-minify-unmangled.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Compress JavaScript with `mangle: false` as with mangling, and keep `Object.keys`, `values` and `entries` calls a program replaces.
5+
Compress JavaScript smaller in one pass, with or without mangling.

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4260,8 +4260,6 @@ class MinifierTreeScopeAnalyzer {
42604260
if (
42614261
type === NodeType.FunctionDeclaration &&
42624262
this.functionBindings !== null &&
4263-
// Moved, it loses the name `keep_fnames` keeps.
4264-
this.functionDeclarators === null &&
42654263
/** @type {Uint8Array} */ (listsStatements)[this.types[parent]] ===
42664264
1 &&
42674265
this.types[parent] !== NodeType.BlockStatement &&

0 commit comments

Comments
 (0)