@asamuzakjp/dom-selector 0.15.12 → 0.15.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +4 -4
- package/src/js/matcher.js +20 -8
package/package.json
CHANGED
|
@@ -24,11 +24,11 @@
|
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
26
|
"@types/css-tree": "^2.3.1",
|
|
27
|
-
"c8": "^7.
|
|
27
|
+
"c8": "^7.14.0",
|
|
28
28
|
"chai": "^4.3.7",
|
|
29
29
|
"eslint": "^8.41.0",
|
|
30
|
-
"eslint-config-standard": "^17.
|
|
31
|
-
"eslint-plugin-jsdoc": "^
|
|
30
|
+
"eslint-config-standard": "^17.1.0",
|
|
31
|
+
"eslint-plugin-jsdoc": "^46.0.0",
|
|
32
32
|
"eslint-plugin-regexp": "^1.15.0",
|
|
33
33
|
"eslint-plugin-unicorn": "^47.0.0",
|
|
34
34
|
"jsdom": "^22.1.0",
|
|
@@ -42,5 +42,5 @@
|
|
|
42
42
|
"test": "c8 --reporter=text mocha --exit test/**/*.test.js",
|
|
43
43
|
"tsc": "npx tsc"
|
|
44
44
|
},
|
|
45
|
-
"version": "0.15.
|
|
45
|
+
"version": "0.15.13"
|
|
46
46
|
}
|
package/src/js/matcher.js
CHANGED
|
@@ -1735,32 +1735,44 @@ class Matcher {
|
|
|
1735
1735
|
* @returns {Array.<object|undefined>} - collection of matched nodes
|
|
1736
1736
|
*/
|
|
1737
1737
|
_getMatchedNodes(branch = [], node = {}) {
|
|
1738
|
-
const matched = [];
|
|
1739
1738
|
const twig = groupASTLeaves(branch);
|
|
1740
1739
|
const l = twig.length;
|
|
1740
|
+
const matched = [];
|
|
1741
1741
|
if (l) {
|
|
1742
|
+
const lastIndex = l - 1;
|
|
1742
1743
|
const iterator =
|
|
1743
1744
|
this.#document.createNodeIterator(node, FILTER_SHOW_ELEMENT);
|
|
1744
1745
|
let nextNode = iterator.nextNode();
|
|
1745
1746
|
while (nextNode) {
|
|
1746
1747
|
let i = 0;
|
|
1747
|
-
|
|
1748
|
-
const { leaves } = twig[
|
|
1748
|
+
if (nextNode.children.length === 0) {
|
|
1749
|
+
const { leaves } = twig[lastIndex];
|
|
1749
1750
|
const bool = leaves.every(leaf => {
|
|
1750
1751
|
const arr = this._match(leaf, nextNode);
|
|
1751
1752
|
return arr.includes(nextNode);
|
|
1752
1753
|
});
|
|
1753
1754
|
if (bool) {
|
|
1754
|
-
twig[
|
|
1755
|
+
twig[lastIndex].nodes.add(nextNode);
|
|
1756
|
+
}
|
|
1757
|
+
} else {
|
|
1758
|
+
while (i < l) {
|
|
1759
|
+
const { leaves } = twig[i];
|
|
1760
|
+
const bool = leaves.every(leaf => {
|
|
1761
|
+
const arr = this._match(leaf, nextNode);
|
|
1762
|
+
return arr.includes(nextNode);
|
|
1763
|
+
});
|
|
1764
|
+
if (bool) {
|
|
1765
|
+
twig[i].nodes.add(nextNode);
|
|
1766
|
+
}
|
|
1767
|
+
i++;
|
|
1755
1768
|
}
|
|
1756
|
-
i++;
|
|
1757
1769
|
}
|
|
1758
1770
|
nextNode = iterator.nextNode();
|
|
1759
1771
|
}
|
|
1760
|
-
if (
|
|
1772
|
+
if (lastIndex === 0) {
|
|
1761
1773
|
const [{ nodes }] = twig;
|
|
1762
1774
|
matched.push(...nodes);
|
|
1763
|
-
} else if (
|
|
1775
|
+
} else if (lastIndex) {
|
|
1764
1776
|
const prevItem = twig[0];
|
|
1765
1777
|
let j = 1;
|
|
1766
1778
|
while (j < l) {
|
|
@@ -1770,7 +1782,7 @@ class Matcher {
|
|
|
1770
1782
|
const nodes =
|
|
1771
1783
|
matchCombinator(prevCombo, [...prevNodes], [...nextNodes]);
|
|
1772
1784
|
if (nodes.length) {
|
|
1773
|
-
if (j ===
|
|
1785
|
+
if (j === lastIndex) {
|
|
1774
1786
|
matched.push(...new Set(nodes));
|
|
1775
1787
|
break;
|
|
1776
1788
|
} else {
|