From 56e28786b523c5966e31df53d3d4ab7b65bfa73c Mon Sep 17 00:00:00 2001 From: webdevelopersrinu Date: Fri, 14 Aug 2026 18:49:03 +0530 Subject: [PATCH 1/8] =?UTF-8?q?Don't=20space=20out=20`and`/`or`/`not`=20in?= =?UTF-8?q?side=20function=20calls=20in=20`supports-[=E2=80=A6]`=20variant?= =?UTF-8?q?s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The `supports-[…]` variant spaces out the `and`, `or`, and `not` keywords to work around a Chrome bug where `@supports (a)or(b)` is invalid. The replacement was applied to the entire value, including inside function calls where these words can be part of a selector: `supports-[selector(a:not(.foo))]` generated `@supports selector(a: not (.foo))`, an unparsable selector, so the condition silently never matched. Keywords are now only spaced out at the condition level; the contents of function calls like `selector(…)` are left as-is. --- CHANGELOG.md | 1 + packages/tailwindcss/src/variants.test.ts | 37 +++++++++++++++++++++++ packages/tailwindcss/src/variants.ts | 20 ++++++++++-- 3 files changed, 56 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 175a1daa2259..35e236eaa8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Oxide: drop invalid UTF-8 candidates ([#20389](https://github.com/tailwindlabs/tailwindcss/pull/20389)) - `@tailwindcss/vite` no longer forces a full page reload for external files (e.g.: `.php` files) ([#20414](https://github.com/tailwindlabs/tailwindcss/issues/20414)) - Canonicalization: don't merge utilities that reference different theme variables set to CSS-wide keywords like `unset` ([#20417](https://github.com/tailwindlabs/tailwindcss/pull/20417)) +- Don't space out `and`, `or`, and `not` inside function calls like `selector(a:not(.foo))` in `supports-[…]` variants ([#20420](https://github.com/tailwindlabs/tailwindcss/pull/20420)) ## [4.3.3] - 2026-07-16 diff --git a/packages/tailwindcss/src/variants.test.ts b/packages/tailwindcss/src/variants.test.ts index 56b069b315ee..c8948d1cd29d 100644 --- a/packages/tailwindcss/src/variants.test.ts +++ b/packages/tailwindcss/src/variants.test.ts @@ -1424,6 +1424,43 @@ test('sorting `min` and `max` should sort by unit, then by value, then alphabeti `) }) +test('supports: `and`, `or`, and `not` inside function calls are not spaced out', async () => { + expect( + await run([ + 'supports-[selector(a:not(.foo))]:flex', + 'supports-[selector(a:is(.and,.or))]:flex', + 'supports-[(display:grid)or(display:flex)]:grid', + 'supports-[not(display:grid)]:flex', + ]), + ).toMatchInlineSnapshot(` + " + @supports (display: grid) or (display: flex) { + .supports-\\[\\(display\\:grid\\)or\\(display\\:flex\\)\\]\\:grid { + display: grid; + } + } + + @supports not (display: grid) { + .supports-\\[not\\(display\\:grid\\)\\]\\:flex { + display: flex; + } + } + + @supports selector(a:is(.and,.or)) { + .supports-\\[selector\\(a\\:is\\(\\.and\\,\\.or\\)\\)\\]\\:flex { + display: flex; + } + } + + @supports selector(a:not(.foo)) { + .supports-\\[selector\\(a\\:not\\(\\.foo\\)\\)\\]\\:flex { + display: flex; + } + } + " + `) +}) + test('supports', async () => { expect( await run([ diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 79ffe01625a8..6b5752800346 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -937,8 +937,24 @@ export function createVariants(theme: Theme): Variants { // other functions, we can use the value as-is. if (/^[\w-]*\s*\(/.test(value)) { // Chrome has a bug where `(condition1)or(condition2)` is not valid, but - // `(condition1) or (condition2)` is supported. - let query = value.replace(/\b(and|or|not)\b/g, ' $1 ') + // `(condition1) or (condition2)` is supported. Only space out keywords + // in the condition itself, not inside function calls like + // `selector(a:not(.foo))` where `not` is part of a selector. + let parens: boolean[] = [] + let inFunction = 0 + let query = value.replace(/[()]|\b(?:and|or|not)\b/g, (match, offset: number) => { + if (match === '(') { + let head = value.slice(0, offset) + let isFunction = /[\w-]$/.test(head) && !/(?:^|[^\w-])(?:and|or|not)$/.test(head) + parens.push(isFunction) + if (isFunction) inFunction++ + } else if (match === ')') { + if (parens.pop()) inFunction-- + } else if (inFunction === 0) { + return ` ${match} ` + } + return match + }) ruleNode.nodes = [atRule('@supports', query, ruleNode.nodes)] return From 77f02beb68ab2d81a18b9c9f8a620b45829c1aa3 Mon Sep 17 00:00:00 2001 From: webdevelopersrinu Date: Fri, 14 Aug 2026 19:37:20 +0530 Subject: [PATCH 2/8] =?UTF-8?q?Handle=20hyphenated=20function=20names=20an?= =?UTF-8?q?d=20quoted=20parens=20in=20`supports-[=E2=80=A6]`=20conditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tokenize identifiers whole so function names like `foo-not(…)` are not mistaken for the `not` keyword, and skip quoted strings so parens inside values like `selector([data-foo="("])` don't unbalance the function-depth tracking. --- packages/tailwindcss/src/variants.test.ts | 14 ++++++++++ packages/tailwindcss/src/variants.ts | 32 ++++++++++++++--------- 2 files changed, 33 insertions(+), 13 deletions(-) diff --git a/packages/tailwindcss/src/variants.test.ts b/packages/tailwindcss/src/variants.test.ts index c8948d1cd29d..af0df91df0aa 100644 --- a/packages/tailwindcss/src/variants.test.ts +++ b/packages/tailwindcss/src/variants.test.ts @@ -1431,6 +1431,8 @@ test('supports: `and`, `or`, and `not` inside function calls are not spaced out' 'supports-[selector(a:is(.and,.or))]:flex', 'supports-[(display:grid)or(display:flex)]:grid', 'supports-[not(display:grid)]:flex', + 'supports-[foo-not(display:grid)]:flex', + 'supports-[selector([data-foo="("])or(display:grid)]:flex', ]), ).toMatchInlineSnapshot(` " @@ -1440,12 +1442,24 @@ test('supports: `and`, `or`, and `not` inside function calls are not spaced out' } } + @supports foo-not(display:grid) { + .supports-\\[foo-not\\(display\\:grid\\)\\]\\:flex { + display: flex; + } + } + @supports not (display: grid) { .supports-\\[not\\(display\\:grid\\)\\]\\:flex { display: flex; } } + @supports selector([data-foo="("]) or (display: grid) { + .supports-\\[selector\\(\\[data-foo\\=\\"\\(\\"\\]\\)or\\(display\\:grid\\)\\]\\:flex { + display: flex; + } + } + @supports selector(a:is(.and,.or)) { .supports-\\[selector\\(a\\:is\\(\\.and\\,\\.or\\)\\)\\]\\:flex { display: flex; diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 6b5752800346..114971c6828e 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -942,19 +942,25 @@ export function createVariants(theme: Theme): Variants { // `selector(a:not(.foo))` where `not` is part of a selector. let parens: boolean[] = [] let inFunction = 0 - let query = value.replace(/[()]|\b(?:and|or|not)\b/g, (match, offset: number) => { - if (match === '(') { - let head = value.slice(0, offset) - let isFunction = /[\w-]$/.test(head) && !/(?:^|[^\w-])(?:and|or|not)$/.test(head) - parens.push(isFunction) - if (isFunction) inFunction++ - } else if (match === ')') { - if (parens.pop()) inFunction-- - } else if (inFunction === 0) { - return ` ${match} ` - } - return match - }) + let query = value.replace( + /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[()]|[\w-]+/g, + (match, offset: number) => { + if (match === '(') { + let head = value.slice(0, offset) + let isFunction = /[\w-]$/.test(head) && !/(?:^|[^\w-])(?:and|or|not)$/.test(head) + parens.push(isFunction) + if (isFunction) inFunction++ + } else if (match === ')') { + if (parens.pop()) inFunction-- + } else if ( + inFunction === 0 && + (match === 'and' || match === 'or' || match === 'not') + ) { + return ` ${match} ` + } + return match + }, + ) ruleNode.nodes = [atRule('@supports', query, ruleNode.nodes)] return From 0dca3aa20a2aa666fe3c8674d7fd237cd7841a42 Mon Sep 17 00:00:00 2001 From: webdevelopersrinu Date: Fri, 14 Aug 2026 19:48:32 +0530 Subject: [PATCH 3/8] =?UTF-8?q?Skip=20escaped=20characters=20when=20tracki?= =?UTF-8?q?ng=20parens=20in=20`supports-[=E2=80=A6]`=20conditions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A lone escaped paren outside a string (e.g. a class named `.foo\(` in `selector(…)`) unbalanced the function-depth tracking, leaving a following top-level `or` unspaced. --- packages/tailwindcss/src/variants.test.ts | 7 +++++++ packages/tailwindcss/src/variants.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/tailwindcss/src/variants.test.ts b/packages/tailwindcss/src/variants.test.ts index af0df91df0aa..79e3f527797c 100644 --- a/packages/tailwindcss/src/variants.test.ts +++ b/packages/tailwindcss/src/variants.test.ts @@ -1433,6 +1433,7 @@ test('supports: `and`, `or`, and `not` inside function calls are not spaced out' 'supports-[not(display:grid)]:flex', 'supports-[foo-not(display:grid)]:flex', 'supports-[selector([data-foo="("])or(display:grid)]:flex', + 'supports-[selector(.foo\\(bar)or(display:grid)]:flex', ]), ).toMatchInlineSnapshot(` " @@ -1454,6 +1455,12 @@ test('supports: `and`, `or`, and `not` inside function calls are not spaced out' } } + @supports selector(.foo\\(bar) or (display: grid) { + .supports-\\[selector\\(\\.foo\\\\\\(bar\\)or\\(display\\:grid\\)\\]\\:flex { + display: flex; + } + } + @supports selector([data-foo="("]) or (display: grid) { .supports-\\[selector\\(\\[data-foo\\=\\"\\(\\"\\]\\)or\\(display\\:grid\\)\\]\\:flex { display: flex; diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 114971c6828e..a2a9e0b8d6a3 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -943,7 +943,7 @@ export function createVariants(theme: Theme): Variants { let parens: boolean[] = [] let inFunction = 0 let query = value.replace( - /"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[()]|[\w-]+/g, + /\\.|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[()]|[\w-]+/g, (match, offset: number) => { if (match === '(') { let head = value.slice(0, offset) From e532ee047e10070684c3176f0361b9ba6f1a33ba Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Aug 2026 21:12:17 +0200 Subject: [PATCH 4/8] use ValueParser --- packages/tailwindcss/src/variants.ts | 38 ++++++++++------------------ 1 file changed, 14 insertions(+), 24 deletions(-) diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index a2a9e0b8d6a3..06380365d325 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -937,30 +937,20 @@ export function createVariants(theme: Theme): Variants { // other functions, we can use the value as-is. if (/^[\w-]*\s*\(/.test(value)) { // Chrome has a bug where `(condition1)or(condition2)` is not valid, but - // `(condition1) or (condition2)` is supported. Only space out keywords - // in the condition itself, not inside function calls like - // `selector(a:not(.foo))` where `not` is part of a selector. - let parens: boolean[] = [] - let inFunction = 0 - let query = value.replace( - /\\.|"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'|[()]|[\w-]+/g, - (match, offset: number) => { - if (match === '(') { - let head = value.slice(0, offset) - let isFunction = /[\w-]$/.test(head) && !/(?:^|[^\w-])(?:and|or|not)$/.test(head) - parens.push(isFunction) - if (isFunction) inFunction++ - } else if (match === ')') { - if (parens.pop()) inFunction-- - } else if ( - inFunction === 0 && - (match === 'and' || match === 'or' || match === 'not') - ) { - return ` ${match} ` - } - return match - }, - ) + // `(condition1) or (condition2)` is supported. + let changed = false + let ast = ValueParser.parse(value) + for (let node of ast) { + if ( + node.kind === 'function' && + (node.value === 'and' || node.value === 'or' || node.value === 'not') + ) { + changed = true + node.value = ` ${node.value} ` + } + } + + let query = changed ? ValueParser.toCss(ast) : value ruleNode.nodes = [atRule('@supports', query, ruleNode.nodes)] return From 6a381f53c745c97ad53187237312af378556111d Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Aug 2026 21:25:26 +0200 Subject: [PATCH 5/8] update CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cec411709a46..5fec361f5959 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `@tailwindcss/vite` no longer forces a full page reload for external files (e.g.: `.php` files) ([#20414](https://github.com/tailwindlabs/tailwindcss/issues/20414)) - Canonicalization: don't merge utilities that reference different theme variables set to CSS-wide keywords like `unset` ([#20417](https://github.com/tailwindlabs/tailwindcss/pull/20417)) - Don't generate utilities when a modifier is used that would otherwise be silently ignored (e.g. `rounded-sm/[5]`, `shadow-sm/foo`, `stroke-2/50`) ([#20419](https://github.com/tailwindlabs/tailwindcss/pull/20419)) -- Don't space out `and`, `or`, and `not` inside function calls like `selector(a:not(.foo))` in `supports-[…]` variants ([#20420](https://github.com/tailwindlabs/tailwindcss/pull/20420)) +- Only normalize top-level `and`, `or`, and `not` keywords in `supports-[…]` variants (e.g. `selector(a: not (.foo))` → `selector(a:not(.foo))`) ([#20420](https://github.com/tailwindlabs/tailwindcss/pull/20420)) ## [4.3.3] - 2026-07-16 From 999755d1c3a9a971389a1af002a03d6eb70967fd Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Aug 2026 21:32:08 +0200 Subject: [PATCH 6/8] move tests into existing `supports` tests --- packages/tailwindcss/src/variants.test.ts | 98 +++++++++++------------ 1 file changed, 46 insertions(+), 52 deletions(-) diff --git a/packages/tailwindcss/src/variants.test.ts b/packages/tailwindcss/src/variants.test.ts index 79e3f527797c..7a6aa245d705 100644 --- a/packages/tailwindcss/src/variants.test.ts +++ b/packages/tailwindcss/src/variants.test.ts @@ -1424,9 +1424,20 @@ test('sorting `min` and `max` should sort by unit, then by value, then alphabeti `) }) -test('supports: `and`, `or`, and `not` inside function calls are not spaced out', async () => { +test('supports', async () => { expect( await run([ + 'supports-gap:grid', + 'supports-[display:grid]:flex', + 'supports-[selector(A_>_B)]:flex', + 'supports-[font-format(opentype)]:grid', + 'supports-[(display:grid)_and_font-format(opentype)]:grid', + 'supports-[font-tech(color-COLRv1)]:flex', + 'supports-[var(--test)]:flex', + 'supports-[--test]:flex', + + // Only top-level and/or/not should have spaces around them. We should + // ignore and/or/not inside of `selector(…)` 'supports-[selector(a:not(.foo))]:flex', 'supports-[selector(a:is(.and,.or))]:flex', 'supports-[(display:grid)or(display:flex)]:grid', @@ -1437,103 +1448,86 @@ test('supports: `and`, `or`, and `not` inside function calls are not spaced out' ]), ).toMatchInlineSnapshot(` " - @supports (display: grid) or (display: flex) { - .supports-\\[\\(display\\:grid\\)or\\(display\\:flex\\)\\]\\:grid { + @supports (gap: var(--tw)) { + .supports-gap\\:grid { display: grid; } } - @supports foo-not(display:grid) { - .supports-\\[foo-not\\(display\\:grid\\)\\]\\:flex { - display: flex; + @supports (display: grid) and font-format(opentype) { + .supports-\\[\\(display\\:grid\\)_and_font-format\\(opentype\\)\\]\\:grid { + display: grid; } } - @supports not (display: grid) { - .supports-\\[not\\(display\\:grid\\)\\]\\:flex { - display: flex; + @supports (display: grid) or (display: flex) { + .supports-\\[\\(display\\:grid\\)or\\(display\\:flex\\)\\]\\:grid { + display: grid; } } - @supports selector(.foo\\(bar) or (display: grid) { - .supports-\\[selector\\(\\.foo\\\\\\(bar\\)or\\(display\\:grid\\)\\]\\:flex { + @supports (--test: var(--tw)) { + .supports-\\[--test\\]\\:flex { display: flex; } } - @supports selector([data-foo="("]) or (display: grid) { - .supports-\\[selector\\(\\[data-foo\\=\\"\\(\\"\\]\\)or\\(display\\:grid\\)\\]\\:flex { + @supports (display: grid) { + .supports-\\[display\\:grid\\]\\:flex { display: flex; } } - @supports selector(a:is(.and,.or)) { - .supports-\\[selector\\(a\\:is\\(\\.and\\,\\.or\\)\\)\\]\\:flex { - display: flex; + @supports font-format(opentype) { + .supports-\\[font-format\\(opentype\\)\\]\\:grid { + display: grid; } } - @supports selector(a:not(.foo)) { - .supports-\\[selector\\(a\\:not\\(\\.foo\\)\\)\\]\\:flex { + @supports font-tech(color-COLRv1) { + .supports-\\[font-tech\\(color-COLRv1\\)\\]\\:flex { display: flex; } } - " - `) -}) -test('supports', async () => { - expect( - await run([ - 'supports-gap:grid', - 'supports-[display:grid]:flex', - 'supports-[selector(A_>_B)]:flex', - 'supports-[font-format(opentype)]:grid', - 'supports-[(display:grid)_and_font-format(opentype)]:grid', - 'supports-[font-tech(color-COLRv1)]:flex', - 'supports-[var(--test)]:flex', - 'supports-[--test]:flex', - ]), - ).toMatchInlineSnapshot(` - " - @supports (gap: var(--tw)) { - .supports-gap\\:grid { - display: grid; + @supports foo-not(display:grid) { + .supports-\\[foo-not\\(display\\:grid\\)\\]\\:flex { + display: flex; } } - @supports (display: grid) and font-format(opentype) { - .supports-\\[\\(display\\:grid\\)_and_font-format\\(opentype\\)\\]\\:grid { - display: grid; + @supports not (display: grid) { + .supports-\\[not\\(display\\:grid\\)\\]\\:flex { + display: flex; } } - @supports (--test: var(--tw)) { - .supports-\\[--test\\]\\:flex { + @supports selector(.foo\\(bar) or (display: grid) { + .supports-\\[selector\\(\\.foo\\\\\\(bar\\)or\\(display\\:grid\\)\\]\\:flex { display: flex; } } - @supports (display: grid) { - .supports-\\[display\\:grid\\]\\:flex { + @supports selector(A > B) { + .supports-\\[selector\\(A_\\>_B\\)\\]\\:flex { display: flex; } } - @supports font-format(opentype) { - .supports-\\[font-format\\(opentype\\)\\]\\:grid { - display: grid; + @supports selector([data-foo="("]) or (display: grid) { + .supports-\\[selector\\(\\[data-foo\\=\\"\\(\\"\\]\\)or\\(display\\:grid\\)\\]\\:flex { + display: flex; } } - @supports font-tech(color-COLRv1) { - .supports-\\[font-tech\\(color-COLRv1\\)\\]\\:flex { + @supports selector(a:is(.and,.or)) { + .supports-\\[selector\\(a\\:is\\(\\.and\\,\\.or\\)\\)\\]\\:flex { display: flex; } } - @supports selector(A > B) { - .supports-\\[selector\\(A_\\>_B\\)\\]\\:flex { + @supports selector(a:not(.foo)) { + .supports-\\[selector\\(a\\:not\\(\\.foo\\)\\)\\]\\:flex { display: flex; } } From c45e111b5ea935d9733590fe598b65b35ea971d6 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Aug 2026 21:36:01 +0200 Subject: [PATCH 7/8] =?UTF-8?q?add=20test=20with=20grouped=20`(=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tailwindcss/src/variants.test.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/tailwindcss/src/variants.test.ts b/packages/tailwindcss/src/variants.test.ts index 7a6aa245d705..454f4c1bf198 100644 --- a/packages/tailwindcss/src/variants.test.ts +++ b/packages/tailwindcss/src/variants.test.ts @@ -1445,6 +1445,7 @@ test('supports', async () => { 'supports-[foo-not(display:grid)]:flex', 'supports-[selector([data-foo="("])or(display:grid)]:flex', 'supports-[selector(.foo\\(bar)or(display:grid)]:flex', + 'supports-[((display:grid)or(display:flex))]:grid', ]), ).toMatchInlineSnapshot(` " @@ -1454,6 +1455,12 @@ test('supports', async () => { } } + @supports (display: grid) or (display: flex) { + .supports-\\[\\(\\(display\\:grid\\)or\\(display\\:flex\\)\\)\\]\\:grid { + display: grid; + } + } + @supports (display: grid) and font-format(opentype) { .supports-\\[\\(display\\:grid\\)_and_font-format\\(opentype\\)\\]\\:grid { display: grid; From f58dc96f600049719624db1baa4dec958c9ed8a2 Mon Sep 17 00:00:00 2001 From: Robin Malfait Date: Fri, 14 Aug 2026 21:36:15 +0200 Subject: [PATCH 8/8] =?UTF-8?q?use=20proper=20walk=20+=20bail=20when=20we?= =?UTF-8?q?=20see=20`selector(=E2=80=A6)`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/tailwindcss/src/variants.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/tailwindcss/src/variants.ts b/packages/tailwindcss/src/variants.ts index 06380365d325..c13c3ae12e39 100644 --- a/packages/tailwindcss/src/variants.ts +++ b/packages/tailwindcss/src/variants.ts @@ -940,15 +940,18 @@ export function createVariants(theme: Theme): Variants { // `(condition1) or (condition2)` is supported. let changed = false let ast = ValueParser.parse(value) - for (let node of ast) { - if ( - node.kind === 'function' && - (node.value === 'and' || node.value === 'or' || node.value === 'not') - ) { + walk(ast, (node) => { + if (node.kind !== 'function') return + + // Leave selectors as-is, they could contain `selector(a:not(b))`, and + // in this case we don't want the space around the `not`. + if (node.value === 'selector') return WalkAction.Skip + + if (node.value === 'and' || node.value === 'or' || node.value === 'not') { changed = true node.value = ` ${node.value} ` } - } + }) let query = changed ? ValueParser.toCss(ast) : value