marko/packages/translator/test/utils/get-node-info.ts
Ryan Carniato d5ab10232d
chore: dom translator and tests (#65)
* chore: dom translator and tests

* fix: proper skipping of tests
2021-02-18 14:14:42 -08:00

30 lines
583 B
TypeScript

export function getNodePath(node: Node) {
const parts: string[] = [];
let cur: Node | null = node;
while (cur) {
const { parentNode } = cur;
if (!parentNode || (cur as any).TEST_ROOT) {
break;
}
let name = getTypeName(cur);
const index = parentNode
? (Array.from(parentNode.childNodes) as Node[]).indexOf(cur)
: -1;
if (index !== -1) {
name += `${index}`;
}
parts.unshift(name);
cur = parentNode;
}
return parts.join("/");
}
export function getTypeName(node: Node) {
return node.nodeName.toLowerCase();
}