Skip to content

Commit ad0b593

Browse files
test(css): cover the value-support reader where the minimizer's worker hides it
`minimize-dead-fallbacks` drives `_valueReadByTarget`'s whole call branch, but the minimizer runs it inside the worker pool, where coverage cannot follow — the integration flag reports 16.27% of the diff against the unit flag's 80.76%, so the branch reads as untested. Cover it from `CssSyntax.unittest.js`, which runs the printer in process: one case per argument kind it can name and per kind it cannot, both sides of the target gate, and the empty call whose guard is load-bearing — without it an invalid `light-dark()` would drop the declaration before it. `collectValueSupport` takes the BCD property tree as a defaulted argument, as `collectLaterColorNames` and `collectColorFunctions` already do, so a stub can drive the grammar filter (`is_transitionable` is no value of `display`) and the row-less tree its throw names.
1 parent 4700010 commit ad0b593

4 files changed

Lines changed: 116 additions & 2 deletions

File tree

‎cspell.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,7 @@
490490
"toplevel",
491491
"totalmem",
492492
"traceur",
493+
"transitionable",
493494
"translatex",
494495
"translatey",
495496
"translatez",

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11004,3 +11004,86 @@ describe("CssSyntax — the per-transform switches are independent", () => {
1100411004
});
1100511005
});
1100611006

11007+
11008+
describe("CssSyntax minify — a fallback the target reads past", () => {
11009+
const MODERN = ["chrome 130", "firefox 130", "safari 18"];
11010+
const LEGACY = ["chrome 60", "firefox 60", "safari 11"];
11011+
11012+
it("drops the declaration before a color function every target reads", () => {
11013+
expect(minifyFor("a{color:red;color:lab(50% 100 -100)}", MODERN)).toBe(
11014+
"a{color:lab(50% 100 -100)}"
11015+
);
11016+
});
11017+
11018+
it("keeps it where one selected engine reads no such function", () => {
11019+
expect(minifyFor("a{color:red;color:lab(50% 100 -100)}", LEGACY)).toBe(
11020+
"a{color:red;color:lab(50% 100 -100)}"
11021+
);
11022+
});
11023+
11024+
it("names a hue's angle unit among the arguments it can read", () => {
11025+
expect(minifyFor("a{color:red;color:lch(50% 130 20deg)}", MODERN)).toBe(
11026+
"a{color:lch(50% 130 20deg)}"
11027+
);
11028+
});
11029+
11030+
it("names a plain hex argument, which is what a color pair is written as", () => {
11031+
expect(minifyFor("a{color:red;color:light-dark(#fff,#000)}", MODERN)).toBe(
11032+
"a{color:light-dark(#fff,#000)}"
11033+
);
11034+
});
11035+
11036+
it("names a color argument spelled as a color", () => {
11037+
expect(minifyFor("a{color:#fff;color:light-dark(red,blue)}", MODERN)).toBe(
11038+
"a{color:light-dark(red,blue)}"
11039+
);
11040+
});
11041+
11042+
it("leaves a hex stating an alpha to the target's own question", () => {
11043+
expect(
11044+
minifyFor("a{color:red;color:light-dark(transparent,#000)}", MODERN)
11045+
).toBe("a{color:red;color:light-dark(#0000,#000)}");
11046+
});
11047+
11048+
it("reads no keyword argument the color grammar alone names", () => {
11049+
expect(
11050+
minifyFor("a{color:red;color:light-dark(canvastext,#000)}", MODERN)
11051+
).toBe("a{color:red;color:light-dark(canvastext,#000)}");
11052+
});
11053+
11054+
it("reads no predefined space, which is a keyword of its own", () => {
11055+
expect(minifyFor("a{color:red;color:color(display-p3 1 0 0)}", MODERN)).toBe(
11056+
"a{color:red;color:color(display-p3 1 0 0)}"
11057+
);
11058+
});
11059+
11060+
it("reads no relative color, whose origin is no argument of that kind", () => {
11061+
expect(minifyFor("a{color:red;color:oklch(from red l c h)}", MODERN)).toBe(
11062+
"a{color:red;color:oklch(from red l c h)}"
11063+
);
11064+
});
11065+
11066+
it("reads no mix, which names its space as a keyword", () => {
11067+
expect(
11068+
minifyFor("a{color:red;color:color-mix(in oklch,red,blue)}", MODERN)
11069+
).toBe("a{color:red;color:color-mix(in oklch,red,blue)}");
11070+
});
11071+
11072+
it("reads no function the table does not name", () => {
11073+
expect(
11074+
minifyFor("a{background:red;background:linear-gradient(red,blue)}", MODERN)
11075+
).toBe("a{background:red;background:linear-gradient(red,blue)}");
11076+
});
11077+
11078+
it("reads no empty call, which names a value no engine can read", () => {
11079+
expect(minifyFor("a{color:red;color:light-dark()}", MODERN)).toBe(
11080+
"a{color:red;color:light-dark()}"
11081+
);
11082+
});
11083+
11084+
it("reads no value holding more than one call", () => {
11085+
expect(minifyFor("a{filter:none;filter:blur(1px) invert(1)}", MODERN)).toBe(
11086+
"a{filter:none;filter:blur(1px)invert()}"
11087+
);
11088+
});
11089+
});

