Skip to content

Commit 1ba0408

Browse files
committed
fix(css): drop the guard the text cannot trip, and cover what the run reaches
`text` is built from this rule's own `prelude` and `rest` a few lines above, so the check that they match could never fail — it did not fire once across 4232 parses of the comparison corpus. The run's cases are covered instead: a parent declaring nothing, a selector the hoist wrote twice, which the list reads back out, a deeper hoist feeding the run above it, and a parent written as a list.
1 parent c6b4dd3 commit 1ba0408

2 files changed

Lines changed: 26 additions & 5 deletions

File tree

‎lib/css/syntax-printer.js‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4545,12 +4545,10 @@ const printer = (path, writer) => {
45454545
);
45464546
if (nested === null) return "";
45474547
if (out !== text) return out + nested;
4548+
// The run wrote this rule's selectors into itself, so what it returns is
4549+
// the whole of both — `text` being this rule's own `prelude` and `rest`.
45484550
if (nested.length !== 0) {
4549-
// The run wrote this rule's selectors into itself, and only where
4550-
// nothing but them and its block stood here.
4551-
return _nestedTookParent && text === prelude + rest
4552-
? nested
4553-
: text + nested;
4551+
return _nestedTookParent ? nested : text + nested;
45544552
}
45554553
// Where the block is what a sibling is compared against, remember the rule
45564554
// so the parent parts it without re-scanning for the `{`. An at-rule

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10731,6 +10731,29 @@ describe("CssSyntax minify — the rules a hoist leaves side by side", () => {
1073110731
);
1073210732
});
1073310733

10734+
it("joins a run under a rule that declares nothing itself", () => {
10735+
expect(minifyFor("a{.x{top:0}.y{top:0}}", T)).toBe("a .x,a .y{top:0}");
10736+
});
10737+
10738+
it("reads back out a selector the hoist wrote twice", () => {
10739+
// The join concatenates, so one rule written twice lands in the list
10740+
// twice — and a list is a set.
10741+
expect(minifyFor("a{.x{top:0}.x{top:0}}", T)).toBe("a .x{top:0}");
10742+
});
10743+
10744+
it("joins what a deeper hoist feeds the run above it", () => {
10745+
expect(minifyFor("a{.b{.c{top:0}.d{top:0}}}", T)).toBe(
10746+
"a .b .c,a .b .d{top:0}"
10747+
);
10748+
expect(minifyFor("a{top:0;.b{top:0;.c{top:0}}}", T)).toBe(
10749+
"a,a .b,a .b .c{top:0}"
10750+
);
10751+
});
10752+
10753+
it("takes in a parent written as a list", () => {
10754+
expect(minifyFor("a,b{top:0;.x{top:0}}", T)).toBe(":is(a,b) .x,a,b{top:0}");
10755+
});
10756+
1073410757
it("leaves the list as written where selectors are not shortened", () => {
1073510758
expect(
1073610759
minifyForWith("a{.y{top:0}.x{top:0}}", T, { shortenSelectors: false })

0 commit comments

Comments
 (0)