Skip to content

Commit f013991

Browse files
feat(javascript): honor unused and inline, drop ignored compress options
`unused: false` keeps what nothing reads, `inline: false` leaves each function where it is declared, and the compress options the one pass never reads are gone from its type. Also fixes nested `global_defs` keys, shorthand and negative values, `top_retain` implying `toplevel`, and `drop_console` outside statement lists. Claude-Session: https://claude.ai/code/session_01Tgxgyb4N35ndP6cC4KcrXC
1 parent ded4ce5 commit f013991

6 files changed

Lines changed: 223 additions & 104 deletions

File tree

‎.changeset/080-javascript-minify-compress-options.md‎

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

5-
Honor `pure_funcs`, `drop_console`, `global_defs` and `top_retain` in minify.
5+
Honor `pure_funcs`, `drop_console`, `global_defs`, `top_retain`, `unused` and `inline` in minify.

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1328,6 +1328,7 @@ class MinifierLabel {
13281328
* @property {boolean=} withNames whether a scope a `with` reaches keeps only the names its body spells, mangling the rest
13291329
* @property {number=} spelledNames which names to collect that the mangler may give the name beside them to write less: 1 for an import's or export's, 2 for a key's too
13301330
* @property {boolean=} substitutesAliases whether each read of a `let` or `const` set to a name nothing writes reads that name instead, as the one pass prints it
1331+
* @property {boolean=} movesFunctions under `substitutesAliases`, false to leave each function read once where it is declared, as terser's `inline` turned off does
13311332
*/
13321333

13331334
/**
@@ -3360,7 +3361,9 @@ const analyzeMinifierTree = (tree, program, types, options, raise) => {
33603361
// A catch parameter moved to its function shares its name with the
33613362
// function's own, so a function moved into the catch would read it.
33623363
const movedFunctions =
3363-
analyzer.functionBindings === null || analyzer.catchNames.length !== 0
3364+
analyzer.functionBindings === null ||
3365+
analyzer.catchNames.length !== 0 ||
3366+
options.movesFunctions === false
33643367
? null
33653368
: analyzer._moveFunctions();
33663369
return {

‎lib/javascript/jsMinify.js‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,14 +148,10 @@ const jsMinify = async (
148148
? {}
149149
: false
150150
: { ...options.compress };
151-
if (compress) {
152-
// `ecma` is read per option group, and the compressor is the one that
153-
// would otherwise write syntax the asset's own `ecma` excludes.
154-
if (typeof compress.ecma === "undefined") compress.ecma = options.ecma;
155-
// https://github.com/webpack/webpack/issues/16135
156-
if (options.ecma === 5 && typeof compress.arrows === "undefined") {
157-
compress.arrows = false;
158-
}
151+
// `ecma` is read per option group, and the compressor is the one that
152+
// would otherwise write syntax the asset's own `ecma` excludes.
153+
if (compress && typeof compress.ecma === "undefined") {
154+
compress.ecma = options.ecma;
159155
}
160156

161157
const [[file, given]] = Object.entries(input);

0 commit comments

Comments
 (0)