Skip to content

Commit 22a5b52

Browse files
fix(css): keep only the vendor prefix an uncovered browser's engine reads
Every prefix counted as live once the selection named an uncovered browser, which kept Tailwind's -ms- placeholder rules for the default selection: +12 KiB gzip on test/configCases/css/large. Opera Mini reads -o-, KaiOS -moz-, UC, QQ, Baidu and BlackBerry -webkit-; a Node entry renders no CSS, so it no longer turns every rewrite off.
1 parent d9fe4e8 commit 22a5b52

4 files changed

Lines changed: 88 additions & 9 deletions

File tree

‎lib/css/data.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8203,6 +8203,19 @@ const SUPPORT_BROWSERS = [
82038203
"samsung"
82048204
];
82058205

8206+
// The vendor prefix each browserslist name no profile covers reads, by its
8207+
// engine, and null for one reading no CSS. A name missing here reads them all.
8208+
/** @type {Map<string, string | null>} */
8209+
const UNSTATED_BROWSER_PREFIXES = new Map([
8210+
["and_qq", "-webkit-"],
8211+
["and_uc", "-webkit-"],
8212+
["baidu", "-webkit-"],
8213+
["bb", "-webkit-"],
8214+
["kaios", "-moz-"],
8215+
["node", null],
8216+
["op_mini", "-o-"]
8217+
]);
8218+
82068219
// The versions themselves, rows of `SUPPORT_BROWSERS.length` laid end to end,
82078220
// one row per distinct profile: a construct names the row it reads rather than
82088221
// carrying its own copy of it. `NEVER` is a browser that never shipped it.
@@ -9805,6 +9818,7 @@ module.exports.STEP_POSITION_MINIMUM_COUNTS = STEP_POSITION_MINIMUM_COUNTS;
98059818
module.exports.SUBSTITUTION_FUNCTIONS = SUBSTITUTION_FUNCTIONS;
98069819
module.exports.SUPPORTED_FROM = SUPPORTED_FROM;
98079820
module.exports.SUPPORT_BROWSERS = SUPPORT_BROWSERS;
9821+
module.exports.UNSTATED_BROWSER_PREFIXES = UNSTATED_BROWSER_PREFIXES;
98089822
module.exports.getSupportProfiles = getSupportProfiles;
98099823
module.exports.SVG_USER_UNIT_PROPERTIES = SVG_USER_UNIT_PROPERTIES;
98109824
module.exports.SYSTEM_UI_STACK = SYSTEM_UI_STACK;

