Skip to content

Commit 37f87b9

Browse files
fix(css): drop no declaration a keyframe, a revert or a slot's arity keeps
The browser tier over web-platform-tests caught three colors and animations this turn's own redundancy removal changed the meaning of. - CSS Animations 1 §3 ignores an `!important` declaration inside a keyframe, so the plain one before it is what the engine reads. `border-color:green; border-color:red!important` kept only the important one, which the engine then discards — the element lost its border color rather than gaining a red one (`css-cascade/important-prop.html`). - The rule-level override read the later block's *first* declaration of the property rather than its last, so `#t{color:green}` before `#t{color:red;color:revert-rule}` was compared against the red and dropped. `revert-rule` reads back to that very rule, so the color went green to red (`css-cascade/revert-rule-layer.html`). The last one decides now, which is also what leaves the `revert` family declining on its own terms. - One slot takes the iteration count and two take a time, so `animation:1 2`, `animation:1 1`, `animation:0s 0s 0s` and `transition:0s 0s 0s` are layers no engine reads — and dropping the default from one handed back a layer that runs. Both droppers decline where a layer names more than the slots take. The folds that were right stay: `animation:0s 0s` is still `animation:0s`, `animation:x 1 2s` still loses its count, and an `!important` outside a keyframe still stands over what precedes it. The two changesets this pull request carried are one, as the guide asks, and the `};` recovery case in the html suite names two properties now — with one, the override removal takes the pair it was written to show. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018tNx7sU4SbnKFhFeofDVr5
1 parent 7c5c6d9 commit 37f87b9

5 files changed

Lines changed: 70 additions & 17 deletions

File tree

‎.changeset/016-css-drop-what-is-already-said.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-
Drop a CSS declaration, a shorthand slot or a query condition that says what another already says.
5+
Drop what a declaration, slot or query already says, and add `lowerUnsupported`.

