Repository navigation
Commit 9d3b707
authored
feat(css): seven more value- and selector-level minify transforms (#21610)
* feat(css): drop the selectors a list repeats
A repeat matches what its first spelling already matches, at the same
specificity, so only the first is ever read. Written order is kept: the
compressor reads a stylesheet in author order, where like rules already
sit together, and sorting the list measured worse.
* feat(css): squeeze the whitespace and number spelling a custom property carries
A custom property's value is a token stream, so collapsing the whitespace
between its tokens and normalizing how they are spelled leaves every
`var()` substitution reading exactly the same stream.
Only the spelling: `getComputedStyle().getPropertyValue()` hands this text
back, so a rewrite that restates a value in another notation stays held
back — a color, a hash, a time's unit, an easing keyword, a folded sum and
a string's quotes all keep what was written. esbuild, clean-css,
lightningcss and cssnano all rewrite here by default; csso does not.
* feat(css): rewrite a custom property's colors, and write 2n+1 as odd
A color a custom property carries is the same color spelled shorter, so
it minifies like any other — only a rewrite the substitution could not
undo stays held back (a unit, an easing keyword, a folded sum, a string).
`odd` is the An+B notation Selectors 4 gives a keyword, and the keyword is
the shorter spelling. The pseudo-classes it applies to are read out of
mdn-data by the `<an+b>` their own grammar names, not listed by hand.
* feat(css): drop a nested calc's keyword, and write a `from` keyframe as 0%
CSS Values 4 §10.1: a `calc()` standing inside a math expression is what a
plain parenthesis already says, so the keyword carries nothing — verified
in headless Chromium for an operand, a `round()` argument, a `min()` one
and a `clamp()` one, each computing identically either way.
CSS Animations 1 §4 defines `from` as `0%`, two bytes shorter; `to` keeps
its spelling, being shorter than the `100%` it names.
* feat(css): drop the unit a zero angle does not need
The functions taking a bare `0` where an angle belongs are the ones whose
own grammar names `<zero>` beside `<angle>`, so the table is read out of
mdn-data rather than listed. Verified in headless Chromium: rotate(),
rotate3d(), skew(), skewX() and hue-rotate() each compute the same either
way, and a function with no `<zero>` keeps its unit.
* feat(css): write each unicode-range in its shortest equal spelling
Leading zeros carry nothing, and a range running from a prefix followed by
zeros to that prefix followed by `f`s is exactly what the `?` wildcard
says — so `U+0025-00FF` is `U+25-FF` and `U+1E00-1EFF` is `U+1E??`.
Chromium reads both spellings of each pair back as one value through the
CSSOM, which is the equivalence stated. A range whose end is not aligned
keeps its bounds. The generic numeric printer still never sees a `U+…`.
* chore: fold the new CSS minify transforms into the pending changeset
* test(css): update the cached-build snapshots and the words the new terms need
`ConfigCacheTestCases` keeps its own snapshots, so the config cases the
transforms changed needed updating there too. `urange` is the CSS Syntax
production the unicode-range printer is named for; the transform-function
names come out of the generated table lowercased.
* fix(css): keep every transform to one that builds the same CSSOM
`SyntaxBrowserEquivalence` drives real Chrome and asserts a minified
stylesheet builds the CSSOM its source does. Two transforms broke that:
- a custom property's value is the text `getPropertyValue()` hands back,
so squeezing its whitespace or rewriting its colors builds a different
CSSOM from the same document — whatever a `var()` substitution reads.
That is a stricter contract than "renders the same", and it is webpack's.
- dropping a selector a list repeats changes `selectorText` the same way,
and measured byte-neutral on every fixture.
Both are reverted. The zero-angle table is narrowed to the functions whose
grammar names no type but `<angle>` / `<zero>`, so `rotate3d()` is out: its
first three arguments are numbers, and giving `rotate3d(0deg,0,1,45deg)` a
unitless zero revives a declaration Chromium drops.
What remains — `odd`, a `from` keyframe, a nested `calc`, a zero angle and
a `unicode-range` — was checked pairwise in Chromium and builds an
identical CSSOM.
* chore: drop the reverted transforms from the changeset
* fix(css): keep a nested calc() — unwrapping it changes the CSSOM
A declaration holding a substitution keeps its value as the text it was
written with, so `calc(X)` -> `(X)` inside one builds a different CSSOM
even where the expression means the same.
* test(css): cover the urange fallback and the selector-list splitter
The eight lines the patch left uncovered: a `unicode-range` that is no
urange, and the depths a keyframe selector list's comma can sit inside.1 parent 13135e7 commit 9d3b707
20 files changed
Lines changed: 384 additions & 60 deletions
File tree
- .changeset
- lib/css
- test
- configCases/css
- minimize-declined
- __snapshots__
- minimize-esbuild/__snapshots__
- minimize-lightningcss-selectors/__snapshots__
- minimize-lightningcss-values/__snapshots__
- minimize-selectors/__snapshots__
- minimize-values
- __snapshots__
- tooling
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
20 | 24 | | |
21 | 25 | | |
22 | 26 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
758 | 758 | | |
759 | 759 | | |
760 | 760 | | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
761 | 783 | | |
762 | 784 | | |
763 | 785 | | |
| |||
1940 | 1962 | | |
1941 | 1963 | | |
1942 | 1964 | | |
| 1965 | + | |
1943 | 1966 | | |
1944 | 1967 | | |
1945 | 1968 | | |
| |||
1949 | 1972 | | |
1950 | 1973 | | |
1951 | 1974 | | |
| 1975 | + | |
1952 | 1976 | | |
1953 | 1977 | | |
1954 | 1978 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
37 | 38 | | |
38 | 39 | | |
39 | 40 | | |
| |||
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
| 46 | + | |
45 | 47 | | |
46 | 48 | | |
47 | 49 | | |
| |||
1843 | 1845 | | |
1844 | 1846 | | |
1845 | 1847 | | |
| 1848 | + | |
1846 | 1849 | | |
1847 | 1850 | | |
1848 | 1851 | | |
| |||
3878 | 3881 | | |
3879 | 3882 | | |
3880 | 3883 | | |
| 3884 | + | |
3881 | 3885 | | |
3882 | 3886 | | |
| 3887 | + | |
| 3888 | + | |
| 3889 | + | |
3883 | 3890 | | |
3884 | 3891 | | |
3885 | 3892 | | |
3886 | 3893 | | |
3887 | 3894 | | |
| 3895 | + | |
3888 | 3896 | | |
3889 | 3897 | | |
3890 | 3898 | | |
| |||
4464 | 4472 | | |
4465 | 4473 | | |
4466 | 4474 | | |
4467 | | - | |
| 4475 | + | |
| 4476 | + | |
| 4477 | + | |
4468 | 4478 | | |
4469 | 4479 | | |
4470 | 4480 | | |
| |||
5649 | 5659 | | |
5650 | 5660 | | |
5651 | 5661 | | |
| 5662 | + | |
| 5663 | + | |
| 5664 | + | |
| 5665 | + | |
| 5666 | + | |
| 5667 | + | |
| 5668 | + | |
| 5669 | + | |
| 5670 | + | |
| 5671 | + | |
| 5672 | + | |
| 5673 | + | |
| 5674 | + | |
| 5675 | + | |
| 5676 | + | |
| 5677 | + | |
| 5678 | + | |
| 5679 | + | |
| 5680 | + | |
| 5681 | + | |
| 5682 | + | |
| 5683 | + | |
| 5684 | + | |
| 5685 | + | |
| 5686 | + | |
| 5687 | + | |
| 5688 | + | |
| 5689 | + | |
| 5690 | + | |
| 5691 | + | |
| 5692 | + | |
| 5693 | + | |
| 5694 | + | |
| 5695 | + | |
| 5696 | + | |
| 5697 | + | |
| 5698 | + | |
| 5699 | + | |
| 5700 | + | |
| 5701 | + | |
| 5702 | + | |
| 5703 | + | |
| 5704 | + | |
| 5705 | + | |
| 5706 | + | |
| 5707 | + | |
| 5708 | + | |
| 5709 | + | |
| 5710 | + | |
| 5711 | + | |
| 5712 | + | |
| 5713 | + | |
| 5714 | + | |
| 5715 | + | |
| 5716 | + | |
| 5717 | + | |
| 5718 | + | |
| 5719 | + | |
| 5720 | + | |
| 5721 | + | |
| 5722 | + | |
5652 | 5723 | | |
5653 | 5724 | | |
5654 | 5725 | | |
| |||
5739 | 5810 | | |
5740 | 5811 | | |
5741 | 5812 | | |
| 5813 | + | |
| 5814 | + | |
| 5815 | + | |
| 5816 | + | |
| 5817 | + | |
| 5818 | + | |
| 5819 | + | |
| 5820 | + | |
| 5821 | + | |
| 5822 | + | |
| 5823 | + | |
| 5824 | + | |
| 5825 | + | |
| 5826 | + | |
| 5827 | + | |
| 5828 | + | |
| 5829 | + | |
| 5830 | + | |
| 5831 | + | |
| 5832 | + | |
| 5833 | + | |
| 5834 | + | |
| 5835 | + | |
| 5836 | + | |
| 5837 | + | |
| 5838 | + | |
| 5839 | + | |
| 5840 | + | |
| 5841 | + | |
| 5842 | + | |
| 5843 | + | |
| 5844 | + | |
| 5845 | + | |
| 5846 | + | |
| 5847 | + | |
| 5848 | + | |
| 5849 | + | |
5742 | 5850 | | |
5743 | 5851 | | |
5744 | 5852 | | |
| |||
6340 | 6448 | | |
6341 | 6449 | | |
6342 | 6450 | | |
| 6451 | + | |
| 6452 | + | |
| 6453 | + | |
| 6454 | + | |
6343 | 6455 | | |
6344 | 6456 | | |
6345 | 6457 | | |
| |||
6366 | 6478 | | |
6367 | 6479 | | |
6368 | 6480 | | |
6369 | | - | |
| 6481 | + | |
6370 | 6482 | | |
6371 | 6483 | | |
6372 | 6484 | | |
| |||
6384 | 6496 | | |
6385 | 6497 | | |
6386 | 6498 | | |
6387 | | - | |
| 6499 | + | |
| 6500 | + | |
| 6501 | + | |
| 6502 | + | |
6388 | 6503 | | |
6389 | 6504 | | |
6390 | 6505 | | |
| |||
6398 | 6513 | | |
6399 | 6514 | | |
6400 | 6515 | | |
| 6516 | + | |
| 6517 | + | |
| 6518 | + | |
| 6519 | + | |
| 6520 | + | |
| 6521 | + | |
| 6522 | + | |
| 6523 | + | |
| 6524 | + | |
6401 | 6525 | | |
6402 | | - | |
| 6526 | + | |
| 6527 | + | |
6403 | 6528 | | |
6404 | 6529 | | |
6405 | 6530 | | |
| |||
6422 | 6547 | | |
6423 | 6548 | | |
6424 | 6549 | | |
6425 | | - | |
| 6550 | + | |
| 6551 | + | |
6426 | 6552 | | |
6427 | 6553 | | |
6428 | 6554 | | |
| |||
6485 | 6611 | | |
6486 | 6612 | | |
6487 | 6613 | | |
6488 | | - | |
6489 | | - | |
6490 | | - | |
6491 | | - | |
6492 | | - | |
6493 | | - | |
6494 | | - | |
6495 | | - | |
6496 | | - | |
6497 | | - | |
| 6614 | + | |
| 6615 | + | |
| 6616 | + | |
| 6617 | + | |
| 6618 | + | |
6498 | 6619 | | |
| 6620 | + | |
| 6621 | + | |
| 6622 | + | |
| 6623 | + | |
| 6624 | + | |
| 6625 | + | |
| 6626 | + | |
| 6627 | + | |
| 6628 | + | |
| 6629 | + | |
6499 | 6630 | | |
6500 | 6631 | | |
6501 | 6632 | | |
| |||
6543 | 6674 | | |
6544 | 6675 | | |
6545 | 6676 | | |
6546 | | - | |
| 6677 | + | |
6547 | 6678 | | |
6548 | 6679 | | |
6549 | 6680 | | |
6550 | 6681 | | |
| 6682 | + | |
| 6683 | + | |
| 6684 | + | |
| 6685 | + | |
| 6686 | + | |
| 6687 | + | |
| 6688 | + | |
| 6689 | + | |
| 6690 | + | |
| 6691 | + | |
| 6692 | + | |
| 6693 | + | |
| 6694 | + | |
| 6695 | + | |
| 6696 | + | |
6551 | 6697 | | |
6552 | 6698 | | |
6553 | 6699 | | |
| |||
6751 | 6897 | | |
6752 | 6898 | | |
6753 | 6899 | | |
| 6900 | + | |
| 6901 | + | |
| 6902 | + | |
| 6903 | + | |
6754 | 6904 | | |
6755 | 6905 | | |
6756 | 6906 | | |
| |||
0 commit comments