Skip to content

Commit c8ada7c

Browse files
fix(css): treat a pseudo-element taking arguments as one too
`::part()` and `::slotted()` print as a single token with their arguments attached, so the branch reading those arguments ran before the one that spots a pseudo-element and the boundary was never set: `::part(label):hover` became `::part(label).hovered`, which matches nothing. The second colon decides it now, whether or not the name takes arguments — `:not(.x):hover` is a functional pseudo-class and still takes the class it was given. Co-Authored-By: Claude Opus 5 <[email protected]> Claude-Session: https://claude.ai/code/session_018tNx7sU4SbnKFhFeofDVr5
1 parent e7c9686 commit c8ada7c

2 files changed

Lines changed: 22 additions & 8 deletions

File tree

‎lib/css/syntax.js‎

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9710,10 +9710,8 @@ const _COMPOUND_BOUNDARY_RE = /^[\s>+~,]/;
97109710

97119711
/**
97129712
* Write each pseudo-class the caller named as the class it gave instead, in the
9713-
* printed parts, in place — so a script can apply the class where the engine
9714-
* reads no such pseudo. Only a plain one standing where a class may: a
9715-
* functional pseudo prints with its arguments attached, and nothing after a
9716-
* pseudo-element is what a class stands in for.
9713+
* printed parts, in place. Nothing after a pseudo-element is replaced: a class
9714+
* cannot stand there.
97179715
* @param {string[]} parts the prelude's printed parts
97189716
* @returns {void}
97199717
*/
@@ -9727,6 +9725,13 @@ const _replacePseudoClasses = (parts) => {
97279725
for (let i = 0; i < parts.length; i++) {
97289726
if (parts[i].length === 0) continue;
97299727
if (_COMPOUND_BOUNDARY_RE.test(parts[i])) afterPseudoElement = false;
9728+
// `::name`, whether or not it takes arguments — `::part()` and `::slotted()`
9729+
// are pseudo-elements as much as `::before` is.
9730+
const doubled =
9731+
second !== -1 &&
9732+
parts[second] === ":" &&
9733+
first !== -1 &&
9734+
parts[first] === ":";
97309735
if (parts[i].includes("(")) {
97319736
// A functional pseudo prints with its arguments attached, and those hold
97329737
// selectors of their own — `:not(:hover)` is the same question one level
@@ -9743,14 +9748,12 @@ const _replacePseudoClasses = (parts) => {
97439748
}
97449749
);
97459750
}
9751+
if (doubled) afterPseudoElement = true;
97469752
} else if (second !== -1 && parts[second] === ":") {
97479753
const name = toLowerCaseIfNeeded(parts[i]);
97489754
// A `::name`, or one of the four a single colon also spells — which the
97499755
// fold above may have just written this as.
9750-
if (
9751-
(first !== -1 && parts[first] === ":") ||
9752-
LEGACY_PSEUDO_ELEMENTS.has(name)
9753-
) {
9756+
if (doubled || LEGACY_PSEUDO_ELEMENTS.has(name)) {
97549757
afterPseudoElement = true;
97559758
} else if (!afterPseudoElement) {
97569759
const written = named.get(name);

‎test/CssSyntax.unittest.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8317,6 +8317,17 @@ describe("CssSyntax minify — pseudo-class replacement", () => {
83178317
expect(withClasses("a:hover::before{color:red}", NAMED)).toBe(
83188318
"a.hovered:before{color:red}"
83198319
);
8320+
// One taking arguments is a pseudo-element all the same.
8321+
expect(withClasses("a::part(label):hover{color:red}", NAMED)).toBe(
8322+
"a::part(label):hover{color:red}"
8323+
);
8324+
expect(withClasses("a::slotted(b):hover{color:red}", NAMED)).toBe(
8325+
"a::slotted(b):hover{color:red}"
8326+
);
8327+
// ...where a functional pseudo-*class* is not, and still takes one.
8328+
expect(withClasses("a:not(.x):hover{color:red}", NAMED)).toBe(
8329+
"a:not(.x).hovered{color:red}"
8330+
);
83208331
});
83218332
});
83228333

0 commit comments

Comments
 (0)