Repository navigation
feat(minify): write strings as templates where every one can be, split the gzip-noise gaps by cause - #22923
Conversation
🦋 Changeset detectedLatest commit: 03cd53b The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
This PR is packaged and the instant preview of its latest commit is available. Install it locally:
npm i -D webpack@https://pkg.pr.new/webpack@22923
yarn add -D webpack@https://pkg.pr.new/webpack@22923
pnpm add -D webpack@https://pkg.pr.new/webpack@22923 |
Types CoverageCoverage after merging feat/minify-gzip-gaps into main will be
Coverage Report |
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Backtick rewriting lib/javascript/syntax-printer.js, test/unitCases/javascript/printer.unittest.js, .changeset/068-minify-gzip-gaps.md |
The printer records eligible string literals and rewrites them as template literals when the improvement is enabled and its conditions are met. Tests cover output equivalence, source maps, and contexts or settings that retain quotes. |
Tail-return and loop simplification lib/javascript/syntax-printer.js, test/unitCases/javascript/printer.unittest.js |
Tail-return shortening preserves conditional effects and can convert a final if statement to a logical expression. The for-of improvement keeps a preceding expression outside the iterable unless it assigns the value read there. Tests cover both changes. |
Corpus size comparisons test/helpers/oxcSmaller.js, test/helpers/swcSmaller.js, test/specCases/minify-corpora.spectest.js, docs/syntax.md, cspell.json |
The size-comparison helpers split broad gzip-difference categories into reason-specific groups. Corpus exceptions and documentation change, and the spell-check dictionary adds dangi. |
Possibly related PRs
- webpack/webpack#22919: Adds function inlining and value substitution in the improve phase, which the syntax documentation also describes.
- webpack/webpack#22887: Changes execution of the minify-corpora tests; this PR also updates their corpus exception table.
- webpack/webpack#22909: Implements improve-phase transformations that the syntax documentation describes alongside other minifier changes.
Suggested labels: area: parser, area: types
Suggested reviewers: aryanraj45, bjohansebas
Priority:
Change: Feature
Merge Risk: 
Minimal · up to 03cd5
-
No actionable merge blocker is established by the supplied evidence; normal validation remains appropriate.
Pre-merge checks: 
3 · 
1
-
Failed checks: 1 inconclusive Passed checks: 3 passedFull details: Title check
-
Explanation
The title uses valid Conventional Commit syntax with the allowed type
featand the scopeminify. It accurately describes the main changes. The branch prefix is not provided, so the required type-prefix match cannot be verified.Resolution
Provide the branch name or branch prefix. Confirm that it uses the
featprefix, or update the title type to match the branch prefix.
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Warning
Some tools did not complete. Review the errors below.
🔧 ast-grep (0.45.3)
-
test/unitCases/javascript/printer.unittest.js
-
ast-grep timed out on this file
lib/javascript/syntax-printer.js
-
ast-grep timed out on this file
-
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands.
Generated code sizeComparing base (
Read 23 asset(s) changed size, test untouched, biggest 20 by raw or gzip change
No runtime gained or lost a runtime module. Built |
Merging this PR will improve performance by 37.56%2 warnings, 1 note
Performance Changes
Tip Curious why performance improved? Comment Comparing |
Summary
The ~260 gap-list entries filed as "gzips a few bytes smaller" were treated as noise. This PR measures them and closes what is real.
First, it measures every spelling rule across all 35k corpus outputs by flipping each one. None loses on real code:
==is 4.9 KB gzip better than literal-firstconst→letis 3.1 KB better"function"==typeof xis 1.2 KB better than the reverseThe one consistent loss is the quote character. In deflate's Huffman header
`costs less than".Changes (all in the
improvephase):require()/Object.defineProperty()arguments (read bycjs-module-lexer), or ecma < 2015. The rule can be switched off withimprovements.backticks.enabled.return c?void a:void bfalls off asc?a:b, and a lastif(c)ebecomesc&&e. Corpus-wide: −61 raw, −33 gzip.for…ofheads. A statement before afor…ofstays out of its head, where it needs parentheses: −195 raw, −191 gzip on test262.Measured and rejected:
if…returnchains"…"+void 0foldedGap lists:
oxcSmaller.js: 424 → 361 entries.swcSmaller.js: unchanged in size; its noise group is split by cause.,vs;, method vs arrow, and so on.IMPROVED_YET_BIGGER.Before/after (
compress: { passes: 2 }, mangle: true, ecma: 2020; raw/gzip bytes):What kind of change does this PR introduce?
feat
Did you add tests for your changes?
Yes.
test/unitCases/javascript/printer.unittest.jscovers the rewrites and every excluded place and option. Snapshots now show backticks: the printer suites andconfigCases/optimization/minify-object-enumeration. The test that compares option reading against terser turns backticks off. The gap lists andIMPROVED_YET_BIGGERlive intest/specCases/minify-corpora.spectest.js.Does this PR introduce a breaking change?
No.
If relevant, what needs to be documented once your changes are merged or what have you already documented?
docs/syntax.md(thesyntax-printer.jsbullet) describes the new rewrites.Use of AI
Claude Code wrote the changes and tests. An analysis agent measured each spelling rule across the corpora. Two agents then implemented the backtick rule and the regrouping, and the shape rewrites. The results were merged and checked with the printer unit tests, the full corpus suite, the minifier config cases, the fuzz seeds and
yarn lint.Generated by Claude Code
Summary by CodeRabbit