Skip to content

Commit 52e389a

Browse files
fix(css): read a BCD entry the same way everywhere a spelling's arrival is
`collectSupportedFrom` took an entry BCD later removed as the arrival, so an ability could survive past the version that stopped reading it. The other two readings already excluded one; all three now share `isPlainSupport`. No table today has a removed plain entry, so `lib/css/data.js` is byte-identical.
1 parent 3a5bddd commit 52e389a

2 files changed

Lines changed: 45 additions & 30 deletions

File tree

‎test/CssValueSyntax.unittest.js‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
collectRatioProperties,
1717
collectUnsharedLonghandKeywords,
1818
collectZeroUnitAmbiguousProperties,
19+
isPlainSupport,
1920
isSpelledSyntax,
2021
longhandType,
2122
parseValueSyntax,
@@ -410,6 +411,26 @@ describe("CssValueSyntax", () => {
410411
});
411412
});
412413

414+
describe("isPlainSupport", () => {
415+
it("reads a bare arrival as the plain spelling", () => {
416+
expect(isPlainSupport({ version_added: "10" })).toBe(true);
417+
});
418+
419+
it.each([
420+
["a prefixed one", { version_added: "10", prefix: "-webkit-" }],
421+
[
422+
"one spelled another way",
423+
{ version_added: "10", alternative_name: "-webkit-box" }
424+
],
425+
["one behind a flag", { version_added: "10", flags: [{}] }],
426+
["one BCD later removed", { version_added: "10", version_removed: "30" }]
427+
])("is not %s", (_why, entry) => {
428+
// Support that ended is the one every reading of a BCD entry has to
429+
// exclude: a target past the removal no longer reads the construct.
430+
expect(isPlainSupport(entry)).toBe(false);
431+
});
432+
});
433+
413434
describe("isSpelledSyntax", () => {
414435
it("spells out a group's body through the multiplier over it", () => {
415436
expect(isSpelledSyntax("[ red | blue ]?", new Set())).toBe(true);

‎tooling/generate-css-data.js‎

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4050,11 +4050,25 @@ const SUPPORTED_FEATURES = [
40504050
]
40514051
];
40524052

4053+
/**
4054+
* Whether a BCD support entry is the plain spelling arriving for good. One
4055+
* behind a flag is not support a page can rely on, one spelled with a prefix or
4056+
* another name is not the plain spelling at all, and one BCD later removed is
4057+
* support that ended — reading any of them as the arrival is what would let a
4058+
* construct be written for a target that cannot read it.
4059+
* @param {BcdSupport} entry a BCD support entry
4060+
* @returns {boolean} true when it is the plain spelling, still supported
4061+
*/
4062+
const isPlainSupport = (entry) =>
4063+
!entry.prefix &&
4064+
!entry.alternative_name &&
4065+
!entry.version_removed &&
4066+
!entry.flags;
4067+
40534068
/**
40544069
* When each browser first read every one of a feature's constructs, as
4055-
* `[browserslistName, since][]`. A prefixed, renamed or flagged arrival is not
4056-
* one the plain spelling reaches, so it does not count; a browser BCD never
4057-
* gives it carries `Infinity`, which no version satisfies.
4070+
* `[browserslistName, since][]`. Only a plain arrival counts, and a browser BCD
4071+
* never gives one carries `Infinity`, which no version satisfies.
40584072
* @param {string[]} paths BCD paths that all have to have arrived
40594073
* @returns {[string, number][]} the versions, by browserslist name
40604074
*/
@@ -4073,9 +4087,7 @@ const collectSupportedFrom = (paths) => {
40734087
const names = BCD_TO_BROWSERSLIST.get(bcdBrowser);
40744088
if (names === undefined) continue;
40754089
const entries = Array.isArray(raw) ? raw : [raw];
4076-
const plain = entries.find(
4077-
(entry) => !entry.prefix && !entry.alternative_name && !entry.flags
4078-
);
4090+
const plain = entries.find(isPlainSupport);
40794091
const added = plain ? encodeVersion(plain.version_added) : null;
40804092
for (const name of names) {
40814093
const before = since.get(name);
@@ -4189,22 +4201,10 @@ const collectPrefixes = (compat, name, alternatives) => {
41894201
const entries = Array.isArray(raw) ? raw : [raw];
41904202
let unprefixedFrom = null;
41914203
for (const entry of entries) {
4192-
// An entry BCD later removed never established unprefixed support — the
4193-
// one it ends may be a partial implementation the next refines, but
4194-
// reading a partial one as support is what would drop a spelling an
4195-
// engine still needs (`-webkit-mask`, against a `mask` Chrome has
4196-
// partially had since 1). One behind a flag is not support a page can
4197-
// rely on, one spelled another way is not the unprefixed spelling at
4198-
// all, and the earliest of the rest is the arrival — BCD's newest-first
4199-
// ordering is convention, not schema.
4200-
if (
4201-
entry.prefix ||
4202-
entry.alternative_name ||
4203-
entry.version_removed ||
4204-
entry.flags
4205-
) {
4206-
continue;
4207-
}
4204+
// The earliest plain entry is the arrival — BCD's newest-first ordering is
4205+
// convention, not schema. Reading a removed one as support would drop
4206+
// `-webkit-mask` against a `mask` Chrome has only partially had since 1.
4207+
if (!isPlainSupport(entry)) continue;
42084208
const added = encodeVersion(entry.version_added);
42094209
if (
42104210
added !== null &&
@@ -4378,14 +4378,7 @@ const engineVersionLine = (bcdName, baseName, from) => {
43784378
/** @type {(support: BcdSupport | BcdSupport[] | undefined) => number | null} */
43794379
const unprefixed = (support) => {
43804380
const list = Array.isArray(support) ? support : support ? [support] : [];
4381-
// The same reading of "arrived unprefixed" the window rule above uses.
4382-
const entry = list.find(
4383-
(one) =>
4384-
!one.prefix &&
4385-
!one.alternative_name &&
4386-
!one.version_removed &&
4387-
!one.flags
4388-
);
4381+
const entry = list.find(isPlainSupport);
43894382
return entry ? encodeVersion(entry.version_added) : null;
43904383
};
43914384
/**
@@ -6157,6 +6150,7 @@ module.exports.collectUnsharedLonghandKeywords =
61576150
collectUnsharedLonghandKeywords;
61586151
module.exports.collectZeroUnitAmbiguousProperties =
61596152
collectZeroUnitAmbiguousProperties;
6153+
module.exports.isPlainSupport = isPlainSupport;
61606154
module.exports.isSpelledSyntax = isSpelledSyntax;
61616155
module.exports.longhandType = longhandType;
61626156
module.exports.parseValueSyntax = parseValueSyntax;

0 commit comments

Comments
 (0)