buildFallbackCSS function presentation ✓ 100.0%
Last updated: 2026-03-05T12:26:14.062Z
Metrics
LOC: 35
Complexity: 7
Params: 1
Coverage: 100.0% (13/13 lines, 0x executed)
Signature
buildFallbackCSS(el: Element): : SmartSelector
Source Code
function buildFallbackCSS(el: Element): SmartSelector {
if (el.id) return { value: `#${escapeCSS(el.id)}`, strategy: "css" };
const parts: string[] = [];
let current: Element | null = el;
while (current && current !== document.body) {
let selector = current.tagName.toLowerCase();
if (current.id) {
parts.unshift(`#${escapeCSS(current.id)}`);
break;
}
const parent: Element | null = current.parentElement;
if (parent) {
const siblings = Array.from(parent.children).filter(
(c: Element) => c.tagName === current!.tagName,
);
if (siblings.length > 1) {
const index = siblings.indexOf(current) + 1;
selector += `:nth-of-type(${index})`;
}
}
parts.unshift(selector);
current = parent;
}
return {
value: parts.join(" > "),
strategy: "selector-path",
description: "DOM selector path",
};
}
Dependencies (Outgoing)
| Target | Type |
|---|---|
| escapeCSS | calls |
Impact (Incoming)
| Source | Type |
|---|---|
| buildCSSPath | calls |
| extractSmartSelectors | calls |