Skip to content

Commit ef0496d

Browse files
fix(css): prefix and drop the 2009 flexbox draft's names (#22320)
* fix(css): prefix and drop the 2009 flexbox draft's names WebKit and Gecko shipped the 2009 flexbox draft under display: -webkit-box and -moz-box, with every property renamed (-webkit-box-align for align-items, -webkit-box-pack for justify-content, and so on). BCD files those as properties of their own that modern engines still read, so a modern target kept every autoprefixed copy. They are now stated as the legacy spellings of the properties that replaced them, with the keywords the draft renamed: dropped beside the standard property where no target needs them, and written for the targets that read only them. A block with no standard twin, like a line clamp, keeps its own. * 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 21172f7 commit ef0496d

16 files changed

Lines changed: 762 additions & 337 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Prefix and drop the 2009 flexbox draft's names like other vendor spellings.

‎lib/css/data.js‎

Lines changed: 398 additions & 323 deletions
Large diffs are not rendered by default.

‎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,
@@ -8725,11 +8726,14 @@ const _prefixedPropertyName = (property) => {
87258726
return _prefixedPropertyNames.get(property);
87268727
};
87278728

8729+
// A number with no sign, unit or exponent: what a legacy spelling reading one
8730+
// is written with, and what an offset can be added to exactly.
8731+
const _UNSIGNED_NUMBER_REGEXP = /^(?:\d+\.?\d*|\.\d+)$/;
8732+
87288733
/**
87298734
* One prefixed copy of a declaration, for a spelling a target still needs. A
8730-
* spelling whose older property read other keywords carries them with it, and
8731-
* writes nothing at all for a value that property cannot read — the map is its
8732-
* whole grammar.
8735+
* spelling whose older property read other keywords or a number carries them
8736+
* with it, and writes nothing for a value that property cannot read.
87338737
* @param {string} spelling the vendor spelling to write
87348738
* @param {string} text the declaration's printed text
87358739
* @param {number} colon where its `:` sits
@@ -8742,9 +8746,16 @@ const _prefixedDeclaration = (spelling, text, colon) => {
87428746
const value = toLowerCaseIfNeeded(text.slice(colon + 1, end));
87438747
// A CSS-wide keyword is every property's, whatever its own grammar says.
87448748
if (CSS_WIDE_KEYWORDS.has(value)) return spelling + text.slice(colon);
8745-
const legacy = keywords.get(value);
8749+
let legacy = keywords.get(value);
8750+
if (legacy === undefined) {
8751+
const offset = PREFIXED_SPELLING_NUMBERS.get(spelling);
8752+
if (offset === undefined) return "";
8753+
const first = value.split(" ", 1)[0];
8754+
if (!_UNSIGNED_NUMBER_REGEXP.test(first)) return "";
8755+
legacy = offset === 0 ? first : `${Number(first) + offset}`;
8756+
}
87468757
// `!important` and the `;` carry over; the value between them is rewritten.
8747-
return legacy === undefined ? "" : `${spelling}:${legacy}${text.slice(end)}`;
8758+
return `${spelling}:${legacy}${text.slice(end)}`;
87488759
};
87498760

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

‎lib/css/syntax-printer.js‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ const {
7171
PREFIXED_AT_RULES,
7272
PREFIXED_PROPERTIES,
7373
PREFIXED_SELECTORS,
74+
PREFIXED_SPELLING_KEYWORDS,
7475
RATIO_PROPERTIES,
7576
REPEAT_STYLE_KEYWORDS,
7677
REPEAT_STYLE_PROPERTIES,
@@ -3598,6 +3599,9 @@ const _standardSpelling = (property) => {
35983599
_standardSpellings = new Map();
35993600
for (const [standard, spellings] of PREFIXED_PROPERTIES) {
36003601
for (const [spelling] of spellings) {
3602+
// One with keywords of its own reads another grammar (`-webkit-box-flex`
3603+
// takes a number), so the standard property's value rules are not its.
3604+
if (PREFIXED_SPELLING_KEYWORDS.has(spelling)) continue;
36013605
_standardSpellings.set(spelling, standard);
36023606
}
36033607
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
android 4.3
2+
firefox 20
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigCacheTestCases css minimize-vendor-prefixes-flexbox-2009 minimize-vendor-prefixes-flexbox-2009 should compile 1`] = `
4+
Array [
5+
"/*! 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}",
6+
"/*! 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\` 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}",
9+
"/*! a value the draft cannot read gets no copy at all */.t04{justify-content:space-evenly}",
10+
]
11+
`;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigTestCases css minimize-vendor-prefixes-flexbox-2009 minimize-vendor-prefixes-flexbox-2009 should compile 1`] = `
4+
Array [
5+
"/*! 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}",
6+
"/*! 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\` 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}",
9+
"/*! a value the draft cannot read gets no copy at all */.t04{justify-content:space-evenly}",
10+
]
11+
`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "./style.css";
2+
3+
it("should write the 2009 flexbox draft's names for a browserslist target that reads only them", () => {
4+
// The emitted stylesheet is snapshotted in test.config.js (afterExecute);
5+
// this keeps a runnable entry so the chunk and its `.css` are produced.
6+
expect(true).toBe(true);
7+
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* Android 4.3 and Firefox 20 read the 2009 flexbox draft, which named every
2+
property anew and read `display: -webkit-box` / `-moz-box` as the container. */
3+
4+
/*! a container, and the keywords the draft renamed */
5+
.t01 { display: flex; align-items: flex-start; justify-content: space-between }
6+
/*! one direction is two properties there */
7+
.t02 { display: inline-flex; flex-direction: column-reverse }
8+
/*! `box-flex` reads the grow factor, and `box-ordinal-group` counts from 1 */
9+
.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 }
15+
/*! a value the draft cannot read gets no copy at all */
16+
.t04 { justify-content: space-evenly }
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"use strict";
2+
3+
const readMinifiedSections = require("../../../helpers/readMinifiedSections");
4+
5+
module.exports = {
6+
findBundle() {
7+
return ["bundle0.js"];
8+
},
9+
afterExecute(options) {
10+
expect(
11+
readMinifiedSections(options.output.path, "bundle0.css")
12+
).toMatchSnapshot();
13+
}
14+
};

0 commit comments

Comments
 (0)