Skip to content

Commit 3e277a9

Browse files
committed
fix(css): keep initial where an engine reads the keyword apart
`prop: initial` was written back as the property's initial keyword, which is the same declaration only where the engine agrees the two are. Five of the 351 entries name a keyword Chromium reads apart: it refuses `outline-color: auto` and `text-emphasis-position: auto` outright, so the declaration goes, and computes `visible` for the overflow axes and `no-autospace` for `text-autospace` where the spec gives `auto` and `normal`.
1 parent 5307497 commit 3e277a9

10 files changed

Lines changed: 107 additions & 6 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+
Keep `initial` where an engine reads the property's initial keyword apart.

‎.gitattributes‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ test/configCases/html/minimize-shell-end-tags/** eol=lf
3434
test/configCases/html/minimize-lookup-decoded-value/** eol=lf
3535
test/configCases/html/minimize-rewrite-referenced-value/** eol=lf
3636
test/configCases/html/minimize-spell-back-referenced-value/** eol=lf
37+
test/configCases/css/minify-initial-keyword-engine-gap/** eol=lf
3738
test/configCases/performance/unused-reexports/** eol=lf
3839
test/configCases/performance/unused-reexports-error/** eol=lf
3940
examples/* eol=lf

‎lib/css/data.js‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3188,11 +3188,8 @@ const INITIAL_VALUE_KEYWORDS = new Map([
31883188
["offset-path", "none"],
31893189
["offset-position", "normal"],
31903190
["offset-rotate", "auto"],
3191-
["outline-color", "auto"],
31923191
["outline-style", "none"],
31933192
["overflow-anchor", "auto"],
3194-
["overflow-block", "auto"],
3195-
["overflow-inline", "auto"],
31963193
["overflow-wrap", "normal"],
31973194
["overlay", "none"],
31983195
["overscroll-behavior", "auto"],
@@ -3256,7 +3253,6 @@ const INITIAL_VALUE_KEYWORDS = new Map([
32563253
["text-align", "start"],
32573254
["text-align-last", "auto"],
32583255
["text-anchor", "start"],
3259-
["text-autospace", "normal"],
32603256
["text-box", "normal"],
32613257
["text-box-edge", "auto"],
32623258
["text-box-trim", "none"],
@@ -3265,7 +3261,6 @@ const INITIAL_VALUE_KEYWORDS = new Map([
32653261
["text-decoration-skip-ink", "auto"],
32663262
["text-decoration-style", "solid"],
32673263
["text-decoration-thickness", "auto"],
3268-
["text-emphasis-position", "auto"],
32693264
["text-emphasis-style", "none"],
32703265
["text-fit", "none"],
32713266
["text-justify", "auto"],
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigCacheTestCases css minify-initial-keyword-engine-gap minify-initial-keyword-engine-gap should compile 1`] = `".a{outline-color:initial}.b{text-emphasis-position:initial}.c{overflow-block:initial}.d{overflow-inline:initial}.e{text-autospace:initial}.f{text-fit:none}.g{caption-side:top}.h{empty-cells:show}"`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigTestCases css minify-initial-keyword-engine-gap minify-initial-keyword-engine-gap should compile 1`] = `".a{outline-color:initial}.b{text-emphasis-position:initial}.c{overflow-block:initial}.d{overflow-inline:initial}.e{text-autospace:initial}.f{text-fit:none}.g{caption-side:top}.h{empty-cells:show}"`;
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import "./style.css";
2+
3+
// `initial` is only worth replacing where the engine reads the keyword as the
4+
// same declaration.
5+
it("should keep initial where an engine reads the keyword apart", () => {
6+
expect(true).toBe(true);
7+
});
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/* Each spells an initial the spec gives and an engine reads apart from
2+
`initial`, so the keyword is not written back. */
3+
.a { outline-color: initial }
4+
.b { text-emphasis-position: initial }
5+
.c { overflow-block: initial }
6+
.d { overflow-inline: initial }
7+
.e { text-autospace: initial }
8+
9+
/* A property whose keyword the engine does read as `initial` still takes it.
10+
Both are ones this engine implements, so the comparison can see them. */
11+
.f { text-fit: initial }
12+
.g { caption-side: initial }
13+
.h { empty-cells: initial }
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
"use strict";
2+
3+
const fs = require("fs");
4+
const path = require("path");
5+
6+
module.exports = {
7+
afterExecute(options) {
8+
const css = fs.readFileSync(
9+
path.join(options.output.path, "bundle0.css"),
10+
"utf8"
11+
);
12+
expect(css).toMatchSnapshot();
13+
14+
// Chromium refuses the keyword outright, so writing it back drops the
15+
// declaration rather than shortening it.
16+
expect(css).toContain("outline-color:initial");
17+
expect(css).toContain("text-emphasis-position:initial");
18+
// Chromium computes a different value from the keyword the spec names.
19+
expect(css).toContain("overflow-block:initial");
20+
expect(css).toContain("overflow-inline:initial");
21+
expect(css).toContain("text-autospace:initial");
22+
// Where the engine reads the keyword as `initial`, it is still written.
23+
expect(css).toContain("text-fit:none");
24+
expect(css).toContain("caption-side:top");
25+
expect(css).toContain("empty-cells:show");
26+
}
27+
};
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
"use strict";
2+
3+
const MinimizerPlugin = require("minimizer-webpack-plugin");
4+
const cssMinify = require("../../../../lib/css/cssMinify");
5+
6+
/** @type {import("../../../../").Configuration} */
7+
module.exports = {
8+
target: "web",
9+
mode: "production",
10+
output: {
11+
pathinfo: false
12+
},
13+
optimization: {
14+
minimize: true,
15+
minimizer: [
16+
{
17+
apply: (compiler) => {
18+
new MinimizerPlugin({
19+
test: /\.css(\?.*)?$/i,
20+
minify: cssMinify
21+
}).apply(/** @type {EXPECTED_ANY} */ (compiler));
22+
}
23+
}
24+
]
25+
},
26+
experiments: {
27+
css: true
28+
}
29+
};

