Skip to content

Commit 0f9c89e

Browse files
Ignoring :has() within @supports check
#312
1 parent 78a89da commit 0f9c89e

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

experimental/css-has-pseudo/src/index.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
1616
return {
1717
postcssPlugin: 'css-has-pseudo-experimental',
1818
RuleExit: (rule, { result }) => {
19-
if (!rule.selector.includes(':has(')) {
19+
if (!rule.selector.includes(':has(') || isWithinSupportCheck(rule)) {
2020
return;
2121
}
2222

@@ -102,6 +102,22 @@ creator.postcss = true;
102102

103103
export default creator;
104104

105+
function isWithinSupportCheck(rule) {
106+
let isSupportCheck = false;
107+
let ruleParent = rule.parent;
108+
109+
while (!isSupportCheck && ruleParent) {
110+
if (ruleParent.type === 'atrule') {
111+
112+
isSupportCheck = ruleParent.params.includes(':has(') && ruleParent.params.startsWith('selector(');
113+
}
114+
115+
ruleParent = ruleParent.parent;
116+
}
117+
118+
return isSupportCheck;
119+
}
120+
105121
function selectorSpecificity(node) {
106122
let a = 0;
107123
let b = 0;

0 commit comments

Comments
 (0)