Skip to content

Commit fb7da92

Browse files
committed
fix: csspathformating and removed dead code
1 parent e8caa1d commit fb7da92

File tree

1 file changed

+28
-40
lines changed

1 file changed

+28
-40
lines changed

src/index.js

+28-40
Original file line numberDiff line numberDiff line change
@@ -410,54 +410,42 @@
410410
do {
411411
if (!node || !node.tagName) return false;
412412
let pathSplit = node.tagName.toLowerCase();
413-
// if (node.tagName == "DOM-PARSER" || node.hasAttribute('contenteditable')){
414-
// pathSplit = "[contenteditable]";
415-
// node = '';
416-
// }
413+
417414
if (node.id) {
418415
pathSplit += "#" + node.id;
419416
node = '';
420-
}
421-
else {
422-
// let eid = node.getAttribute('eid');
423-
// if (/{{\s*([\w\W]+)\s*}}/g.test(eid)) {
424-
// eid = false;
425-
// }
426-
// if (eid) {
427-
// pathSplit += `[eid="${eid}"]`;
428-
// node = '';
429-
// }
430-
// else {
431-
// if (node.classList.length) {
432-
// node.classList.forEach((item) => {
433-
// if (item.indexOf(":") === -1) pathSplit += "." + item;
434-
// });
435-
// }
436-
437-
if (node.parentNode && node.parentNode.children.length > 1) {
438-
// TODO: improve array logic so ignores javascript generated html??
439-
let children = []
440-
for (let child of node.parentNode.children) {
441-
// if (!child.matches('.mirror'))
442-
// children.push(child);
443-
if (child.tagName == node.tagName)
444-
children.push(child);
417+
} else {
418+
let eid = node.getAttribute('eid');
419+
if (eid && !(/{{\s*([\w\W]+)\s*}}/g.test(eid))) {
420+
pathSplit += `[eid="${eid}"]`;
421+
node = '';
422+
} else
423+
// if (node.classList.length) {
424+
// node.classList.forEach((item) => {
425+
// if (item.indexOf(":") === -1) pathSplit += "." + item;
426+
// });
427+
// }
428+
429+
if (node.parentNode && node.parentNode.children.length > 1) {
430+
// TODO: improve array logic so ignores javascript generated html??
431+
let children = []
432+
for (let child of node.parentNode.children) {
433+
if (child.tagName == node.tagName)
434+
children.push(child);
435+
}
436+
let index = Array.prototype.indexOf.call(
437+
children,
438+
node
439+
);
440+
441+
pathSplit += `:nth-of-type(${index + 1})`;
445442
}
446-
let index = Array.prototype.indexOf.call(
447-
children,
448-
node
449-
);
450-
// if (children.length > 1)
451-
// pathSplit += `:nth-child(${index + 1})`;
452-
pathSplit += `:nth-of-type(${index + 1})`;
453-
}
454443

455-
// pathSplits.unshift(pathSplit);
456444
node = node.parentNode;
457-
if (node == null || node.tagName == "HTML" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
445+
if (node == null || node.tagName == "HTML" || node.tagName == "BODY" || node.tagName == "DOM-PARSER" || node.nodeName == "#document" || node.hasAttribute('contenteditable'))
458446
node = '';
459447
}
460-
// }
448+
461449
pathSplits.unshift(pathSplit);
462450
} while (node);
463451
let path = pathSplits.join(" > ")

0 commit comments

Comments
 (0)