‎.changeset/017-css-lower-unsupported-switch.md‎

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎lib/css/syntax.js‎

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11917,6 +11917,13 @@ const ZERO_TIME_RE = /^[+-]?(?:0+\.?0*|\.0+)m?s$/i;
1191711917
*/
1191811918
const _dropZeroTimes = (components) => {
1191911919
if (components.length < 2) return null;
11920+
// Two slots take a time — the duration and the delay — so a layer holding a
11921+
// third is one no engine reads, and dropping from it would bring it to life.
11922+
let times = 0;
11923+
for (const one of components) {
11924+
if (_TRANSITION_TIME_RE.test(one)) times++;
11925+
}
11926+
if (times > 2) return null;
1192011927
let kept = components;
1192111928
for (;;) {
1192211929
let at = -1;
@@ -11940,6 +11947,14 @@ const _ONE_COUNT_RE = /^\+?1(?:\.0*)?$/;
1194011947
*/
1194111948
const _dropSingleCount = (components) => {
1194211949
if (components.length < 2) return null;
11950+
// One slot takes it, so a layer naming a second number is one no engine
11951+
// reads, and dropping from it would bring it to life.
11952+
let numbers = 0;
11953+
for (const one of components) {
11954+
const written = _LONE_NUMBER_RE.exec(one);
11955+
if (written !== null && written[1] === undefined) numbers++;
11956+
}
11957+
if (numbers > 1) return null;
1194311958
const at = components.findIndex((one) => _ONE_COUNT_RE.test(one));
1194411959
if (at === -1) return null;
1194511960
const kept = [...components];
@@ -13296,12 +13311,15 @@ const _joinRuleEntries = (before, entry, owned) => {
1329613311
for (const [at, one] of earlier.entries()) {
1329713312
for (const other of names) {
1329813313
if (one.property === other) {
13299-
const value =
13300-
later === null
13301-
? null
13302-
: /** @type {{ value: string }} */ (
13303-
later.find((held) => held.property === other)
13304-
).value;
13314+
let value = null;
13315+
// The last of that property, not the first: it is the one the
13316+
// later block leaves standing, and a `revert` family keyword
13317+
// there reads back to this very rule.
13318+
if (later !== null) {
13319+
for (const held of later) {
13320+
if (held.property === other) value = held.value;
13321+
}
13322+
}
1330513323
// An `!important` earlier declaration still wins, so it is not
1330613324
// behind the later one at all.
1330713325
if (
@@ -14251,6 +14269,13 @@ const _composeBlockBody = (
1425114269
// it stands after, and neither supersedes anything.
1425214270
/** @type {Set<number> | null} */
1425314271
let superseded = null;
14272+
// CSS Animations 1 §3: a keyframe ignores an `!important` declaration, so
14273+
// one there is read for nothing and stands over nothing before it.
14274+
const keyframe =
14275+
owner !== null &&
14276+
path.parent !== null &&
14277+
path.type(path.parent) === T_AT_RULE &&
14278+
KEYFRAMES_AT_RULE_RE.test(path.name(path.parent));
1425414279
// One item can supersede nothing, and most rules hold one or none.
1425514280
if (minify && _transforms.removeDeadRules && items.length > 1) {
1425614281
superseded = new Set();
@@ -14297,7 +14322,9 @@ const _composeBlockBody = (
1429714322
} else {
1429814323
const value = _printedValue(text, colon);
1429914324
const important = path.important(items[i]);
14300-
for (let j = earlier.length - 1; j >= 0; j--) {
14325+
// An `!important` one a keyframe ignores stands over nothing.
14326+
const stands = !keyframe || !important;
14327+
for (let j = stands ? earlier.length - 1 : -1; j >= 0; j--) {
1430114328
const before = earlier[j];
1430214329
// An `!important` earlier one still wins over a later plain
1430314330
// declaration, which leaves the later dead rather than it.

‎test/CssSyntax.unittest.js‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5915,6 +5915,18 @@ describe("CssSyntax minify — the value transforms' rejection paths", () => {
59155915
"a{animation:x 1s infinite}"
59165916
);
59175917
});
5918+
5919+
it.each([
5920+
// One slot takes a `<number>` and two take a `<time>`, so a layer
5921+
// naming more is one no engine reads — dropping from it would hand
5922+
// back a layer that runs.
5923+
["two counts", "a{animation:1 2}"],
5924+
["two counts, both one", "a{animation:1 1}"],
5925+
["three times", "a{animation:0s 0s 0s}"],
5926+
["three times in a transition", "a{transition:0s 0s 0s}"]
5927+
])("keeps a layer naming %s", (_name, css) => {
5928+
expect(minify(css)).toBe(css);
5929+
});
59185930
});
59195931

59205932
describe("a declaration a later one overrides", () => {
@@ -5951,11 +5963,30 @@ describe("CssSyntax minify — the value transforms' rejection paths", () => {
59515963
// is where that pair is written on purpose.
59525964
["a keyword", "a{display:block;display:flex}"],
59535965
// An `!important` earlier declaration still wins.
5954-
["an earlier one that wins", "a{color:red!important;color:blue}"]
5966+
["an earlier one that wins", "a{color:red!important;color:blue}"],
5967+
// CSS Animations 1 §3 ignores an `!important` declaration in a
5968+
// keyframe, so the plain one before it is what the engine reads.
5969+
[
5970+
"one a keyframe ignores",
5971+
"@keyframes k{0%{color:green;color:red!important}}"
5972+
]
59555973
])("keeps it behind %s", (_name, css, printed = css) => {
59565974
expect(minify(css)).toBe(printed);
59575975
});
59585976

5977+
it("reads the later rule's last declaration of the property", () => {
5978+
// `revert-rule` reads back to the rule before it, so the earlier rule
5979+
// is what it reverts to rather than something the later one repeats.
5980+
const reverted =
5981+
"@layer{#t{color:red}}@layer{#t{color:green}#t{color:red;color:revert-rule}}";
5982+
expect(minify(reverted)).toBe(reverted);
5983+
// ...and the last one deciding is what lets the plain pair still join,
5984+
// which the block's own dedupe then reads down to that last one.
5985+
expect(minify("a{color:green}a{color:blue;color:red}")).toBe(
5986+
"a{color:red}"
5987+
);
5988+
});
5989+
59595990
it("reads two rules' declarations only where it may drop one", () => {
59605991
// An empty declaration between two is nothing to read; one without a
59615992
// value is not a declaration this can answer for.

‎test/HtmlSyntax.unittest.js‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5263,9 +5263,9 @@ describe("SourceProcessor — renderEmbeddedSource", () => {
52635263
)
52645264
).toBe("<svg><rect style=padding:0 /></svg>");
52655265
// Nothing opened a block, so a `}` closes none: it is a parse error whose
5266-
// bad declaration runs to the next `;`, which is what a browser reads.
5267-
expect(minify('<p style="background:red;};background:blue">x</p>')).toBe(
5268-
"<p style=background:red;background:blue>x"
5266+
// bad declaration runs to the next `;` — two properties, so both survive it.
5267+
expect(minify('<p style="color:red;};background:blue">x</p>')).toBe(
5268+
"<p style=color:red;background:blue>x"
52695269
);
52705270
// No `;` after it, so the bad declaration runs to the end.
52715271
expect(minify('<p style="background:red;}background:blue">x</p>')).toBe(

0 commit comments

Comments
 (0)