‎tooling/generate-css-data.js‎

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2747,6 +2747,7 @@ const collectInitialValueKeywords = () => {
27472747
/** @type {[string, string][]} */
27482748
const out = [];
27492749
const stated = new Map(SUPPLEMENT.initialValueKeywords);
2750+
const readsApart = new Set(SUPPLEMENT.initialKeywordsAnEngineReadsApart);
27502751
for (const [name, entry] of Object.entries(properties)) {
27512752
// `mdn-data`'s own types omit the field, which its data does carry.
27522753
const written = /** @type {{ initial?: string | string[] }} */ (entry)
@@ -2773,6 +2774,9 @@ const collectInitialValueKeywords = () => {
27732774
// Chromium: `outline-width:initial` computes to 1.5px at `zoom:2` and
27742775
// `outline-width:medium` to 3px.
27752776
if (lengthKeywords.has(initial)) continue;
2777+
// WHY: The spec states one initial and an engine reads another, so writing
2778+
// the keyword back is a different declaration rather than the same one.
2779+
if (readsApart.has(name)) continue;
27762780
out.push([name, initial]);
27772781
}
27782782
return out.sort((a, b) => (a[0] < b[0] ? -1 : 1));
@@ -3773,7 +3777,7 @@ const eighthTurnEntries = (values) => {
37733777
// Spec prose no dataset states: an equivalence between two spellings, or a
37743778
// judgement about what a construct still does. Each carries the reason it has to
37753779
// be written out rather than derived.
3776-
/** @type {{ cssWideKeywords: string[], cubicBezierKeywords: [string, string][], flexKeywords: [string, string][], fontWeightNumbers: [string, string][], fontStretchPercentages: [string, string][], filterFunctionOmitted: [string, string][], positionKeywordPercentages: [string, string][], legacyPseudoElements: string[], compoundContinuations: string[], featurelessPseudoClasses: string[], initialValueKeywords: [string, string][], unmergeableSlotKeywords: [string, string][], zeroUnitKeepingProperties: string[], calcRejectingProperties: string[], clampedValueRanges: [string, string, number, number][], autoSecondValueProperties: string[], defaultGradientDirections: string[], xAxisTransforms: [string, string][], negativeAcceptingProperties: string[], placeShorthands: string[], oneValuePairShorthands: string[], familyShorthands: string[], orderedShorthands: string[], omittableInitialKeywords: string[], pairLonghandOverrides: [string, string[]][], droppableWhenEmptyAtRules: string[], replacedByNameAtRules: string[], classSpellings: [string, string[]][], absoluteUnitScale: [string, string, number][], unitConversionTargets: string[], angleUnits: string[], colorSpacePrimitives: [string, string][], oklabMatrices: number[][], systemUiStack: string[], colorTransfers: [string, string][], predefinedColorSpaces: [string, string, string, string][], colorPrimaries: [string, number[]][], colorWhitePoints: [string, number[]][], enginesDisagreeOnTransfer: string[], calcConstantValues: [string, string][], quarterTurnAngle: [string, number][], eighthTurnSine: (number | null)[], eighthTurnTangent: (number | null)[], mathFunctionFold: [string, string, string, string, string | null, boolean][], mathPrimitives: [string, string][], predefinedCounterStyles: string[], predefinedCounterNames: string[], cssModulesKeywordSupplement: [string, string, number][] }} */
3780+
/** @type {{ cssWideKeywords: string[], cubicBezierKeywords: [string, string][], flexKeywords: [string, string][], fontWeightNumbers: [string, string][], fontStretchPercentages: [string, string][], filterFunctionOmitted: [string, string][], positionKeywordPercentages: [string, string][], legacyPseudoElements: string[], compoundContinuations: string[], featurelessPseudoClasses: string[], initialValueKeywords: [string, string][], initialKeywordsAnEngineReadsApart: string[], unmergeableSlotKeywords: [string, string][], zeroUnitKeepingProperties: string[], calcRejectingProperties: string[], clampedValueRanges: [string, string, number, number][], autoSecondValueProperties: string[], defaultGradientDirections: string[], xAxisTransforms: [string, string][], negativeAcceptingProperties: string[], placeShorthands: string[], oneValuePairShorthands: string[], familyShorthands: string[], orderedShorthands: string[], omittableInitialKeywords: string[], pairLonghandOverrides: [string, string[]][], droppableWhenEmptyAtRules: string[], replacedByNameAtRules: string[], classSpellings: [string, string[]][], absoluteUnitScale: [string, string, number][], unitConversionTargets: string[], angleUnits: string[], colorSpacePrimitives: [string, string][], oklabMatrices: number[][], systemUiStack: string[], colorTransfers: [string, string][], predefinedColorSpaces: [string, string, string, string][], colorPrimaries: [string, number[]][], colorWhitePoints: [string, number[]][], enginesDisagreeOnTransfer: string[], calcConstantValues: [string, string][], quarterTurnAngle: [string, number][], eighthTurnSine: (number | null)[], eighthTurnTangent: (number | null)[], mathFunctionFold: [string, string, string, string, string | null, boolean][], mathPrimitives: [string, string][], predefinedCounterStyles: string[], predefinedCounterNames: string[], cssModulesKeywordSupplement: [string, string, number][] }} */
37773781

37783782
const SUPPLEMENT = {
37793783
// CSS Values 4's list. `mdn-data` has no `css-wide-keyword` production.
@@ -3863,6 +3867,20 @@ const SUPPLEMENT = {
38633867
// Chromium under both `dir=ltr` and `dir=rtl`: `initial`, `start` and `unset`
38643868
// compute alike and paint the glyph at the same offset.
38653869
initialValueKeywords: [["text-align", "start"]],
3870+
// WHY: Not derivable — `mdn-data` states the initial its spec gives, and `bcd`
3871+
// answers when a value arrived rather than what `initial` computes to. Each of
3872+
// these ships a keyword an engine reads apart from `initial`, so writing it
3873+
// back is a different declaration. Measured in headless Chromium:
3874+
// `outline-color:auto` and `text-emphasis-position:auto` are refused outright,
3875+
// `overflow-block` and `overflow-inline` compute `visible` where the spec says
3876+
// `auto`, and `text-autospace` computes `no-autospace` where it says `normal`.
3877+
initialKeywordsAnEngineReadsApart: [
3878+
"outline-color",
3879+
"overflow-block",
3880+
"overflow-inline",
3881+
"text-autospace",
3882+
"text-emphasis-position"
3883+
],
38663884
// Not derivable, no grammar says the unit matters here: IE 11 drops a unitless
38673885
// `flex-basis`, and Chrome rejects `overflow-clip-margin:0` the spec allows.
38683886
zeroUnitKeepingProperties: ["flex-basis", "overflow-clip-margin"],

0 commit comments

Comments
 (0)