Skip to content

Commit 925d247

Browse files
fix(css): ask two color stops of a gradient only, not of text-decoration
1 parent bafe31c commit 925d247

2 files changed

Lines changed: 15 additions & 6 deletions

File tree

‎lib/css/syntax-parser.js‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14655,7 +14655,8 @@ const _valueReadByTarget = (property, value) => {
1465514655
const fn = toLowerCaseIfNeeded(value.slice(0, open));
1465614656
if (!_readsOverridingValue(_valueSupportedFrom(fn))) return false;
1465714657
if (fn.endsWith("gradient")) {
14658-
return _gradientArgumentsRead(value.slice(open + 1, -1));
14658+
// A one-stop gradient is CSS Images 4's, which not every engine reads yet.
14659+
return _gradientArgumentsRead(value.slice(open + 1, -1), 2);
1465914660
}
1466014661
const args = value.slice(open + 1, -1).match(_COLOR_ARGUMENT_RE);
1466114662
if (args === null) return false;
@@ -14709,12 +14710,11 @@ const _GRADIENT_AMOUNT_RE = /^[+-]?(?:\d+\.?\d*|\.\d+)([a-z]+|%)?$/i;
1470914710
* line, shape or position of keywords and amounts, and stops of a color every
1471014711
* engine names. A call inside, or an interpolation space, is not asked here.
1471114712
* @param {string} inner the printed arguments
14713+
* @param {number} stopsNeeded how many color stops the arguments must hold
1471214714
* @returns {boolean} true when the target reads every one
1471314715
*/
14714-
const _gradientArgumentsRead = (inner) => {
14716+
const _gradientArgumentsRead = (inner, stopsNeeded) => {
1471514717
const args = _splitTopLevelArguments(inner);
14716-
// A one-stop gradient is CSS Images 4's, which not every engine reads yet, so
14717-
// only two stops make the gradient readable everywhere.
1471814718
let stops = 0;
1471914719
for (let index = 0; index < args.length; index++) {
1472014720
// A line, shape or position opens the list alone; a stop is one color
@@ -14764,7 +14764,7 @@ const _gradientArgumentsRead = (inner) => {
1476414764
}
1476514765
if (colors !== 0) stops++;
1476614766
}
14767-
return stops > 1;
14767+
return stops >= stopsNeeded;
1476814768
};
1476914769

1477014770
/**
@@ -14792,7 +14792,7 @@ const _textDecorationRead = (components) => {
1479214792
);
1479314793
if (keywords.includes(toLowerCaseIfNeeded(written))) continue;
1479414794
// A color or an amount, read as a gradient's stop or length is.
14795-
if (!_gradientArgumentsRead(written)) return false;
14795+
if (!_gradientArgumentsRead(written, 0)) return false;
1479614796
}
1479714797
return true;
1479814798
};

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16184,6 +16184,15 @@ describe("CssSyntax minify — a later value no engine reads keeps the one befor
1618416184
expect(dropOverridden(css)).toContain("linear-gradient(red,blue)");
1618516185
});
1618616186

16187+
it("drops a `text-decoration` behind one naming another color", () => {
16188+
expect(
16189+
minifyFor(
16190+
"a{text-decoration:underline blue;text-decoration:underline red}",
16191+
MODERN
16192+
)
16193+
).toBe("a{text-decoration:underline red}");
16194+
});
16195+
1618716196
it("converts an `oklch()` gray, which states no hue to lose", () => {
1618816197
expect(minifyFor("a{color:oklch(50% 0 0)}", MODERN)).toBe(
1618916198
"a{color:#636363}"

0 commit comments

Comments
 (0)