Skip to content

Commit dd68bd1

Browse files
authored
Set selector syntax to selector name when possible (#1848)
The syntax of selectors is often not formally defined in specs. For selectors that are function-like such as `:nth-child()`, we'll have to see how specs can be updated. For selectors that are keyword-like such as `:visited`, updating the specs seems more confusing than anything else though: the syntax of the selector goes without saying, it is simply the selector's name. This update makes Reffy set the selector's syntax to be the selector's name when the selector is keyword-like.
1 parent dd31482 commit dd68bd1

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

src/browserlib/extract-cssdfn.mjs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,21 @@ export default function () {
306306
delete value.pureSyntax;
307307
}
308308

309+
// Specs typically do not make the syntax of selectors such as `:visited`
310+
// explicit because it essentially goes without saying: the syntax is the
311+
// selector's name itself. Note that the syntax of selectors that are
312+
// function-like such as `:nth-child()` cannot be inferred in the same way.
313+
for (const selector of res.selectors) {
314+
if (!selector.value && !selector.name.match(/\(/)) {
315+
selector.value = selector.name;
316+
}
317+
for (const subSelector of selector.values ?? []) {
318+
if (!subSelector.value && !subSelector.name.match(/\(/)) {
319+
subSelector.value = subSelector.name;
320+
}
321+
}
322+
}
323+
309324
// Report warnings
310325
if (warnings.length > 0) {
311326
res.warnings = warnings;

test/extract-css.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -668,11 +668,13 @@ that spans multiple lines */
668668
css: [
669669
{
670670
name: ":open",
671-
prose: "The :open pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “open” state."
671+
prose: "The :open pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “open” state.",
672+
value: ":open"
672673
},
673674
{
674675
name: ":closed",
675-
prose: "The :closed pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “closed” state."
676+
prose: "The :closed pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “closed” state.",
677+
value: ":closed"
676678
}
677679
]
678680
},
@@ -1234,10 +1236,12 @@ that spans multiple lines */
12341236
css: [{
12351237
name: '::first-letter',
12361238
prose: 'The ::first-letter pseudo-element represents the first letter.',
1239+
value: '::first-letter',
12371240
values: [{
12381241
name: '::prefix',
12391242
type: 'selector',
1240-
prose: 'The ::prefix represents the preceding punctuation of the ::first-letter element.'
1243+
prose: 'The ::prefix represents the preceding punctuation of the ::first-letter element.',
1244+
value: '::prefix'
12411245
}]
12421246
}]
12431247
},

0 commit comments

Comments
 (0)