Skip to content

Commit 8741598

Browse files
feat(minify): fold string methods on constants and more aliases written through (#22823)
* feat(minify): fold a string method called on a constant holding a string Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(minify): read a name set once from another through it, after a write through the copy Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * chore: shorten the changeset summary Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(minify): write x -= 1 as --x, and x += 1 as ++x where x holds only numbers Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(minify): keep the spelling gzip writes smaller Re-run a small program with each measured spelling (literals last, lets) switched off and keep the output gzip writes smallest. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * feat(minify): also try names in oxc's letter order, where gzip writes it smaller In a small program, re-run with mangled names taken in English letter order instead of by counted characters, and keep whichever gzips smaller. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(minify): keep `+= 1` on a name a for-in or for-of head declares Also run the measured spellings one after another in their test, and retire two rival cases no longer bigger. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test: count tree prints of one run, without the size choice Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(minify): choose spellings one call at a time, and only for small sources The switches the choice flips are shared, so concurrent calls now wait their turn; a source over 32 KiB is minified once. Regenerate the schema validators, which the names choice writes up to 9 B smaller gzipped. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(minify): ask a comments callback once per comment across size-choice runs A callback keeping a license comment only the first time it is asked would otherwise drop it from a trial run, which then measures smaller. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test: let a late file event invalidate the multi-compiler restart case On Windows the step's own writes can report a change after watching starts, adding an invalidation or a run; the case asserts the restart, not the count. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test: retire the corpus cases now no bigger, and compare them with shorthand kept The gzip-guided choice closes 76 listed gaps, among them both literal-last groups. Re-printing at ECMAScript 5 wrote `{a}` as `{a:a}`, measuring text neither minifier emits; it now keeps shorthand properties. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test(minify): cover every changed line of the numeric and size-choice paths Drop two branches no input reaches: a source the first run accepted is never null, and a `for-in` target already counts as a pattern write. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * fix(minify): measure the program without its inline map, and choose `--x` by size too A source map written inline no longer sways the size choice. `--x` and a shorthand name nothing else reads are measured spellings, and the spellings are also tried off together. Regenerate the validators: 254 B smaller gzipped. Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD * test: retire one oxc case and list a quote-style gzip tie Claude-Session: https://claude.ai/code/session_01ViD41i2KdwwGxrDk7yrjeD
1 parent f48f90e commit 8741598

42 files changed

Lines changed: 732 additions & 166 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
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 string methods on constants, more aliases and `x -= 1` into `--x`, and keep whichever spelling gzips smaller when minifying JavaScript.

‎lib/javascript/ScopeAnalyzer.js‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,8 @@ class CompressorVariable extends MinifierVariable {
17051705
this.copyOf = undefined;
17061706
/** @type {boolean} whether `reduce_vars` met a read of it before any value was set */
17071707
this.readUnset = false;
1708+
/** @type {boolean} whether `reduce_vars` met a declaration of it giving a value */
1709+
this.declaredWithValue = false;
17081710
}
17091711
}
17101712

‎lib/javascript/syntax-printer.js‎

Lines changed: 404 additions & 13 deletions
Large diffs are not rendered by default.

‎schemas/plugins/BannerPlugin.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/HtmlGeneratorOptions.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎schemas/plugins/IgnorePlugin.check.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)