Skip to content

Commit df1f038

Browse files
fix(css): write the 2009 draft's box-flex and box-ordinal-group numbers
A target reading only the 2009 names got no copy of flex or order, since those read a number where the standard property reads more. The copy now takes the standard value's first component when it is a plain non-negative number, plus one for box-ordinal-group (it counts from 1), with auto and none as 1 and 0 for box-flex.
1 parent 7f219ef commit df1f038

7 files changed

Lines changed: 117 additions & 16 deletions

File tree

‎lib/css/data.js‎

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7817,7 +7817,13 @@ const PREFIXED_SPELLING_KEYWORDS = new Map([
78177817
["column-reverse", "reverse"]
78187818
])
78197819
],
7820-
["-moz-box-flex", new Map()],
7820+
[
7821+
"-moz-box-flex",
7822+
new Map([
7823+
["auto", "1"],
7824+
["none", "0"]
7825+
])
7826+
],
78217827
["-moz-box-ordinal-group", new Map()],
78227828
[
78237829
"-moz-box-orient",
@@ -7898,7 +7904,13 @@ const PREFIXED_SPELLING_KEYWORDS = new Map([
78987904
["column-reverse", "reverse"]
78997905
])
79007906
],
7901-
["-webkit-box-flex", new Map()],
7907+
[
7908+
"-webkit-box-flex",
7909+
new Map([
7910+
["auto", "1"],
7911+
["none", "0"]
7912+
])
7913+
],
79027914
["-webkit-box-ordinal-group", new Map()],
79037915
[
79047916
"-webkit-box-orient",
@@ -7935,6 +7947,17 @@ const PREFIXED_SPELLING_KEYWORDS = new Map([
79357947
]
79367948
]);
79377949

7950+
// WHY: The legacy spellings reading a number where the standard property reads
7951+
// more, as `spelling -> offset`: the standard value's first component, when a
7952+
// plain non-negative number, plus the offset — `order:1` is `box-ordinal-group:2`.
7953+
/** @type {Map<string, number>} */
7954+
const PREFIXED_SPELLING_NUMBERS = new Map([
7955+
["-moz-box-flex", 0],
7956+
["-moz-box-ordinal-group", 1],
7957+
["-webkit-box-flex", 0],
7958+
["-webkit-box-ordinal-group", 1]
7959+
]);
7960+
79387961
module.exports.ABSOLUTE_UNIT_SCALE = ABSOLUTE_UNIT_SCALE;
79397962
module.exports.ALPHA_VALUE_PROPERTIES = ALPHA_VALUE_PROPERTIES;
79407963
module.exports.ANGLE_UNITS = ANGLE_UNITS;
@@ -8019,6 +8042,7 @@ module.exports.PREFIXED_AT_RULES = PREFIXED_AT_RULES;
80198042
module.exports.PREFIXED_PROPERTIES = PREFIXED_PROPERTIES;
80208043
module.exports.PREFIXED_SELECTORS = PREFIXED_SELECTORS;
80218044
module.exports.PREFIXED_SPELLING_KEYWORDS = PREFIXED_SPELLING_KEYWORDS;
8045+
module.exports.PREFIXED_SPELLING_NUMBERS = PREFIXED_SPELLING_NUMBERS;
80228046
module.exports.PREFIXED_VALUES = PREFIXED_VALUES;
80238047
module.exports.PREFIX_WINDOWS = PREFIX_WINDOWS;
80248048
module.exports.PREFIX_WINDOW_STARTS = PREFIX_WINDOW_STARTS;

