Skip to content

Commit 7c57559

Browse files
test(css): read a repeated selector's importance as the cascade does
A selector written twice took the later block's value for every property, but CSS Cascade 4 §6.2 keeps an important declaration over a normal one written after it — so `.a{--x:red!important}.a{--x:blue}` compared unequal to the one rule the cascade reads it as. The comparison corpus is installed in one step per cache too: `run` stops at the first command that fails, so a single block cost both corpora where only one install went wrong. Co-authored-by: aryanraj45 <[email protected]>
1 parent 078cd32 commit 7c57559

3 files changed

Lines changed: 37 additions & 8 deletions

File tree

‎.github/workflows/test.yml‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,15 @@ jobs:
343343
# comparisons install. Not fatal — the suite reads whichever fixtures are
344344
# there and reports the tier as not built when the install did not land, so
345345
# a registry outage costs that corpus rather than the job.
346-
- name: Install the comparison corpus
346+
# One step each: `run` stops at the first command that fails, so a single
347+
# block would cost both corpora where only one install went wrong.
348+
- name: Install the CSS comparison corpus
347349
continue-on-error: true
348-
run: |
349-
yarn benchmark:css-tools:setup
350-
yarn benchmark:html-tools:setup
350+
run: yarn benchmark:css-tools:setup
351+
352+
- name: Install the HTML comparison corpus
353+
continue-on-error: true
354+
run: yarn benchmark:html-tools:setup
351355

352356
- name: Cache jest result
353357
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0

‎test/helpers/syntaxEquivalence.js‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -596,10 +596,13 @@ const installHelpers = () => {
596596
for (const source of own || [probe.style]) {
597597
for (let at = 0; at < source.length; at++) {
598598
const property = source.item(at);
599-
stated.set(property, [
600-
source.getPropertyValue(property),
601-
source.getPropertyPriority(property)
602-
]);
599+
// CSS Cascade 4 §6.2: an important declaration is not overridden by a
600+
// normal one written after it, so the later block does not take it.
601+
const priority = source.getPropertyPriority(property);
602+
const earlier = stated.get(property);
603+
if (earlier === undefined || priority !== "" || earlier[1] === "") {
604+
stated.set(property, [source.getPropertyValue(property), priority]);
605+
}
603606
}
604607
}
605608
/** @type {string[]} */

‎test/syntaxEquivalence.spectest.js‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,28 @@ describe("printer output in real Chrome", () => {
655655
FILE_TIMEOUT
656656
);
657657

658+
// CSS Cascade 4 §6.2: a normal declaration written after an important one
659+
// does not override it, so the later block is the dead one.
660+
it(
661+
"reads a repeated selector's importance as the cascade does",
662+
async () => {
663+
const differences = await compareStylesheets([
664+
{
665+
name: "important-then-normal",
666+
raw: ".a{--x:red!important}.a{--x:blue}",
667+
min: ".a{--x:red!important}"
668+
},
669+
{
670+
name: "normal-then-normal",
671+
raw: ".a{--y:red}.a{--y:blue}",
672+
min: ".a{--y:blue}"
673+
}
674+
]);
675+
expect(differences).toEqual([]);
676+
},
677+
FILE_TIMEOUT
678+
);
679+
658680
// A value that is not itself a color still carries them, and the computed
659681
// value keeps the space each was written in.
660682
it(

0 commit comments

Comments
 (0)