test: simplify export html specificity count

This commit is contained in:
Peter Steinberger
2026-05-08 22:59:57 +01:00
parent 91a6372897
commit df1851b27d

View File

@@ -145,9 +145,12 @@ function selectorSpecificity(selector: string): [number, number, number] {
const ids = selector.match(/#[\w-]+/g)?.length ?? 0;
const classes = selector.match(/\.[\w-]+/g)?.length ?? 0;
const withoutIdsOrClasses = selector.replace(/#[\w-]+|\.[\w-]+/g, " ");
const elements = withoutIdsOrClasses
.split(/[\s>+~]+/)
.filter((part) => /^[a-z][\w-]*$/i.test(part)).length;
let elements = 0;
for (const part of withoutIdsOrClasses.split(/[\s>+~]+/)) {
if (/^[a-z][\w-]*$/i.test(part)) {
elements++;
}
}
return [ids, classes, elements];
}