‎lib/css/syntax-parser.js‎

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ const {
5858
PREFIXED_PROPERTIES,
5959
PREFIXED_SELECTORS,
6060
PREFIXED_SPELLING_KEYWORDS,
61+
PREFIXED_SPELLING_NUMBERS,
6162
PREFIXED_VALUES,
6263
PREFIX_WINDOWS,
6364
PREFIX_WINDOW_STARTS,
@@ -8715,11 +8716,14 @@ const _prefixedPropertyName = (property) => {
87158716
return _prefixedPropertyNames.get(property);
87168717
};
87178718

8719+
// A number with no sign, unit or exponent: what a legacy spelling reading one
8720+
// is written with, and what an offset can be added to exactly.
8721+
const _UNSIGNED_NUMBER_REGEXP = /^(?:\d+\.?\d*|\.\d+)$/;
8722+
87188723
/**
87198724
* One prefixed copy of a declaration, for a spelling a target still needs. A
8720-
* spelling whose older property read other keywords carries them with it, and
8721-
* writes nothing at all for a value that property cannot read — the map is its
8722-
* whole grammar.
8725+
* spelling whose older property read other keywords or a number carries them
8726+
* with it, and writes nothing for a value that property cannot read.
87238727
* @param {string} spelling the vendor spelling to write
87248728
* @param {string} text the declaration's printed text
87258729
* @param {number} colon where its `:` sits
@@ -8732,9 +8736,16 @@ const _prefixedDeclaration = (spelling, text, colon) => {
87328736
const value = toLowerCaseIfNeeded(text.slice(colon + 1, end));
87338737
// A CSS-wide keyword is every property's, whatever its own grammar says.
87348738
if (CSS_WIDE_KEYWORDS.has(value)) return spelling + text.slice(colon);
8735-
const legacy = keywords.get(value);
8739+
let legacy = keywords.get(value);
8740+
if (legacy === undefined) {
8741+
const offset = PREFIXED_SPELLING_NUMBERS.get(spelling);
8742+
if (offset === undefined) return "";
8743+
const first = value.split(" ", 1)[0];
8744+
if (!_UNSIGNED_NUMBER_REGEXP.test(first)) return "";
8745+
legacy = offset === 0 ? first : `${Number(first) + offset}`;
8746+
}
87368747
// `!important` and the `;` carry over; the value between them is rewritten.
8737-
return legacy === undefined ? "" : `${spelling}:${legacy}${text.slice(end)}`;
8748+
return `${spelling}:${legacy}${text.slice(end)}`;
87388749
};
87398750

87408751
// WHY: the shape of every name some engine spells its own way — one bit per

‎test/configCases/css/minimize-vendor-prefixes-flexbox-2009/__snapshots__/ConfigCacheTest.snap‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ exports[`ConfigCacheTestCases css minimize-vendor-prefixes-flexbox-2009 minimize
44
Array [
55
"/*! a container, and the keywords the draft renamed */.t01{display:-webkit-box;display:-moz-box;display:flex;-webkit-box-align:start;-moz-box-align:start;align-items:flex-start;-webkit-box-pack:justify;-moz-box-pack:justify;justify-content:space-between}",
66
"/*! one direction is two properties there */.t02{display:-webkit-inline-box;display:-moz-inline-box;display:inline-flex;-webkit-box-orient:vertical;-webkit-box-direction:reverse;-moz-box-orient:vertical;-moz-box-direction:reverse;flex-direction:column-reverse}",
7-
"/*! \`box-flex\` and \`box-ordinal-group\` read numbers, so no copy is written */.t03{flex:1;order:2}",
7+
"/*! \`box-flex\` reads the grow factor, and \`box-ordinal-group\` counts from 1 */.t03{-webkit-box-flex:1;-moz-box-flex:1;flex:1;-webkit-box-ordinal-group:3;-moz-box-ordinal-group:3;order:2}.t05{-webkit-box-flex:2;-moz-box-flex:2;flex:2;-webkit-box-ordinal-group:1;-moz-box-ordinal-group:1;order:0}.t06{-webkit-box-flex:1;-moz-box-flex:1;flex:auto}.t07{-webkit-box-flex:0;-moz-box-flex:0;flex:none}",
8+
"/*! neither reads a number it cannot be given: a negative group, a basis alone */.t08{flex:10px;order:-1}",
89
"/*! a value the draft cannot read gets no copy at all */.t04{justify-content:space-evenly}",
910
]
1011
`;

‎test/configCases/css/minimize-vendor-prefixes-flexbox-2009/__snapshots__/ConfigTest.snap‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ exports[`ConfigTestCases css minimize-vendor-prefixes-flexbox-2009 minimize-vend
44
Array [
55
"/*! a container, and the keywords the draft renamed */.t01{display:-webkit-box;display:-moz-box;display:flex;-webkit-box-align:start;-moz-box-align:start;align-items:flex-start;-webkit-box-pack:justify;-moz-box-pack:justify;justify-content:space-between}",
66
"/*! one direction is two properties there */.t02{display:-webkit-inline-box;display:-moz-inline-box;display:inline-flex;-webkit-box-orient:vertical;-webkit-box-direction:reverse;-moz-box-orient:vertical;-moz-box-direction:reverse;flex-direction:column-reverse}",
7-
"/*! \`box-flex\` and \`box-ordinal-group\` read numbers, so no copy is written */.t03{flex:1;order:2}",
7+
"/*! \`box-flex\` reads the grow factor, and \`box-ordinal-group\` counts from 1 */.t03{-webkit-box-flex:1;-moz-box-flex:1;flex:1;-webkit-box-ordinal-group:3;-moz-box-ordinal-group:3;order:2}.t05{-webkit-box-flex:2;-moz-box-flex:2;flex:2;-webkit-box-ordinal-group:1;-moz-box-ordinal-group:1;order:0}.t06{-webkit-box-flex:1;-moz-box-flex:1;flex:auto}.t07{-webkit-box-flex:0;-moz-box-flex:0;flex:none}",
8+
"/*! neither reads a number it cannot be given: a negative group, a basis alone */.t08{flex:10px;order:-1}",
89
"/*! a value the draft cannot read gets no copy at all */.t04{justify-content:space-evenly}",
910
]
1011
`;

‎test/configCases/css/minimize-vendor-prefixes-flexbox-2009/style.css‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
.t01 { display: flex; align-items: flex-start; justify-content: space-between }
66
/*! one direction is two properties there */
77
.t02 { display: inline-flex; flex-direction: column-reverse }
8-
/*! `box-flex` and `box-ordinal-group` read numbers, so no copy is written */
8+
/*! `box-flex` reads the grow factor, and `box-ordinal-group` counts from 1 */
99
.t03 { flex: 1; order: 2 }
10+
.t05 { flex: 2 1 0%; order: 0 }
11+
.t06 { flex: auto }
12+
.t07 { flex: none }
13+
/*! neither reads a number it cannot be given: a negative group, a basis alone */
14+
.t08 { flex: 10px; order: -1 }
1015
/*! a value the draft cannot read gets no copy at all */
1116
.t04 { justify-content: space-evenly }

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7616,6 +7616,24 @@ describe("CssSyntax minify — vendor prefixes (properties)", () => {
76167616
).toBe("a{flex-flow:wrap}");
76177617
});
76187618

7619+
it("writes the 2009 draft's number from the standard value", () => {
7620+
// `box-ordinal-group` counts from 1 and `box-flex` reads the grow factor
7621+
// alone; a value neither can be given one writes no copy.
7622+
for (const [css, printed] of [
7623+
["a{order:1}", "a{-webkit-box-ordinal-group:2;order:1}"],
7624+
["a{order:-1}", "a{order:-1}"],
7625+
["a{flex:2 1 0%}", "a{-webkit-box-flex:2;flex:2}"],
7626+
["a{flex:auto}", "a{-webkit-box-flex:1;flex:auto}"],
7627+
["a{flex:none}", "a{-webkit-box-flex:0;flex:none}"],
7628+
["a{flex:10px}", "a{flex:10px}"]
7629+
]) {
7630+
expect(minifyFor(css, ["android 4.3"])).toBe(printed);
7631+
}
7632+
expect(minifyFor("a{order:1;flex:.5}", ["firefox 20"])).toBe(
7633+
"a{-moz-box-ordinal-group:2;order:1;-moz-box-flex:.5;flex:.5}"
7634+
);
7635+
});
7636+
76197637
it("lets an alias a target still reads block the merge around it", () => {
76207638
expect(
76217639
minifyFor(

‎tooling/generate-css-data.js‎

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5903,7 +5903,7 @@ const LOGICAL_SIZE_WINDOWS = [
59035903
["android", "4.4", "57"]
59045904
];
59055905

5906-
/** @type {Map<string, [string, [string, string, string | number][], [string, string][]?][]>} */
5906+
/** @type {Map<string, [string, [string, string, string | number][], [string, string][]?, number?][]>} */
59075907
const PREFIX_SUPPLEMENT = new Map([
59085908
[
59095909
// WHY: Multi-column's own gap, prefixed until the module went unprefixed — Chrome
@@ -6033,7 +6033,7 @@ const PREFIX_SUPPLEMENT = new Map([
60336033
// WHY: The 2009 flexbox draft, which WebKit and Gecko shipped under `display:
60346034
// -webkit-box` / `-moz-box` before the 2012 one (caniuse, through autoprefixer's
60356035
// table). It named each property anew, and no dataset maps the names across.
6036-
// An empty map writes no copy: `box-flex` and `box-ordinal-group` read numbers.
6036+
// `box-flex` reads the grow factor alone, and `auto` and `none` as theirs.
60376037
[
60386038
"flex",
60396039
[
@@ -6045,9 +6045,21 @@ const PREFIX_SUPPLEMENT = new Map([
60456045
["ios_saf", "3.2", "7"],
60466046
["android", "2.1", "4.4"]
60476047
],
6048-
[]
6048+
[
6049+
["auto", "1"],
6050+
["none", "0"]
6051+
],
6052+
0
60496053
],
6050-
["-moz-box-flex", [["firefox", "2", "22"]], []]
6054+
[
6055+
"-moz-box-flex",
6056+
[["firefox", "2", "22"]],
6057+
[
6058+
["auto", "1"],
6059+
["none", "0"]
6060+
],
6061+
0
6062+
]
60516063
]
60526064
],
60536065
[
@@ -6133,9 +6145,10 @@ const PREFIX_SUPPLEMENT = new Map([
61336145
["ios_saf", "3.2", "7"],
61346146
["android", "2.1", "4.4"]
61356147
],
6136-
[]
6148+
[],
6149+
1
61376150
],
6138-
["-moz-box-ordinal-group", [["firefox", "2", "22"]], []]
6151+
["-moz-box-ordinal-group", [["firefox", "2", "22"]], [], 1]
61396152
]
61406153
],
61416154
[
@@ -6457,6 +6470,22 @@ const PREFIX_SUPPLEMENT = new Map([
64576470
* spelling that table writes.
64586471
* @returns {[string, [string, string][]][]} `[spelling, [standard, legacy][]][]`
64596472
*/
6473+
/**
6474+
* The offset each legacy spelling reading a number adds to the standard value's
6475+
* first component, from the fourth element of a `PREFIX_SUPPLEMENT` entry.
6476+
* @returns {[string, number][]} spelling and offset, sorted by spelling
6477+
*/
6478+
const collectPrefixSpellingNumbers = () => {
6479+
/** @type {[string, number][]} */
6480+
const out = [];
6481+
for (const [, stated] of PREFIX_SUPPLEMENT) {
6482+
for (const [spelling, , , offset] of stated) {
6483+
if (offset !== undefined) out.push([spelling, offset]);
6484+
}
6485+
}
6486+
return out.sort((a, b) => (a[0] < b[0] ? -1 : 1));
6487+
};
6488+
64606489
const collectPrefixSpellingKeywords = () => {
64616490
/** @type {[string, [string, string][]][]} */
64626491
const out = [];
@@ -6989,6 +7018,7 @@ const collectData = async () => {
69897018
const eighthTurnCosine = collectEighthTurnCosine();
69907019
const prefixedProperties = collectPrefixTable(bcd.css.properties, true, true);
69917020
const prefixSpellingKeywords = collectPrefixSpellingKeywords();
7021+
const prefixSpellingNumbers = collectPrefixSpellingNumbers();
69927022
const prefixedSelectors = collectPrefixTable(bcd.css.selectors, true);
69937023
const selectorSupport = collectSelectorSupport();
69947024
/** @type {[string, [string, number][]][]} */
@@ -7790,6 +7820,16 @@ ${prefixSpellingKeywords
77907820
.join(",\n")}
77917821
]);
77927822
7823+
// WHY: The legacy spellings reading a number where the standard property reads
7824+
// more, as \`spelling -> offset\`: the standard value's first component, when a
7825+
// plain non-negative number, plus the offset — \`order:1\` is \`box-ordinal-group:2\`.
7826+
/** @type {Map<string, number>} */
7827+
const PREFIXED_SPELLING_NUMBERS = new Map([
7828+
${prefixSpellingNumbers
7829+
.map(([spelling, offset]) => `\t["${spelling}", ${offset}]`)
7830+
.join(",\n")}
7831+
]);
7832+
77937833
module.exports.ABSOLUTE_UNIT_SCALE = ABSOLUTE_UNIT_SCALE;
77947834
module.exports.ALPHA_VALUE_PROPERTIES = ALPHA_VALUE_PROPERTIES;\nmodule.exports.ANGLE_UNITS = ANGLE_UNITS;
77957835
module.exports.ARC_COSINE_DEGREES = ARC_COSINE_DEGREES;
@@ -7834,6 +7874,7 @@ module.exports.PREFIXED_AT_RULES = PREFIXED_AT_RULES;
78347874
module.exports.PREFIXED_PROPERTIES = PREFIXED_PROPERTIES;
78357875
module.exports.PREFIXED_SELECTORS = PREFIXED_SELECTORS;
78367876
module.exports.PREFIXED_SPELLING_KEYWORDS = PREFIXED_SPELLING_KEYWORDS;
7877+
module.exports.PREFIXED_SPELLING_NUMBERS = PREFIXED_SPELLING_NUMBERS;
78377878
module.exports.PREFIXED_VALUES = PREFIXED_VALUES;
78387879
module.exports.PREFIX_WINDOWS = PREFIX_WINDOWS;\nmodule.exports.PREFIX_WINDOW_STARTS = PREFIX_WINDOW_STARTS;
78397880
module.exports.QUARTER_TURN_ANGLE = QUARTER_TURN_ANGLE;

0 commit comments

Comments
 (0)