-
-
Notifications
You must be signed in to change notification settings - Fork 75
is-pseudo : handle more complex selector patterns #923
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
is-pseudo : handle more complex selector patterns #923
Conversation
// :-csstools-matches(.a > .b) + :-csstools-matches(.c > .d) | ||
// equivalent to | ||
// .a.c > .b + .d | ||
// | ||
// and | ||
// | ||
// :-csstools-matches(.a > .b) ~ :-csstools-matches(.c > .d) | ||
// equivalent to | ||
// .a.c ~ .b + .d | ||
// |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are actually the same, trivial to support both.
const previous = sortedCompoundSelectors[i - 1]; | ||
|
||
sortedCompoundSelectors[i].remove(); | ||
node.prepend(sortedCompoundSelectors[i]); | ||
|
||
if (previous && previous.type === 'tag' && sortedCompoundSelectors[i].type === 'tag') { | ||
const wrapped = parser.pseudo({ | ||
value: ':is', | ||
nodes: [ | ||
parser.selector({ | ||
value: '', | ||
nodes: [ | ||
sortedCompoundSelectors[i], | ||
], | ||
}), | ||
], | ||
}); | ||
|
||
node.prepend(wrapped); | ||
} else { | ||
node.prepend(sortedCompoundSelectors[i]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorting will group tag selectors a
and b
into ab
which serializes as a single tag ab
.
This bit is a "post fix" to wrap it back with :is()
into a:is(b)
@@ -1,7 +1,7 @@ | |||
import parser from 'postcss-selector-parser'; | |||
|
|||
export function sortCompoundSelectorsInsideComplexSelector(node) { | |||
if (!node || !node.nodes) { | |||
if (!node || !node.nodes || node.nodes.length === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:is(a)
cause issues and doesn't require sorting anyway.
Better to short circuit.
background-color: #ffc; | ||
} | ||
|
||
:is(:-csstools-matches(.a, .b)) > .c { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I want to be sure that code looking for :-csstools-matches
can also handle selector lists.
Internally we never produce :-csstools-matches
with lists, but want to cover it anyway.
(We produce :-csstools-matches
as an intermediate step with partially transpiled selectors to prevent infinite loops.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks al lot for the comments on specific areas of interest! Love it
fixes : #922