Skip to content

Commit 4c89486

Browse files
build(css): name each pseudo once in the selector support table (#22153)
`selectors.json` states `::cue` and `::cue()` separately, and the spelling the print looks up is derived from the syntax, so both reached the table and the second shadowed the first in the `Map` it becomes. Deduped on the derived spelling, which drops `::cue` and `:host` to one entry each; both resolve to the same compat node, so the profiles were identical and the generated output is otherwise unchanged. The TODO above `_JOINABLE_SELECTOR_RE` goes with it. Its stated blocker is gone — `SELECTOR_SUPPORTED_FROM` already says which engine reads which spelling — but the widening it asks for measures as a loss: over Bootstrap 5 it saves 195 raw bytes and costs one gzip byte, and gzip decides.
1 parent d7e0fd9 commit 4c89486

3 files changed

Lines changed: 13 additions & 10 deletions

File tree

‎lib/css/data.js‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6762,7 +6762,6 @@ const SELECTOR_SUPPORTED_FROM = new Map([
67626762
["::before", 23],
67636763
["::checkmark", 24],
67646764
["::cue", 25],
6765-
["::cue", 25],
67666765
["::details-content", 26],
67676766
["::file-selector-button", 27],
67686767
["::first-letter", 28],
@@ -6807,7 +6806,6 @@ const SELECTOR_SUPPORTED_FROM = new Map([
68076806
[":has", 58],
68086807
[":has-slotted", 59],
68096808
[":host", 48],
6810-
[":host", 48],
68116809
[":host-context", 60],
68126810
[":hover", 61],
68136811
[":in-range", 62],

‎lib/css/syntax.js‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14711,10 +14711,10 @@ const _ruleEntryOf = (node, text) => {
1471114711
// id or attribute selector joined by a combinator, and nothing else. One
1471214712
// selector an engine cannot parse invalidates the whole list, so joining a
1471314713
// selector it keeps to one it drops loses the first: a pseudo it does not know,
14714-
// or a shape the parser passed through without validating.
14715-
// TODO widen this to the pseudos `mdn-data`'s `selectors.json` names, derived in
14716-
// the generator like every other table, once it says which engine reads which
14717-
// prefix.
14714+
// or a shape the parser passed through without validating. Widening this to the
14715+
// pseudos `mdn-data` names earns nothing a user downloads: over Bootstrap 5 it
14716+
// saves 195 raw bytes and costs one gzip byte, and which engine reads a pseudo
14717+
// is already `_pseudosReadable`'s answer rather than this shape's.
1471814718
const _IDENT = String.raw`(?:[-\w\u00A0-\uFFFF]|\\[\s\S])+`;
1471914719
const _STRING = String.raw`"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'`;
1472014720
// The matchers Selectors 4 §6 defines, and only `i` after one: an engine that

‎tooling/generate-css-data.js‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5405,16 +5405,21 @@ const collectSupportedFrom = (paths) => {
54055405
const collectSelectorSupport = () => {
54065406
/** @type {[string, [string, number][]][]} */
54075407
const table = [];
5408+
// `::cue` and `::cue()` are two entries naming one pseudo, and the spelling
5409+
// is what the print looks up — so the second would shadow the first in the
5410+
// `Map` this becomes rather than say anything new.
5411+
/** @type {Set<string>} */
5412+
const spellings = new Set();
54085413
for (const entry of Object.values(selectors)) {
54095414
if (entry.status !== "standard") continue;
54105415
const match = /^(::?)([-\w]+)/.exec(entry.syntax || "");
54115416
if (match === null) continue;
54125417
const [, colons, name] = match;
54135418
if (!bcd.css.selectors[name]) continue;
5414-
table.push([
5415-
`${colons}${name}`,
5416-
collectSupportedFrom([`css.selectors.${name}`])
5417-
]);
5419+
const spelling = `${colons}${name}`;
5420+
if (spellings.has(spelling)) continue;
5421+
spellings.add(spelling);
5422+
table.push([spelling, collectSupportedFrom([`css.selectors.${name}`])]);
54185423
}
54195424
return table.sort((a, b) => (a[0] < b[0] ? -1 : 1));
54205425
};

0 commit comments

Comments
 (0)