fix some specificity stuff

pull/10491/head
Rich Harris 3 years ago
parent e624b713a8
commit c35f5d70ce

@ -73,6 +73,12 @@ const analysis_visitors = {
...context.state, ...context.state,
rule: node rule: node
}); });
node.metadata.has_local_selectors = node.prelude.children.some((selector) => {
return selector.children.some(
({ metadata }) => !metadata.is_global && !metadata.is_host && !metadata.is_root
);
});
} }
}; };

@ -172,10 +172,20 @@ const visitors = {
// if this selector list belongs to a rule, require a specificity bump for the // if this selector list belongs to a rule, require a specificity bump for the
// first scoped selector but only if we're at the top level // first scoped selector but only if we're at the top level
// TODO this isn't quite right, it would break with `:global(x) {...}` let parent = path.at(-1);
const parent = path.at(-1);
if (parent?.type === 'Rule') { if (parent?.type === 'Rule') {
specificity = { bumped: !!parent.metadata.parent_rule }; specificity = { bumped: false };
/** @type {import('#compiler').Css.Rule | null} */
let rule = parent.metadata.parent_rule;
while (rule) {
if (rule.metadata.has_local_selectors) {
specificity = { bumped: true };
break;
}
rule = rule.metadata.parent_rule;
}
} }
next({ ...state, specificity }); next({ ...state, specificity });

@ -27,6 +27,7 @@ export interface Rule extends BaseNode {
block: Block; block: Block;
metadata: { metadata: {
parent_rule: null | Rule; parent_rule: null | Rule;
has_local_selectors: boolean;
}; };
} }

Loading…
Cancel
Save