Skip to content

Commit 00d6fbf

Browse files
fix(css): trim only CSS whitespace off a nested selector when lowering
String#trim also takes U+1680 and the other Unicode spaces, which an identifier carries as ordinary characters, so .b<U+1680> became .b.
1 parent 2ca185d commit 00d6fbf

3 files changed

Lines changed: 7 additions & 3 deletions

File tree

‎lib/css/syntax-parser.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19733,6 +19733,7 @@ module.exports._NUMERIC_RE = _NUMERIC_RE;
1973319733
module.exports._atKeywordOf = _atKeywordOf;
1973419734
module.exports._printedSource = _printedSource;
1973519735
module.exports._rawName = _rawName;
19736+
module.exports._trimCssWhiteSpace = _trimCssWhiteSpace;
1973619737
module.exports._declarationsOf = _declarationsOf;
1973719738
module.exports._rulesOf = _rulesOf;
1973819739
module.exports._isImportant = _isImportant;

‎lib/css/syntax-printer.js‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ const {
212212
_takeUnusedRule,
213213
_terminate,
214214
_tokenizeCalc,
215+
_trimCssWhiteSpace,
215216
_unreadableColorFunction,
216217
_unwrapLoneIs,
217218
_valueClasses,
@@ -2240,7 +2241,7 @@ const _resolveNestedPrelude = (prelude, parent) => {
22402241
const reference = _isCompoundSelector(parent) ? parent : `:is(${parent})`;
22412242
const written = _splitSelectorList(prelude);
22422243
for (let i = 0; i < written.length; i++) {
2243-
const one = written[i].trim();
2244+
const one = _trimCssWhiteSpace(written[i]);
22442245
if (_namesParent(one)) {
22452246
written[i] = _substituteAmpersand(one, reference);
22462247
continue;
@@ -2273,7 +2274,7 @@ const _parentNamed = (prelude) => {
22732274
let relative = false;
22742275
let naming = 0;
22752276
for (let i = 0; i < written.length; i++) {
2276-
written[i] = written[i].trim();
2277+
written[i] = _trimCssWhiteSpace(written[i]);
22772278
if (_COMBINATOR_CODES.has(written[i].charCodeAt(0))) relative = true;
22782279
if (_namesParent(written[i])) naming++;
22792280
}

‎test/unitCases/CssSyntax.unittest.js‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12817,7 +12817,9 @@ describe("CssSyntax minify — a nested selector opening on a combinator", () =>
1281712817
["a,e{>b{c{top:0}}}", ":is(:is(a,e)>b) c{top:0}"],
1281812818
["a{d{~b{c{top:0}}}}", "a :is(d~b) c{top:0}"],
1281912819
// A list where only some name `&`: the others keep the parent they imply.
12820-
["a{b,&~d{c{top:0}}}", ":is(a~d,a b) c{top:0}"]
12820+
["a{b,&~d{c{top:0}}}", ":is(a~d,a b) c{top:0}"],
12821+
// U+1680 is an identifier code point, which `String#trim` would take off.
12822+
["a{.b ,~b{c{top:0}}}", ":is(a .b ,a~b) c{top:0}"]
1282112823
])(
1282212824
"writes %s, a rule nested in one opening on a combinator, with no relative argument",
1282312825
(css, out) => {

0 commit comments

Comments
 (0)