Skip to content

Set selector syntax to selector name when possible #1848

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/browserlib/extract-cssdfn.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,21 @@ export default function () {
delete value.pureSyntax;
}

// Specs typically do not make the syntax of selectors such as `:visited`
// explicit because it essentially goes without saying: the syntax is the
// selector's name itself. Note that the syntax of selectors that are
// function-like such as `:nth-child()` cannot be inferred in the same way.
for (const selector of res.selectors) {
if (!selector.value && !selector.name.match(/\(/)) {
selector.value = selector.name;
}
for (const subSelector of selector.values ?? []) {
if (!subSelector.value && !subSelector.name.match(/\(/)) {
subSelector.value = subSelector.name;
}
}
}

// Report warnings
if (warnings.length > 0) {
res.warnings = warnings;
Expand Down
10 changes: 7 additions & 3 deletions test/extract-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,11 +668,13 @@ that spans multiple lines */
css: [
{
name: ":open",
prose: "The :open pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “open” state."
prose: "The :open pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “open” state.",
value: ":open"
},
{
name: ":closed",
prose: "The :closed pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “closed” state."
prose: "The :closed pseudo-class represents an element that has both “open” and “closed” states, and which is currently in the “closed” state.",
value: ":closed"
}
]
},
Expand Down Expand Up @@ -1234,10 +1236,12 @@ that spans multiple lines */
css: [{
name: '::first-letter',
prose: 'The ::first-letter pseudo-element represents the first letter.',
value: '::first-letter',
values: [{
name: '::prefix',
type: 'selector',
prose: 'The ::prefix represents the preceding punctuation of the ::first-letter element.'
prose: 'The ::prefix represents the preceding punctuation of the ::first-letter element.',
value: '::prefix'
}]
}]
},
Expand Down