-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
…10903) * Pull pseudo elements outside of `:is` and `:has` when using `@apply` * Update changelog * Refactor * Update important selector handling for :is and :has * fixup * fixup * trigger CI --------- Co-authored-by: Robin Malfait <[email protected]>
- Loading branch information
1 parent
a785c93
commit 0ecc464
Showing
6 changed files
with
149 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,31 @@ | ||
import { splitAtTopLevelOnly } from './splitAtTopLevelOnly' | ||
import parser from 'postcss-selector-parser' | ||
import { collectPseudoElements, sortSelector } from './formatVariantSelector.js' | ||
|
||
export function applyImportantSelector(selector, important) { | ||
let matches = /^(.*?)(:before|:after|::[\w-]+)(\)*)$/g.exec(selector) | ||
if (!matches) return `${important} ${wrapWithIs(selector)}` | ||
let sel = parser().astSync(selector) | ||
|
||
let [, before, pseudo, brackets] = matches | ||
return `${important} ${wrapWithIs(before + brackets)}${pseudo}` | ||
} | ||
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') | ||
|
||
function wrapWithIs(selector) { | ||
let parts = splitAtTopLevelOnly(selector, ' ') | ||
if (!isWrapped) { | ||
sel.nodes = [ | ||
parser.pseudo({ | ||
value: ':is', | ||
nodes: [sel.clone()], | ||
}), | ||
] | ||
} | ||
|
||
if (parts.length === 1 && parts[0].startsWith(':is(') && parts[0].endsWith(')')) { | ||
return selector | ||
} | ||
let [pseudoElements] = collectPseudoElements(sel) | ||
if (pseudoElements.length > 0) { | ||
sel.nodes.push(...pseudoElements.sort(sortSelector)) | ||
} | ||
}) | ||
|
||
return `:is(${selector})` | ||
return `${important} ${sel.toString()}` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters