Skip to content

Commit 5b3e3c3

Browse files
fix(css): join an :nth-*() only over an argument CSS reads as An+B
The shape took any run of digits, signs, n and spaces, so :nth-child(3 n) or (n2) joined a rule an engine then dropped with its neighbor.
1 parent 128a610 commit 5b3e3c3

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎.changeset/107-css-join-invalid-selectors.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
"webpack": patch
33
---
44

5-
Keep a CSS rule apart from an identical neighbor whose selector no browser parses, which a join would drop it with.
5+
Keep CSS rules apart from a neighbor whose selector no browser parses.

‎lib/css/syntax-parser.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14854,7 +14854,9 @@ const _LEGACY_ELEMENT_NAMES = [...LEGACY_PSEUDO_ELEMENTS].join("|");
1485414854
// `:nth-*()`, whose grammar is closed — the one argument a shape may carry.
1485514855
const _PSEUDO_CLASS = String.raw`:(?!(?:${_LEGACY_ELEMENT_NAMES})(?![-\w]))(?:(?:${[
1485614856
...NTH_PSEUDO_FUNCTIONS
14857-
].join("|")})\(\s*(?:[-+\dn ]+|odd|even)\s*\)|[-\w]+(?![-\w(]))`;
14857+
].join(
14858+
"|"
14859+
)})\(\s*(?:odd|even|[-+]?(?:\d*n(?:\s*[-+]\s*\d+)?|\d+))\s*\)|[-\w]+(?![-\w(]))`;
1485814860
// A pseudo-element ends the selector it is in: anything after it is no shape
1485914861
// an engine parses.
1486014862
const _PSEUDO_ELEMENT = String.raw`(?:::[-\w]+|:(?:${_LEGACY_ELEMENT_NAMES}))(?![-\w(])`;

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6067,6 +6067,12 @@ describe("CssSyntax minify — the value transforms' rejection paths", () => {
60676067
["a pseudo-class belongs to `@page`", "a{top:0}b:first{top:0}"],
60686068
["a pseudo takes no argument", "a{top:0}b:hover(odd){top:0}"],
60696069
["a pseudo goes without the argument it needs", "a{top:0}b:nth-child{top:0}"],
6070+
// CSS Syntax 3 §6 reads `An+B` only with no space inside `An` or after a
6071+
// leading sign, and one sign before `B`.
6072+
["an `An+B` has a space inside `An`", "a{top:0}b:nth-child(3 n){top:0}"],
6073+
["...or no `n` to stand for", "a{top:0}b:nth-child(n2){top:0}"],
6074+
["...or two signs", "a{top:0}b:nth-child(+-n){top:0}"],
6075+
["...or two before `B`", "a{top:0}b:nth-child(2n++1){top:0}"],
60706076
["...as does a pseudo-element", "a{top:0}b::part{top:0}"],
60716077
["a pseudo-element is followed in its compound", "a{top:0}b:before.c{top:0}"],
60726078
["...or by another compound", "a{top:0}b:before c{top:0}"],

0 commit comments

Comments
 (0)