@@ -53,6 +53,7 @@ const {
5353 MERGEABLE_AT_RULES,
5454 MERGE_LONGHANDS,
5555 NEVER,
56+ NTH_PSEUDO_FUNCTIONS,
5657 ONE_VALUE_PAIR_SHORTHANDS,
5758 ORDERED_LONGHANDS,
5859 PAIR_LONGHANDS,
@@ -9166,6 +9167,26 @@ const _readsAll = (profile) => {
91669167 return true;
91679168};
91689169
9170+ // The browsers standing for the three engines that ship today.
9171+ const _ENGINE_BROWSERS = ["chrome", "firefox", "safari"].map((name) =>
9172+ SUPPORT_BROWSERS.indexOf(name)
9173+ );
9174+
9175+ /**
9176+ * Whether each engine shipping today reads an ability in some release, which is
9177+ * what a selector needs where no selection names the browsers to answer for.
9178+ * @param {number} profile its `getSupportProfiles()` row
9179+ * @returns {boolean} true when Chromium, Gecko and WebKit all read it
9180+ */
9181+ const _readByEveryEngine = (profile) => {
9182+ const row = profile * SUPPORT_BROWSERS.length;
9183+ const profiles = getSupportProfiles();
9184+ for (const at of _ENGINE_BROWSERS) {
9185+ if (profiles[row + at] === NEVER) return false;
9186+ }
9187+ return true;
9188+ };
9189+
91699190/**
91709191 * The vendor spellings at least one target browser still needs for a construct —
91719192 * a target at version V needs spelling S when some `[browser, from, to]` of S has
@@ -14828,21 +14849,29 @@ const _STRING = String.raw`"(?:[^"\\]|\\[\s\S])*"|'(?:[^'\\]|\\[\s\S])*'`;
1482814849// The matchers Selectors 4 §6 defines, and only `i` after one: an engine that
1482914850// cannot read the `s` modifier drops the selector, and with it the list.
1483014851const _ATTRIBUTE = String.raw`\[(?:${_IDENT}\|)?${_IDENT}(?:[~|^$*]?=(?:${_IDENT}|${_STRING})(?: [iI])?)?\]`;
14831- // A pseudo-class or pseudo-element with no selector inside it: argument-less, or
14832- // the `An+B` of `:nth-*()`, whose grammar is closed. One holding a selector list
14833- // (`:not()`, `:is()`, `:has()`) would have to have its argument checked too.
14834- const _PSEUDO = String.raw`::?[-\w]+(?:\(\s*(?:[-+\dn ]+|[oO][dD][dD]|[eE][vV][eE][nN])\s*\))?`;
14835- const _COMPOUND = `(?:\\*|${_IDENT}|[.#]${_IDENT}|${_ATTRIBUTE})(?:[.#]${_IDENT}|${_ATTRIBUTE}|${_PSEUDO})*`;
14852+ const _LEGACY_ELEMENT_NAMES = [...LEGACY_PSEUDO_ELEMENTS].join("|");
14853+ // A pseudo-class with no selector inside it: argument-less, or the `An+B` of an
14854+ // `:nth-*()`, whose grammar is closed — the one argument a shape may carry.
14855+ const _PSEUDO_CLASS = String.raw`:(?!(?:${_LEGACY_ELEMENT_NAMES})(?![-\w]))(?:(?:${[
14856+ ...NTH_PSEUDO_FUNCTIONS
14857+ ].join("|")})\(\s*(?:[-+\dn ]+|odd|even)\s*\)|[-\w]+(?![-\w(]))`;
14858+ // A pseudo-element ends the selector it is in: anything after it is no shape
14859+ // an engine parses.
14860+ const _PSEUDO_ELEMENT = String.raw`(?:::[-\w]+|:(?:${_LEGACY_ELEMENT_NAMES}))(?![-\w(])`;
14861+ const _COMPOUND = `(?:\\*|${_IDENT}|[.#]${_IDENT}|${_ATTRIBUTE})(?:[.#]${_IDENT}|${_ATTRIBUTE}|${_PSEUDO_CLASS})*`;
14862+ const _COMBINATOR = "(?:\\s*[>+~]\\s*|\\s+)";
1483614863const _JOINABLE_SELECTOR_RE = new RegExp(
14837- `^${_COMPOUND}(?:(?:\\s*[>+~]\\s*|\\s+)${_COMPOUND})*$`
14864+ `^(?:${_COMPOUND}${_COMBINATOR})*${_COMPOUND}(?:${_PSEUDO_ELEMENT})?$`,
14865+ "i"
1483814866);
1483914867
1484014868// The same, for a rule nested in another: `&` joins there because an engine that
1484114869// cannot read it cannot read the block holding it either, so both selectors are
1484214870// dropped together rather than one taking the other down.
1484314871const _NESTED_COMPOUND = `(?:&(?:${_COMPOUND})?|${_COMPOUND})`;
1484414872const _JOINABLE_NESTED_RE = new RegExp(
14845- `^${_NESTED_COMPOUND}(?:(?:\\s*[>+~]\\s*|\\s+)${_NESTED_COMPOUND})*$`
14873+ `^(?:${_NESTED_COMPOUND}${_COMBINATOR})*${_NESTED_COMPOUND}(?:${_PSEUDO_ELEMENT})?$`,
14874+ "i"
1484614875);
1484714876
1484814877// A keyframe selector is a percentage or `to` — `from` is already printed `0%`.
@@ -14922,7 +14951,10 @@ const _pseudosReadable = (prelude) => {
1492214951 end++;
1492314952 }
1492414953 if (end === from) return false;
14925- const spelling = toLowerCaseIfNeeded(prelude.slice(i, end));
14954+ // A pseudo taking an argument is a different entry from the bare one.
14955+ const spelling = `${toLowerCaseIfNeeded(prelude.slice(i, end))}${
14956+ prelude.charCodeAt(end) === CC_LEFT_PARENTHESIS ? "(" : ""
14957+ }`;
1492614958 let reads = _selectorReadMemo.get(spelling);
1492714959 if (reads === undefined) {
1492814960 // A pseudo-element reads with one colon as well as two, and the table
@@ -14935,7 +14967,11 @@ const _pseudosReadable = (prelude) => {
1493514967 // A pseudo the table does not name is one no engine is known to parse —
1493614968 // a vendor spelling, a CSS-modules one, or simply newer than the data —
1493714969 // and no selection makes it safe, so this precedes the target check.
14938- reads = since !== undefined && _readsAll(since);
14970+ reads =
14971+ since !== undefined &&
14972+ (_prefixBrowsers === null
14973+ ? _readByEveryEngine(since)
14974+ : _readsAll(since));
1493914975 _selectorReadMemo.set(spelling, reads);
1494014976 }
1494114977 if (!reads) return false;
@@ -15806,7 +15842,10 @@ const _nothingBetweenShadows = (items, texts, from, to, declared, subjects) => {
1580615842
1580715843// The last compound of a selector the joinable shape accepted, once attribute
1580815844// selectors and pseudos are gone: what either holds may look like a combinator.
15809- const _SUBJECT_STRIP_RE = new RegExp(`${_ATTRIBUTE}|${_PSEUDO}`, "g");
15845+ const _SUBJECT_STRIP_RE = new RegExp(
15846+ `${_ATTRIBUTE}|${_PSEUDO_CLASS}|${_PSEUDO_ELEMENT}`,
15847+ "gi"
15848+ );
1581015849const _SUBJECT_TYPE_RE = /(?:^|[\s>+~])([-\w\u00A0-\uFFFF]+)[^\s>+~]*$/;
1581115850
1581215851/**
0 commit comments