‎lib/css/syntax-parser.js‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ const {
7474
THROUGH_TRANSFER,
7575
TRANSITION_BEHAVIORS,
7676
UNSHARED_LONGHAND_KEYWORDS,
77+
UNSTATED_BROWSER_PREFIXES,
7778
foldAdd,
7879
foldDivide,
7980
foldMultiply,
@@ -9410,6 +9411,11 @@ let _parsedBrowsersMemo = null;
94109411
// is what a rewrite taking a declaration away has to decline on.
94119412
let _someBrowserUnanswered = false;
94129413
let _someBrowserUnansweredMemo = false;
9414+
// The prefixes those browsers read, by their engines; null for every prefix.
9415+
/** @type {Set<string> | null} */
9416+
let _unstatedPrefixes = null;
9417+
/** @type {Set<string> | null} */
9418+
let _unstatedPrefixesMemo = null;
94139419
// Each axis' table -> its per-construct decision for the selection in hand. Kept
94149420
// per table rather than under one tagged key, so a lookup allocates no string.
94159421
/** @type {Map<Map<string, [string, number][]>, Map<string, Set<string> | null>>} */
@@ -9451,6 +9457,8 @@ const _useBrowsers = (browsers) => {
94519457
const parsed = Array.from({ length: SUPPORT_BROWSERS.length });
94529458
let named = 0;
94539459
let unanswered = false;
9460+
/** @type {Set<string> | null} */
9461+
let unstatedPrefixes = new Set();
94549462
for (const entry of browsers) {
94559463
const space = entry.indexOf(" ");
94569464
const name = space === -1 ? entry : entry.slice(0, space);
@@ -9469,7 +9477,12 @@ const _useBrowsers = (browsers) => {
94699477
const slot =
94709478
version === null ? undefined : SUPPORT_BROWSER_SLOT.get(name);
94719479
if (slot === undefined) {
9480+
const engine = UNSTATED_BROWSER_PREFIXES.get(name);
9481+
// Node renders no CSS, so it is no target a stylesheet answers to.
9482+
if (engine === null) continue;
94729483
unanswered = true;
9484+
if (engine === undefined) unstatedPrefixes = null;
9485+
else if (unstatedPrefixes !== null) unstatedPrefixes.add(engine);
94739486
continue;
94749487
}
94759488
// Every selected version is kept: a prefix window is an interval, so an
@@ -9485,11 +9498,23 @@ const _useBrowsers = (browsers) => {
94859498
// Only browsers nothing states is still a target, which reads nothing known.
94869499
_parsedBrowsersMemo = named === 0 && !unanswered ? null : parsed;
94879500
_someBrowserUnansweredMemo = unanswered;
9501+
_unstatedPrefixesMemo = unstatedPrefixes;
94889502
}
94899503
_prefixBrowsers = _parsedBrowsersMemo;
94909504
_someBrowserUnanswered = _someBrowserUnansweredMemo;
9505+
_unstatedPrefixes = _unstatedPrefixesMemo;
94919506
};
94929507

9508+
/**
9509+
* Whether a target browser the tables do not state reads a vendor prefix, which
9510+
* only its own engine's is.
9511+
* @param {string} prefix the prefix, `-ms-` and the like
9512+
* @returns {boolean} true when such a browser may read it
9513+
*/
9514+
const _unstatedReads = (prefix) =>
9515+
_someBrowserUnanswered &&
9516+
(_unstatedPrefixes === null || _unstatedPrefixes.has(prefix));
9517+
94939518
/**
94949519
* A browserslist version to the same `major * 100000 + minor` integer the table
94959520
* is keyed in. A range (`10.0-10.2`) takes its low end, Safari `TP` is newest,
@@ -9728,8 +9753,9 @@ const _tableNeedsPrefix = (table, prefix, parsed) => {
97289753
*/
97299754
const _prefixIsLive = (prefix) => {
97309755
const parsed = _prefixBrowsers;
9731-
// Told no target, or one nothing states, every prefix is assumed read.
9732-
if (parsed === null || _someBrowserUnanswered) return true;
9756+
// Told no target, every prefix is assumed read; so is one an engine the
9757+
// tables do not state reads.
9758+
if (parsed === null || _unstatedReads(prefix)) return true;
97339759
if (_prefixLiveFor !== parsed) {
97349760
_prefixLiveMemo.clear();
97359761
_prefixLiveFor = parsed;
@@ -9895,7 +9921,10 @@ const _DECORATION_SPELLING = "-webkit-text-decoration";
98959921
*/
98969922
const _prefixRemovable = (table, base, spelling) => {
98979923
// A browser nothing states may be the one still reading the vendor spelling.
9898-
if (_someBrowserUnanswered) return false;
9924+
if (_someBrowserUnanswered) {
9925+
const vendor = VENDOR_PREFIX.exec(spelling);
9926+
if (vendor === null || _unstatedReads(vendor[1])) return false;
9927+
}
98999928
const spellings = table.get(base);
99009929
if (spellings === undefined) return false;
99019930
if (!spellings.some(([known]) => known === spelling)) return false;

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14763,13 +14763,30 @@ describe("CssSyntax minify — a fallback the target reads past", () => {
1476314763
);
1476414764
});
1476514765

14766-
it("keeps a vendor spelling such a selection may be the one to read", () => {
14766+
it("keeps the vendor spellings such a browser's engine reads, and no other", () => {
1476714767
const css =
14768-
"a{-webkit-box-shadow:0 0 1px red;box-shadow:0 0 1px red}e::-moz-selection{color:red}e::selection{color:red}";
14769-
expect(minifyFor(css, [...MODERN, "op_mini all"])).toBe(css);
14770-
expect(minifyFor(css, MODERN)).toBe(
14771-
"a{box-shadow:0 0 1px red}e::selection{color:red}"
14768+
"a{-webkit-box-shadow:0 0 1px red;box-shadow:0 0 1px red}e::-moz-selection{color:red}e::selection{color:red}e::-ms-input-placeholder{color:red}";
14769+
const modern = "a{box-shadow:0 0 1px red}e::selection{color:red}";
14770+
expect(minifyFor(css, MODERN)).toBe(modern);
14771+
// Opera Mini renders with Presto, which reads `-o-` alone.
14772+
expect(minifyFor(css, [...MODERN, "op_mini all"])).toBe(modern);
14773+
// KaiOS is Gecko, and UC Blink.
14774+
expect(minifyFor(css, [...MODERN, "kaios 2.5"])).toBe(
14775+
"a{box-shadow:0 0 1px red}e::-moz-selection{color:red}e::selection{color:red}"
1477214776
);
14777+
expect(minifyFor(css, [...MODERN, "and_uc 15.5"])).toBe(
14778+
"a{-webkit-box-shadow:0 0 1px red;box-shadow:0 0 1px red}e::selection{color:red}"
14779+
);
14780+
// A name no table knows the engine of may read any of them.
14781+
expect(minifyFor(css, [...MODERN, "unknown 1"])).toBe(
14782+
"a{-webkit-box-shadow:0 0 1px red;box-shadow:0 0 1px red}e::-moz-selection{color:red}e::selection{color:red}e::-ms-input-placeholder{color:red}"
14783+
);
14784+
});
14785+
14786+
it("reads a Node entry as no target, which renders no CSS", () => {
14787+
expect(
14788+
minifyFor("a{color:rgba(0,0,0,.5)}", [...MODERN, "node 22.23.0"])
14789+
).toBe("a{color:#00000080}");
1477314790
});
1477414791

1477514792
it("leaves the prefixes such a selection asks for alone", () => {

‎tooling/generate-css-data.js‎

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5810,6 +5810,20 @@ const NEVER = 1e9;
58105810
// literal — which is what lets prettier pack the tables many to a line.
58115811
const NEVER_LITERAL = "1e9";
58125812

5813+
// WHY: browserslist names these, but no compat dataset states what they read, so
5814+
// each is known only by its engine: Opera Mini renders with Presto, KaiOS with
5815+
// Gecko, UC, QQ and Baidu with Blink and BlackBerry 10 with WebKit. Node renders
5816+
// no CSS. The minifier keeps the one prefix such an engine reads and no other.
5817+
const UNSTATED_BROWSER_PREFIXES = [
5818+
["and_qq", "-webkit-"],
5819+
["and_uc", "-webkit-"],
5820+
["baidu", "-webkit-"],
5821+
["bb", "-webkit-"],
5822+
["kaios", "-moz-"],
5823+
["node", null],
5824+
["op_mini", "-o-"]
5825+
];
5826+
58135827
/**
58145828
* One version as the emitted tables spell it.
58155829
* @param {number} version an encoded version
@@ -8442,6 +8456,11 @@ const NEVER = ${NEVER_LITERAL};
84428456
/** @type {string[]} */
84438457
const SUPPORT_BROWSERS = ${JSON.stringify(pooled.browsers)};
84448458
8459+
// The vendor prefix each browserslist name no profile covers reads, by its
8460+
// engine, and null for one reading no CSS. A name missing here reads them all.
8461+
/** @type {Map<string, string | null>} */
8462+
const UNSTATED_BROWSER_PREFIXES = new Map(${JSON.stringify(UNSTATED_BROWSER_PREFIXES)});
8463+
84458464
// The versions themselves, rows of \`SUPPORT_BROWSERS.length\` laid end to end,
84468465
// one row per distinct profile: a construct names the row it reads rather than
84478466
// carrying its own copy of it. \`NEVER\` is a browser that never shipped it.
@@ -8559,7 +8578,7 @@ module.exports.QUARTER_TURN_ANGLE = QUARTER_TURN_ANGLE;
85598578
module.exports.RATIO_PROPERTIES = RATIO_PROPERTIES;\nmodule.exports.REPEAT_STYLE_KEYWORDS = REPEAT_STYLE_KEYWORDS;\nmodule.exports.REPEAT_STYLE_PROPERTIES = REPEAT_STYLE_PROPERTIES;\nmodule.exports.RGB_TO_NAME = RGB_TO_NAME;
85608579
module.exports.SELECTOR_FUNCTIONS = SELECTOR_FUNCTIONS;\nmodule.exports.getSelectorSupportedFrom = getSelectorSupportedFrom;\nmodule.exports.SHADOW_PROPERTIES = SHADOW_PROPERTIES;\nmodule.exports.getShorthandInitialKeywords = getShorthandInitialKeywords;\nmodule.exports.getShorthandLonghands = getShorthandLonghands;\nmodule.exports.SLASH_BOX_SHORTHANDS = SLASH_BOX_SHORTHANDS;\nmodule.exports.SLASH_LONGHANDS = SLASH_LONGHANDS;\nmodule.exports.SRGB_SPACE = SRGB_SPACE;
85618580
module.exports.STEPPED_FUNCTIONS = STEPPED_FUNCTIONS;\nmodule.exports.STEP_POSITION_MINIMUM_COUNTS = STEP_POSITION_MINIMUM_COUNTS;
8562-
module.exports.SUBSTITUTION_FUNCTIONS = SUBSTITUTION_FUNCTIONS;\nmodule.exports.SUPPORTED_FROM = SUPPORTED_FROM;\nmodule.exports.SUPPORT_BROWSERS = SUPPORT_BROWSERS;\nmodule.exports.getSupportProfiles = getSupportProfiles;\nmodule.exports.SVG_USER_UNIT_PROPERTIES = SVG_USER_UNIT_PROPERTIES;\nmodule.exports.SYSTEM_UI_STACK = SYSTEM_UI_STACK;\nmodule.exports.THROUGH_MATRIX = THROUGH_MATRIX;\nmodule.exports.THROUGH_TRANSFER = THROUGH_TRANSFER;\nmodule.exports.TRANSITION_BEHAVIORS = TRANSITION_BEHAVIORS;
8581+
module.exports.SUBSTITUTION_FUNCTIONS = SUBSTITUTION_FUNCTIONS;\nmodule.exports.SUPPORTED_FROM = SUPPORTED_FROM;\nmodule.exports.SUPPORT_BROWSERS = SUPPORT_BROWSERS;\nmodule.exports.UNSTATED_BROWSER_PREFIXES = UNSTATED_BROWSER_PREFIXES;\nmodule.exports.getSupportProfiles = getSupportProfiles;\nmodule.exports.SVG_USER_UNIT_PROPERTIES = SVG_USER_UNIT_PROPERTIES;\nmodule.exports.SYSTEM_UI_STACK = SYSTEM_UI_STACK;\nmodule.exports.THROUGH_MATRIX = THROUGH_MATRIX;\nmodule.exports.THROUGH_TRANSFER = THROUGH_TRANSFER;\nmodule.exports.TRANSITION_BEHAVIORS = TRANSITION_BEHAVIORS;
85638582
module.exports.UNIT_CONVERSION_TARGETS = UNIT_CONVERSION_TARGETS;
85648583
module.exports.UNIT_GROUP_BASE = UNIT_GROUP_BASE;\nmodule.exports.UNSHARED_LONGHAND_KEYWORDS = UNSHARED_LONGHAND_KEYWORDS;\nmodule.exports.getValueSupportPacked = getValueSupportPacked;\nmodule.exports.X_AXIS_TRANSFORMS = X_AXIS_TRANSFORMS;
85658584
module.exports.ZERO_ANGLE_FUNCTIONS = ZERO_ANGLE_FUNCTIONS;

0 commit comments

Comments
 (0)