Loosen :is() wrapping rules in applyImportantSelector for more readable output. (#13900)

This commit is contained in:
Josh Wilson 2024-07-16 10:51:45 -04:00 • committed by GitHub
parent 9c29e47c5f
commit 0573c0769a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 18 deletions

View file

@ -5,13 +5,12 @@ export function applyImportantSelector(selector, important) {
let sel = parser().astSync(selector)
sel.each((sel) => {
// Wrap with :is if it's not already wrapped
let isWrapped =
sel.nodes[0].type === 'pseudo' &&
sel.nodes[0].value === ':is' &&
sel.nodes.every((node) => node.type !== 'combinator')
// For nesting, we only need to wrap a selector with :is() if it has a top-level combinator,
// e.g. `.dark .text-white`, to be independent of DOM order. Any other selector, including
// combinators inside of pseudos like `:where()`, are ok to nest.
let shouldWrap = sel.nodes.some((node) => node.type === 'combinator')
if (!isWrapped) {
if (shouldWrap) {
sel.nodes = [
parser.pseudo({
value: ':is',