switch it up

pull/10491/head
Rich Harris 3 years ago
parent aaf9fd22ca
commit c3c1112369

@ -205,19 +205,16 @@ function relative_selector_might_apply_to_node(relative_selector, node, styleshe
const name = selector.name.replace(regex_backslash_and_following_character, '$1');
if (selector.type === 'PseudoClassSelector' && (name === 'host' || name === 'root')) {
switch (selector.type) {
case 'PseudoClassSelector':
if (name === 'host' || name === 'root') {
return NO_MATCH;
}
if (
relative_selector.selectors.length === 1 &&
selector.type === 'PseudoClassSelector' &&
name === 'global'
) {
if (name === 'global' && relative_selector.selectors.length === 1) {
return NO_MATCH;
}
if (selector.type === 'PseudoClassSelector') {
if ((name === 'is' || name === 'where') && selector.args) {
let matched = false;
@ -233,14 +230,12 @@ function relative_selector_might_apply_to_node(relative_selector, node, styleshe
}
}
continue;
}
break;
if (selector.type === 'PseudoElementSelector') {
continue;
}
case 'PseudoElementSelector':
break;
if (selector.type === 'AttributeSelector') {
case 'AttributeSelector':
const whitelisted = whitelist_attribute_selector.get(node.name.toLowerCase());
if (
!whitelisted?.includes(selector.name.toLowerCase()) &&
@ -254,8 +249,9 @@ function relative_selector_might_apply_to_node(relative_selector, node, styleshe
) {
return NO_MATCH;
}
} else {
if (selector.type === 'ClassSelector') {
break;
case 'ClassSelector':
if (
!attribute_matches(node, 'class', name, '~=', false) &&
!node.attributes.some(
@ -264,9 +260,17 @@ function relative_selector_might_apply_to_node(relative_selector, node, styleshe
) {
return NO_MATCH;
}
} else if (selector.type === 'IdSelector') {
if (!attribute_matches(node, 'id', name, '=', false)) return NO_MATCH;
} else if (selector.type === 'TypeSelector') {
break;
case 'IdSelector':
if (!attribute_matches(node, 'id', name, '=', false)) {
return NO_MATCH;
}
break;
case 'TypeSelector':
if (
node.name.toLowerCase() !== name.toLowerCase() &&
name !== '*' &&
@ -274,11 +278,13 @@ function relative_selector_might_apply_to_node(relative_selector, node, styleshe
) {
return NO_MATCH;
}
} else {
break;
default:
return UNKNOWN_SELECTOR;
}
}
}
return POSSIBLE_MATCH;
}

Loading…
Cancel
Save