Skip to content

Commit 0b15d4c

Browse files
committed
fix(css): ask only the shorthand whose lowering keeps it
`_writtenValue` reads the value off the first declaration the lowering wrote, which is the shorthand only where the lowering keeps it. `inset`, `place-*` and the pair shorthands are written as longhands alone, so it would have read a longhand's value under the shorthand's name. Nothing consumed it, the drop declining those for its own reasons, but the answer was wrong. Asked about `text-decoration` alone now.
1 parent 7ee169b commit 0b15d4c

3 files changed

Lines changed: 30 additions & 11 deletions

File tree

‎lib/css/syntax-parser.js‎

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13629,14 +13629,10 @@ const _withColorFallback = (one) => {
1362913629
return fallback === null ? one : fallback + one;
1363013630
};
1363113631

13632-
// The shorthands `_expandUnsupportedShorthand` may write as something else,
13633-
// so a property that is none of them is read by what it says.
13634-
const LOWERED_SHORTHANDS = new Set([
13635-
...PLACE_SHORTHANDS,
13636-
...ONE_VALUE_PAIR_SHORTHANDS,
13637-
"inset",
13638-
"text-decoration"
13639-
]);
13632+
// The shorthands whose lowering keeps the shorthand itself, which is the one
13633+
// shape a later value can be read off. `inset`, `place-*` and the pair
13634+
// shorthands are written as longhands alone, so nothing later writes those.
13635+
const LOWERED_SHORTHANDS = new Set(["text-decoration"]);
1364013636

1364113637
/**
1364213638
* The longhand declarations a shorthand the target cannot read says, from the
@@ -13731,8 +13727,8 @@ const _writtenValue = (text, colon, property) => {
1373113727
}
1373213728
const expanded = _expandUnsupportedShorthand(text);
1373313729
if (expanded === null) return _printedValue(text, colon);
13734-
// The lowering writes the shorthand first, so its value stands in front of
13735-
// the longhands written beside it.
13730+
// The shorthand stands in front of the longhands written beside it, which is
13731+
// what `LOWERED_SHORTHANDS` names the shorthands this may be asked about by.
1373613732
const at = expanded.indexOf(":");
1373713733
const end = expanded.indexOf(";", at);
1373813734
return at === -1 || end === -1

‎test/external/wpt‎

Submodule wpt updated 1651 files

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10754,6 +10754,29 @@ describe("CssSyntax minify — the declaration a lowered shorthand kills", () =>
1075410754
expect(minifyFor(css, T)).toBe(css);
1075510755
});
1075610756

10757+
it.each([
10758+
// These lowerings write the longhands alone, so nothing later writes the
10759+
// property at all — what stands in front of it is read as it was written.
10760+
[
10761+
"inset",
10762+
"a{inset:10px;inset:10px 20px 30px 40px}",
10763+
"a{top:10px;right:10px;bottom:10px;left:10px;top:10px;right:20px;bottom:30px;left:40px}"
10764+
],
10765+
[
10766+
"place-items",
10767+
"a{place-items:center;place-items:center start}",
10768+
"a{place-items:center;place-items:center start}"
10769+
],
10770+
[
10771+
"overflow",
10772+
"a{overflow:hidden;overflow:hidden auto}",
10773+
"a{overflow:hidden;overflow:hidden auto}"
10774+
],
10775+
["gap", "a{gap:1px;gap:1px 2px}", "a{gap:1px;gap:1px 2px}"]
10776+
])("keeps what stands in front of a lowered %s", (_name, css, expected) => {
10777+
expect(minifyFor(css, ["chrome 80"])).toBe(expected);
10778+
});
10779+
1075710780
it("keeps both with the rewrite off", () => {
1075810781
const css = "a{text-decoration:overline;text-decoration:underline dotted}";
1075910782
expect(minifyForWith(css, T, { lowerUnsupported: false })).toBe(css);

0 commit comments

Comments
 (0)