‎test/unitCases/CssValueSyntax.unittest.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ const {
1717
collectOmittableInitialKeywords,
1818
collectRatioProperties,
1919
collectUnsharedLonghandKeywords,
20+
collectValueSupport,
2021
collectZeroUnitAmbiguousProperties,
2122
isPlainSupport,
2223
isSpelledSyntax,
@@ -886,6 +887,28 @@ describe("CssValueSyntax", () => {
886887
"no <named-color> carries a row of its own: bcd moved"
887888
);
888889
});
890+
891+
it("takes a property's keyword only where its own grammar names one, past bcd's own `__compat`", () => {
892+
// Cast because bcd's tree is recursive where `BcdNode` names only its
893+
// own `__compat`, so a stub holding sub-features is not one literally.
894+
const tree = /** @type {EXPECTED_ANY} */ ({
895+
__compat: {},
896+
display: {
897+
__compat: { support: {} },
898+
flex: { __compat: { support: {} } },
899+
is_transitionable: { __compat: { support: {} } }
900+
}
901+
});
902+
expect(
903+
collectValueSupport([], tree).map(([spelling]) => spelling)
904+
).toEqual(["display flex"]);
905+
});
906+
907+
it("rejects a tree where no value carries a row of its own", () => {
908+
expect(() => collectValueSupport([], {})).toThrow(
909+
"no value carries a support row of its own: bcd moved"
910+
);
911+
});
889912
});
890913

891914
describe("the file those tables are emitted into", () => {

‎tooling/generate-css-data.js‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5427,17 +5427,23 @@ const collectSelectorSupport = () => {
54275427
* filed under rather than for one it never names, which is why `canvastext` is
54285428
* absent and its ancient `<system-color>` parent is not read for it.
54295429
* @param {string[]} colorFunctions the functions `<color>` names
5430+
* @param {{ [name: string]: BcdNode }=} propertyNodes the BCD property tree to read
54305431
* @returns {[string, [string, number][]][]} the versions, by spelling
54315432
*/
5432-
const collectValueSupport = (colorFunctions) => {
5433+
const collectValueSupport = (
5434+
colorFunctions,
5435+
propertyNodes = /** @type {{ [name: string]: BcdNode }} */ (
5436+
/** @type {unknown} */ (bcd.css.properties)
5437+
)
5438+
) => {
54335439
/** @type {[string, [string, number][]][]} */
54345440
const table = [];
54355441
for (const name of colorFunctions) {
54365442
const node = /** @type {EXPECTED_ANY} */ (bcd.css.types.color)[name];
54375443
if (!node || !node.__compat) continue;
54385444
table.push([name, collectSupportedFrom([`css.types.color.${name}`])]);
54395445
}
5440-
for (const [property, node] of Object.entries(bcd.css.properties)) {
5446+
for (const [property, node] of Object.entries(propertyNodes)) {
54415447
if (property.startsWith("__")) continue;
54425448
const entry = /** @type {PartialPropertyTable} */ (properties)[property];
54435449
if (!entry || !entry.syntax || entry.status !== "standard") continue;
@@ -7683,6 +7689,7 @@ module.exports.collectOmittableInitialKeywords =
76837689
module.exports.collectRatioProperties = collectRatioProperties;
76847690
module.exports.collectUnsharedLonghandKeywords =
76857691
collectUnsharedLonghandKeywords;
7692+
module.exports.collectValueSupport = collectValueSupport;
76867693
module.exports.collectZeroUnitAmbiguousProperties =
76877694
collectZeroUnitAmbiguousProperties;
76887695
module.exports.isPlainSupport = isPlainSupport;

0 commit comments

Comments
 (0)