happy-dom 17.1.3 → 17.1.4

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.
@@ -31,8 +31,21 @@ const PropertySymbol = __importStar(require("../PropertySymbol.cjs"));
31
31
  const NodeFilterMask_js_1 = __importDefault(require("./NodeFilterMask.cjs"));
32
32
  const DOMException_js_1 = __importDefault(require("../exception/DOMException.cjs"));
33
33
  const NodeFilter_js_1 = __importDefault(require("./NodeFilter.cjs"));
34
+ var TraverseChildrenTypeEnum;
35
+ (function (TraverseChildrenTypeEnum) {
36
+ TraverseChildrenTypeEnum["first"] = "first";
37
+ TraverseChildrenTypeEnum["last"] = "last";
38
+ })(TraverseChildrenTypeEnum || (TraverseChildrenTypeEnum = {}));
39
+ var TraverseSiblingsTypeEnum;
40
+ (function (TraverseSiblingsTypeEnum) {
41
+ TraverseSiblingsTypeEnum["next"] = "next";
42
+ TraverseSiblingsTypeEnum["previous"] = "previous";
43
+ })(TraverseSiblingsTypeEnum || (TraverseSiblingsTypeEnum = {}));
34
44
  /**
35
45
  * The TreeWalker object represents the nodes of a document subtree and a position within them.
46
+ *
47
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
48
+ * @see https://dom.spec.whatwg.org/#interface-treewalker
36
49
  */
37
50
  class TreeWalker {
38
51
  root = null;
@@ -55,44 +68,20 @@ class TreeWalker {
55
68
  this.filter = filter;
56
69
  this.currentNode = root;
57
70
  }
58
- /**
59
- * Moves the current Node to the next visible node in the document order.
60
- *
61
- * @returns Current node.
62
- */
63
- nextNode() {
64
- if (!this.firstChild()) {
65
- while (!this.nextSibling() && this.parentNode()) { }
66
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
67
- }
68
- return this.currentNode;
69
- }
70
- /**
71
- * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
72
- *
73
- * @returns Current node.
74
- */
75
- previousNode() {
76
- while (!this.previousSibling() && this.parentNode()) { }
77
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
78
- return this.currentNode;
79
- }
80
71
  /**
81
72
  * Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
82
73
  *
83
74
  * @returns Current node.
84
75
  */
85
76
  parentNode() {
86
- if (this.currentNode !== this.root &&
87
- this.currentNode &&
88
- this.currentNode[PropertySymbol.parentNode]) {
89
- this.currentNode = this.currentNode[PropertySymbol.parentNode];
90
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter_js_1.default.FILTER_ACCEPT) {
77
+ let node = this.currentNode;
78
+ while (node !== null && node !== this.root) {
79
+ node = node.parentNode;
80
+ if (node !== null && this[PropertySymbol.filterNode](node) === NodeFilter_js_1.default.FILTER_ACCEPT) {
81
+ this.currentNode = node;
91
82
  return this.currentNode;
92
83
  }
93
- this.parentNode();
94
84
  }
95
- this.currentNode = null;
96
85
  return null;
97
86
  }
98
87
  /**
@@ -101,15 +90,7 @@ class TreeWalker {
101
90
  * @returns Current node.
102
91
  */
103
92
  firstChild() {
104
- const childNodes = this.currentNode ? this.currentNode[PropertySymbol.nodeArray] : [];
105
- if (childNodes.length > 0) {
106
- this.currentNode = childNodes[0];
107
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter_js_1.default.FILTER_ACCEPT) {
108
- return this.currentNode;
109
- }
110
- return this.nextSibling();
111
- }
112
- return null;
93
+ return this.#traverseChildren(TraverseChildrenTypeEnum.first);
113
94
  }
114
95
  /**
115
96
  * Moves the current Node to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, null is returned and the current node is not changed.
@@ -117,15 +98,15 @@ class TreeWalker {
117
98
  * @returns Current node.
118
99
  */
119
100
  lastChild() {
120
- const childNodes = this.currentNode ? this.currentNode[PropertySymbol.nodeArray] : [];
121
- if (childNodes.length > 0) {
122
- this.currentNode = childNodes[childNodes.length - 1];
123
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter_js_1.default.FILTER_ACCEPT) {
124
- return this.currentNode;
125
- }
126
- return this.previousSibling();
127
- }
128
- return null;
101
+ return this.#traverseChildren(TraverseChildrenTypeEnum.last);
102
+ }
103
+ /**
104
+ * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
105
+ *
106
+ * @returns Current node.
107
+ */
108
+ nextSibling() {
109
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.next);
129
110
  }
130
111
  /**
131
112
  * Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
@@ -133,41 +114,78 @@ class TreeWalker {
133
114
  * @returns Current node.
134
115
  */
135
116
  previousSibling() {
136
- if (this.currentNode !== this.root &&
137
- this.currentNode &&
138
- this.currentNode[PropertySymbol.parentNode]) {
139
- const siblings = this.currentNode[PropertySymbol.parentNode][PropertySymbol.nodeArray];
140
- const index = siblings.indexOf(this.currentNode);
141
- if (index > 0) {
142
- this.currentNode = siblings[index - 1];
143
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter_js_1.default.FILTER_ACCEPT) {
144
- return this.currentNode;
117
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.previous);
118
+ }
119
+ /**
120
+ * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
121
+ *
122
+ * @returns Current node.
123
+ */
124
+ previousNode() {
125
+ let node = this.currentNode;
126
+ while (node !== this.root) {
127
+ let sibling = node.previousSibling;
128
+ while (sibling !== null) {
129
+ let node = sibling;
130
+ let result = this[PropertySymbol.filterNode](node);
131
+ while (result !== NodeFilter_js_1.default.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
132
+ node = node.lastChild;
133
+ result = this[PropertySymbol.filterNode](node);
145
134
  }
146
- return this.previousSibling();
135
+ if (result === NodeFilter_js_1.default.FILTER_ACCEPT) {
136
+ this.currentNode = node;
137
+ return node;
138
+ }
139
+ sibling = node.previousSibling;
140
+ }
141
+ if (node === this.root || node.parentNode === null) {
142
+ return null;
143
+ }
144
+ node = node.parentNode;
145
+ if (this[PropertySymbol.filterNode](node) === NodeFilter_js_1.default.FILTER_ACCEPT) {
146
+ this.currentNode = node;
147
+ return node;
147
148
  }
148
149
  }
149
150
  return null;
150
151
  }
151
152
  /**
152
- * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
153
+ * Moves the current Node to the next visible node in the document order.
153
154
  *
154
155
  * @returns Current node.
155
156
  */
156
- nextSibling() {
157
- if (this.currentNode !== this.root &&
158
- this.currentNode &&
159
- this.currentNode[PropertySymbol.parentNode]) {
160
- const siblings = this.currentNode[PropertySymbol.parentNode][PropertySymbol.nodeArray];
161
- const index = siblings.indexOf(this.currentNode);
162
- if (index + 1 < siblings.length) {
163
- this.currentNode = siblings[index + 1];
164
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter_js_1.default.FILTER_ACCEPT) {
165
- return this.currentNode;
157
+ nextNode() {
158
+ let node = this.currentNode;
159
+ let result = NodeFilter_js_1.default.FILTER_ACCEPT;
160
+ while (true) {
161
+ while (result !== NodeFilter_js_1.default.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
162
+ node = node.firstChild;
163
+ result = this[PropertySymbol.filterNode](node);
164
+ if (result === NodeFilter_js_1.default.FILTER_ACCEPT) {
165
+ this.currentNode = node;
166
+ return node;
167
+ }
168
+ }
169
+ while (node !== null) {
170
+ if (node === this.root) {
171
+ return null;
166
172
  }
167
- return this.nextSibling();
173
+ const sibling = node.nextSibling;
174
+ if (sibling !== null) {
175
+ node = sibling;
176
+ break;
177
+ }
178
+ node = node.parentNode;
179
+ }
180
+ if (node === null) {
181
+ return null;
182
+ }
183
+ result = this[PropertySymbol.filterNode](node);
184
+ if (result === NodeFilter_js_1.default.FILTER_ACCEPT) {
185
+ this.currentNode = node;
186
+ return node;
168
187
  }
169
188
  }
170
- return null;
171
189
  }
172
190
  /**
173
191
  * Filters a node.
@@ -191,6 +209,78 @@ class TreeWalker {
191
209
  }
192
210
  return NodeFilter_js_1.default.FILTER_ACCEPT;
193
211
  }
212
+ /**
213
+ * Traverses children.
214
+ *
215
+ * @param type Type.
216
+ * @returns Node.
217
+ */
218
+ #traverseChildren(type) {
219
+ let node = this.currentNode;
220
+ node = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
221
+ while (node !== null) {
222
+ const result = this[PropertySymbol.filterNode](node);
223
+ if (result === NodeFilter_js_1.default.FILTER_ACCEPT) {
224
+ this.currentNode = node;
225
+ return node;
226
+ }
227
+ if (result === NodeFilter_js_1.default.FILTER_SKIP) {
228
+ const child = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
229
+ if (child !== null) {
230
+ node = child;
231
+ continue;
232
+ }
233
+ }
234
+ while (node !== null) {
235
+ const sibling = type === TraverseChildrenTypeEnum.first ? node.nextSibling : node.previousSibling;
236
+ if (sibling !== null) {
237
+ node = sibling;
238
+ break;
239
+ }
240
+ const parent = node.parentNode;
241
+ if (parent === null || parent === this.root || parent === this.currentNode) {
242
+ return null;
243
+ }
244
+ node = parent;
245
+ }
246
+ }
247
+ return null;
248
+ }
249
+ /**
250
+ * Traverses siblings.
251
+ *
252
+ * @param type Type.
253
+ * @returns Node.
254
+ */
255
+ #traverseSiblings(type) {
256
+ let node = this.currentNode;
257
+ if (node === this.root) {
258
+ return null;
259
+ }
260
+ while (true) {
261
+ let sibling = type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
262
+ while (sibling !== null) {
263
+ const node = sibling;
264
+ const result = this[PropertySymbol.filterNode](node);
265
+ if (result === NodeFilter_js_1.default.FILTER_ACCEPT) {
266
+ this.currentNode = node;
267
+ return node;
268
+ }
269
+ sibling = type === TraverseSiblingsTypeEnum.next ? node.firstChild : node.lastChild;
270
+ if (result === NodeFilter_js_1.default.FILTER_REJECT || sibling === null) {
271
+ sibling =
272
+ type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
273
+ }
274
+ }
275
+ node = node.parentNode;
276
+ if (node === null || node === this.root) {
277
+ return null;
278
+ }
279
+ if (this[PropertySymbol.filterNode](node) === NodeFilter_js_1.default.FILTER_ACCEPT) {
280
+ return null;
281
+ }
282
+ }
283
+ }
194
284
  }
195
285
  exports.default = TreeWalker;
196
286
  //# sourceMappingURL=TreeWalker.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeWalker.cjs","sourceRoot":"","sources":["../../src/tree-walker/TreeWalker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAyC;AACzC,qEAAuD;AAEvD,4EAAiD;AACjD,mFAAwD;AACxD,oEAAyC;AAEzC;;GAEG;AACH,MAAqB,UAAU;IACvB,IAAI,GAAS,IAAI,CAAC;IAClB,UAAU,GAAG,CAAC,CAAC,CAAC;IAChB,MAAM,GAAgB,IAAI,CAAC;IAC3B,WAAW,GAAS,IAAI,CAAC;IAEhC;;;;;;OAMG;IACH,YAAY,IAAU,EAAE,UAAU,GAAG,CAAC,CAAC,EAAE,SAAsB,IAAI;QAClE,IAAI,CAAC,CAAC,IAAI,YAAY,iBAAI,CAAC,EAAE,CAAC;YAC7B,MAAM,IAAI,yBAAY,CAAC,mCAAmC,CAAC,CAAC;QAC7D,CAAC;QAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC;IACzB,CAAC;IAED;;;;OAIG;IACI,QAAQ;QACd,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,EAAE,CAA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I,CAAC;gBACb,CAAC;gBAED,OAAO,GAAG,IAAI,KAAK,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC;gBAEpF,IAAI,MAAM,KAAK,uBAAU,CAAC,aAAa,IAAI,OAAO,KAAK,IAAI,EAAE,CAAC;oBAC7D,OAAO;wBACN,IAAI,KAAK,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC;gBACnF,CAAC;YACF,CAAC;YAED,IAAI,GAAG,IAAI,CAAC,UAAU,CAAC;YAEvB,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;gBACzC,OAAO,IAAI,CAAC;YACb,CAAC;YAED,IAAI,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,uBAAU,CAAC,aAAa,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;CACD;AA3RD,6BA2RC"}
@@ -3,8 +3,12 @@ import * as PropertySymbol from '../PropertySymbol.cjs';
3
3
  import INodeFilter from './INodeFilter.cjs';
4
4
  /**
5
5
  * The TreeWalker object represents the nodes of a document subtree and a position within them.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
8
+ * @see https://dom.spec.whatwg.org/#interface-treewalker
6
9
  */
7
10
  export default class TreeWalker {
11
+ #private;
8
12
  root: Node;
9
13
  whatToShow: number;
10
14
  filter: INodeFilter;
@@ -17,18 +21,6 @@ export default class TreeWalker {
17
21
  * @param [filter] Filter.
18
22
  */
19
23
  constructor(root: Node, whatToShow?: number, filter?: INodeFilter);
20
- /**
21
- * Moves the current Node to the next visible node in the document order.
22
- *
23
- * @returns Current node.
24
- */
25
- nextNode(): Node;
26
- /**
27
- * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
28
- *
29
- * @returns Current node.
30
- */
31
- previousNode(): Node;
32
24
  /**
33
25
  * Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
34
26
  *
@@ -47,6 +39,12 @@ export default class TreeWalker {
47
39
  * @returns Current node.
48
40
  */
49
41
  lastChild(): Node;
42
+ /**
43
+ * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
44
+ *
45
+ * @returns Current node.
46
+ */
47
+ nextSibling(): Node;
50
48
  /**
51
49
  * Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
52
50
  *
@@ -54,11 +52,17 @@ export default class TreeWalker {
54
52
  */
55
53
  previousSibling(): Node;
56
54
  /**
57
- * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
55
+ * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
58
56
  *
59
57
  * @returns Current node.
60
58
  */
61
- nextSibling(): Node;
59
+ previousNode(): Node;
60
+ /**
61
+ * Moves the current Node to the next visible node in the document order.
62
+ *
63
+ * @returns Current node.
64
+ */
65
+ nextNode(): Node | null;
62
66
  /**
63
67
  * Filters a node.
64
68
  *
@@ -1 +1 @@
1
- {"version":3,"file":"TreeWalker.d.ts","sourceRoot":"","sources":["../../src/tree-walker/TreeWalker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAK3C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IACvB,IAAI,EAAE,IAAI,CAAQ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IACI,YAAY,IAAI,IAAI;IAsC3B;;;;OAIG;IACI,QAAQ,IAAI,IAAI,GAAG,IAAI;IA2C9B;;;;;;;;OAQG;IACI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CA0GtD"}
@@ -3,8 +3,12 @@ import * as PropertySymbol from '../PropertySymbol.js';
3
3
  import INodeFilter from './INodeFilter.js';
4
4
  /**
5
5
  * The TreeWalker object represents the nodes of a document subtree and a position within them.
6
+ *
7
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
8
+ * @see https://dom.spec.whatwg.org/#interface-treewalker
6
9
  */
7
10
  export default class TreeWalker {
11
+ #private;
8
12
  root: Node;
9
13
  whatToShow: number;
10
14
  filter: INodeFilter;
@@ -17,18 +21,6 @@ export default class TreeWalker {
17
21
  * @param [filter] Filter.
18
22
  */
19
23
  constructor(root: Node, whatToShow?: number, filter?: INodeFilter);
20
- /**
21
- * Moves the current Node to the next visible node in the document order.
22
- *
23
- * @returns Current node.
24
- */
25
- nextNode(): Node;
26
- /**
27
- * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
28
- *
29
- * @returns Current node.
30
- */
31
- previousNode(): Node;
32
24
  /**
33
25
  * Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
34
26
  *
@@ -47,6 +39,12 @@ export default class TreeWalker {
47
39
  * @returns Current node.
48
40
  */
49
41
  lastChild(): Node;
42
+ /**
43
+ * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
44
+ *
45
+ * @returns Current node.
46
+ */
47
+ nextSibling(): Node;
50
48
  /**
51
49
  * Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
52
50
  *
@@ -54,11 +52,17 @@ export default class TreeWalker {
54
52
  */
55
53
  previousSibling(): Node;
56
54
  /**
57
- * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
55
+ * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
58
56
  *
59
57
  * @returns Current node.
60
58
  */
61
- nextSibling(): Node;
59
+ previousNode(): Node;
60
+ /**
61
+ * Moves the current Node to the next visible node in the document order.
62
+ *
63
+ * @returns Current node.
64
+ */
65
+ nextNode(): Node | null;
62
66
  /**
63
67
  * Filters a node.
64
68
  *
@@ -1 +1 @@
1
- {"version":3,"file":"TreeWalker.d.ts","sourceRoot":"","sources":["../../src/tree-walker/TreeWalker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAK3C;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IACvB,IAAI,EAAE,IAAI,CAAQ;IAClB,UAAU,SAAM;IAChB,MAAM,EAAE,WAAW,CAAQ;IAC3B,WAAW,EAAE,IAAI,CAAQ;IAEhC;;;;;;OAMG;gBACS,IAAI,EAAE,IAAI,EAAE,UAAU,SAAK,EAAE,MAAM,GAAE,WAAkB;IAWnE;;;;OAIG;IACI,QAAQ,IAAI,IAAI;IAQvB;;;;OAIG;IACI,YAAY,IAAI,IAAI;IAM3B;;;;OAIG;IACI,UAAU,IAAI,IAAI;IAoBzB;;;;OAIG;IACI,UAAU,IAAI,IAAI;IAgBzB;;;;OAIG;IACI,SAAS,IAAI,IAAI;IAgBxB;;;;OAIG;IACI,eAAe,IAAI,IAAI;IAyB9B;;;;OAIG;IACI,WAAW,IAAI,IAAI;IAyB1B;;;;;;;;OAQG;IACI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CAetD"}
1
+ {"version":3,"file":"TreeWalker.d.ts","sourceRoot":"","sources":["../../src/tree-walker/TreeWalker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AACvD,OAAO,WAAW,MAAM,kBAAkB,CAAC;AAe3C;;;;;GAKG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;;IACvB,IAAI,EAAE,IAAI,CAAQ;IAClB,UAAU,SAAM;IAChB,MAAM,EAAE,WAAW,CAAQ;IAC3B,WAAW,EAAE,IAAI,CAAQ;IAEhC;;;;;;OAMG;gBACS,IAAI,EAAE,IAAI,EAAE,UAAU,SAAK,EAAE,MAAM,GAAE,WAAkB;IAWnE;;;;OAIG;IACI,UAAU,IAAI,IAAI;IAYzB;;;;OAIG;IACI,UAAU,IAAI,IAAI;IAIzB;;;;OAIG;IACI,SAAS,IAAI,IAAI;IAIxB;;;;OAIG;IACI,WAAW,IAAI,IAAI;IAI1B;;;;OAIG;IACI,eAAe,IAAI,IAAI;IAI9B;;;;OAIG;IACI,YAAY,IAAI,IAAI;IAsC3B;;;;OAIG;IACI,QAAQ,IAAI,IAAI,GAAG,IAAI;IA2C9B;;;;;;;;OAQG;IACI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,EAAE,IAAI,GAAG,MAAM;CA0GtD"}
@@ -3,8 +3,21 @@ import * as PropertySymbol from '../PropertySymbol.js';
3
3
  import NodeFilterMask from './NodeFilterMask.js';
4
4
  import DOMException from '../exception/DOMException.js';
5
5
  import NodeFilter from './NodeFilter.js';
6
+ var TraverseChildrenTypeEnum;
7
+ (function (TraverseChildrenTypeEnum) {
8
+ TraverseChildrenTypeEnum["first"] = "first";
9
+ TraverseChildrenTypeEnum["last"] = "last";
10
+ })(TraverseChildrenTypeEnum || (TraverseChildrenTypeEnum = {}));
11
+ var TraverseSiblingsTypeEnum;
12
+ (function (TraverseSiblingsTypeEnum) {
13
+ TraverseSiblingsTypeEnum["next"] = "next";
14
+ TraverseSiblingsTypeEnum["previous"] = "previous";
15
+ })(TraverseSiblingsTypeEnum || (TraverseSiblingsTypeEnum = {}));
6
16
  /**
7
17
  * The TreeWalker object represents the nodes of a document subtree and a position within them.
18
+ *
19
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
20
+ * @see https://dom.spec.whatwg.org/#interface-treewalker
8
21
  */
9
22
  export default class TreeWalker {
10
23
  root = null;
@@ -27,44 +40,20 @@ export default class TreeWalker {
27
40
  this.filter = filter;
28
41
  this.currentNode = root;
29
42
  }
30
- /**
31
- * Moves the current Node to the next visible node in the document order.
32
- *
33
- * @returns Current node.
34
- */
35
- nextNode() {
36
- if (!this.firstChild()) {
37
- while (!this.nextSibling() && this.parentNode()) { }
38
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
39
- }
40
- return this.currentNode;
41
- }
42
- /**
43
- * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
44
- *
45
- * @returns Current node.
46
- */
47
- previousNode() {
48
- while (!this.previousSibling() && this.parentNode()) { }
49
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
50
- return this.currentNode;
51
- }
52
43
  /**
53
44
  * Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
54
45
  *
55
46
  * @returns Current node.
56
47
  */
57
48
  parentNode() {
58
- if (this.currentNode !== this.root &&
59
- this.currentNode &&
60
- this.currentNode[PropertySymbol.parentNode]) {
61
- this.currentNode = this.currentNode[PropertySymbol.parentNode];
62
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
49
+ let node = this.currentNode;
50
+ while (node !== null && node !== this.root) {
51
+ node = node.parentNode;
52
+ if (node !== null && this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
53
+ this.currentNode = node;
63
54
  return this.currentNode;
64
55
  }
65
- this.parentNode();
66
56
  }
67
- this.currentNode = null;
68
57
  return null;
69
58
  }
70
59
  /**
@@ -73,15 +62,7 @@ export default class TreeWalker {
73
62
  * @returns Current node.
74
63
  */
75
64
  firstChild() {
76
- const childNodes = this.currentNode ? this.currentNode[PropertySymbol.nodeArray] : [];
77
- if (childNodes.length > 0) {
78
- this.currentNode = childNodes[0];
79
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
80
- return this.currentNode;
81
- }
82
- return this.nextSibling();
83
- }
84
- return null;
65
+ return this.#traverseChildren(TraverseChildrenTypeEnum.first);
85
66
  }
86
67
  /**
87
68
  * Moves the current Node to the last visible child of the current node, and returns the found child. It also moves the current node to this child. If no such child exists, null is returned and the current node is not changed.
@@ -89,15 +70,15 @@ export default class TreeWalker {
89
70
  * @returns Current node.
90
71
  */
91
72
  lastChild() {
92
- const childNodes = this.currentNode ? this.currentNode[PropertySymbol.nodeArray] : [];
93
- if (childNodes.length > 0) {
94
- this.currentNode = childNodes[childNodes.length - 1];
95
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
96
- return this.currentNode;
97
- }
98
- return this.previousSibling();
99
- }
100
- return null;
73
+ return this.#traverseChildren(TraverseChildrenTypeEnum.last);
74
+ }
75
+ /**
76
+ * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
77
+ *
78
+ * @returns Current node.
79
+ */
80
+ nextSibling() {
81
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.next);
101
82
  }
102
83
  /**
103
84
  * Moves the current Node to its previous sibling, if any, and returns the found sibling. If there is no such node, return null and the current node is not changed.
@@ -105,41 +86,78 @@ export default class TreeWalker {
105
86
  * @returns Current node.
106
87
  */
107
88
  previousSibling() {
108
- if (this.currentNode !== this.root &&
109
- this.currentNode &&
110
- this.currentNode[PropertySymbol.parentNode]) {
111
- const siblings = this.currentNode[PropertySymbol.parentNode][PropertySymbol.nodeArray];
112
- const index = siblings.indexOf(this.currentNode);
113
- if (index > 0) {
114
- this.currentNode = siblings[index - 1];
115
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
116
- return this.currentNode;
89
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.previous);
90
+ }
91
+ /**
92
+ * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
93
+ *
94
+ * @returns Current node.
95
+ */
96
+ previousNode() {
97
+ let node = this.currentNode;
98
+ while (node !== this.root) {
99
+ let sibling = node.previousSibling;
100
+ while (sibling !== null) {
101
+ let node = sibling;
102
+ let result = this[PropertySymbol.filterNode](node);
103
+ while (result !== NodeFilter.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
104
+ node = node.lastChild;
105
+ result = this[PropertySymbol.filterNode](node);
117
106
  }
118
- return this.previousSibling();
107
+ if (result === NodeFilter.FILTER_ACCEPT) {
108
+ this.currentNode = node;
109
+ return node;
110
+ }
111
+ sibling = node.previousSibling;
112
+ }
113
+ if (node === this.root || node.parentNode === null) {
114
+ return null;
115
+ }
116
+ node = node.parentNode;
117
+ if (this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
118
+ this.currentNode = node;
119
+ return node;
119
120
  }
120
121
  }
121
122
  return null;
122
123
  }
123
124
  /**
124
- * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
125
+ * Moves the current Node to the next visible node in the document order.
125
126
  *
126
127
  * @returns Current node.
127
128
  */
128
- nextSibling() {
129
- if (this.currentNode !== this.root &&
130
- this.currentNode &&
131
- this.currentNode[PropertySymbol.parentNode]) {
132
- const siblings = this.currentNode[PropertySymbol.parentNode][PropertySymbol.nodeArray];
133
- const index = siblings.indexOf(this.currentNode);
134
- if (index + 1 < siblings.length) {
135
- this.currentNode = siblings[index + 1];
136
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
137
- return this.currentNode;
129
+ nextNode() {
130
+ let node = this.currentNode;
131
+ let result = NodeFilter.FILTER_ACCEPT;
132
+ while (true) {
133
+ while (result !== NodeFilter.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
134
+ node = node.firstChild;
135
+ result = this[PropertySymbol.filterNode](node);
136
+ if (result === NodeFilter.FILTER_ACCEPT) {
137
+ this.currentNode = node;
138
+ return node;
139
+ }
140
+ }
141
+ while (node !== null) {
142
+ if (node === this.root) {
143
+ return null;
138
144
  }
139
- return this.nextSibling();
145
+ const sibling = node.nextSibling;
146
+ if (sibling !== null) {
147
+ node = sibling;
148
+ break;
149
+ }
150
+ node = node.parentNode;
151
+ }
152
+ if (node === null) {
153
+ return null;
154
+ }
155
+ result = this[PropertySymbol.filterNode](node);
156
+ if (result === NodeFilter.FILTER_ACCEPT) {
157
+ this.currentNode = node;
158
+ return node;
140
159
  }
141
160
  }
142
- return null;
143
161
  }
144
162
  /**
145
163
  * Filters a node.
@@ -163,5 +181,77 @@ export default class TreeWalker {
163
181
  }
164
182
  return NodeFilter.FILTER_ACCEPT;
165
183
  }
184
+ /**
185
+ * Traverses children.
186
+ *
187
+ * @param type Type.
188
+ * @returns Node.
189
+ */
190
+ #traverseChildren(type) {
191
+ let node = this.currentNode;
192
+ node = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
193
+ while (node !== null) {
194
+ const result = this[PropertySymbol.filterNode](node);
195
+ if (result === NodeFilter.FILTER_ACCEPT) {
196
+ this.currentNode = node;
197
+ return node;
198
+ }
199
+ if (result === NodeFilter.FILTER_SKIP) {
200
+ const child = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
201
+ if (child !== null) {
202
+ node = child;
203
+ continue;
204
+ }
205
+ }
206
+ while (node !== null) {
207
+ const sibling = type === TraverseChildrenTypeEnum.first ? node.nextSibling : node.previousSibling;
208
+ if (sibling !== null) {
209
+ node = sibling;
210
+ break;
211
+ }
212
+ const parent = node.parentNode;
213
+ if (parent === null || parent === this.root || parent === this.currentNode) {
214
+ return null;
215
+ }
216
+ node = parent;
217
+ }
218
+ }
219
+ return null;
220
+ }
221
+ /**
222
+ * Traverses siblings.
223
+ *
224
+ * @param type Type.
225
+ * @returns Node.
226
+ */
227
+ #traverseSiblings(type) {
228
+ let node = this.currentNode;
229
+ if (node === this.root) {
230
+ return null;
231
+ }
232
+ while (true) {
233
+ let sibling = type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
234
+ while (sibling !== null) {
235
+ const node = sibling;
236
+ const result = this[PropertySymbol.filterNode](node);
237
+ if (result === NodeFilter.FILTER_ACCEPT) {
238
+ this.currentNode = node;
239
+ return node;
240
+ }
241
+ sibling = type === TraverseSiblingsTypeEnum.next ? node.firstChild : node.lastChild;
242
+ if (result === NodeFilter.FILTER_REJECT || sibling === null) {
243
+ sibling =
244
+ type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
245
+ }
246
+ }
247
+ node = node.parentNode;
248
+ if (node === null || node === this.root) {
249
+ return null;
250
+ }
251
+ if (this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
252
+ return null;
253
+ }
254
+ }
255
+ }
166
256
  }
167
257
  //# sourceMappingURL=TreeWalker.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"TreeWalker.js","sourceRoot":"","sources":["../../src/tree-walker/TreeWalker.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,uBAAuB,CAAC;AACzC,OAAO,KAAK,cAAc,MAAM,sBAAsB,CAAC;AAEvD,OAAO,cAAc,MAAM,qBAAqB,CAAC;AACjD,OAAO,YAAY,MAAM,8BAA8B,CAAC;AACxD,OAAO,UAAU,MAAM,iBAAiB,CAAC;AAEzC;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,UAAU;IACvB,IAAI,GAAS,IAAI,CAAC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O,IAAI,CAAC;YACb,CAAC;YAED,IAAI,IAAI,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,IAAI,CAAC,KAAK,UAAU,CAAC,aAAa,EAAE,CAAC;gBACxE,OAAO,IAAI,CAAC;YACb,CAAC;QACF,CAAC;IACF,CAAC;CACD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "happy-dom",
3
- "version": "17.1.3",
3
+ "version": "17.1.4",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/capricorn86/happy-dom",
6
6
  "repository": "https://github.com/capricorn86/happy-dom",
@@ -5,8 +5,21 @@ import NodeFilterMask from './NodeFilterMask.js';
5
5
  import DOMException from '../exception/DOMException.js';
6
6
  import NodeFilter from './NodeFilter.js';
7
7
 
8
+ enum TraverseChildrenTypeEnum {
9
+ first = 'first',
10
+ last = 'last'
11
+ }
12
+
13
+ enum TraverseSiblingsTypeEnum {
14
+ next = 'next',
15
+ previous = 'previous'
16
+ }
17
+
8
18
  /**
9
19
  * The TreeWalker object represents the nodes of a document subtree and a position within them.
20
+ *
21
+ * @see https://developer.mozilla.org/en-US/docs/Web/API/TreeWalker
22
+ * @see https://dom.spec.whatwg.org/#interface-treewalker
10
23
  */
11
24
  export default class TreeWalker {
12
25
  public root: Node = null;
@@ -32,52 +45,20 @@ export default class TreeWalker {
32
45
  this.currentNode = root;
33
46
  }
34
47
 
35
- /**
36
- * Moves the current Node to the next visible node in the document order.
37
- *
38
- * @returns Current node.
39
- */
40
- public nextNode(): Node {
41
- if (!this.firstChild()) {
42
- while (!this.nextSibling() && this.parentNode()) {}
43
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
44
- }
45
- return this.currentNode;
46
- }
47
-
48
- /**
49
- * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
50
- *
51
- * @returns Current node.
52
- */
53
- public previousNode(): Node {
54
- while (!this.previousSibling() && this.parentNode()) {}
55
- this.currentNode = this.currentNode === this.root ? null : this.currentNode || null;
56
- return this.currentNode;
57
- }
58
-
59
48
  /**
60
49
  * Moves the current Node to the first visible ancestor node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
61
50
  *
62
51
  * @returns Current node.
63
52
  */
64
53
  public parentNode(): Node {
65
- if (
66
- this.currentNode !== this.root &&
67
- this.currentNode &&
68
- this.currentNode[PropertySymbol.parentNode]
69
- ) {
70
- this.currentNode = this.currentNode[PropertySymbol.parentNode];
71
-
72
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
54
+ let node = this.currentNode;
55
+ while (node !== null && node !== this.root) {
56
+ node = node.parentNode;
57
+ if (node !== null && this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
58
+ this.currentNode = node;
73
59
  return this.currentNode;
74
60
  }
75
-
76
- this.parentNode();
77
61
  }
78
-
79
- this.currentNode = null;
80
-
81
62
  return null;
82
63
  }
83
64
 
@@ -87,19 +68,7 @@ export default class TreeWalker {
87
68
  * @returns Current node.
88
69
  */
89
70
  public firstChild(): Node {
90
- const childNodes = this.currentNode ? (<Node>this.currentNode)[PropertySymbol.nodeArray] : [];
91
-
92
- if (childNodes.length > 0) {
93
- this.currentNode = childNodes[0];
94
-
95
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
96
- return this.currentNode;
97
- }
98
-
99
- return this.nextSibling();
100
- }
101
-
102
- return null;
71
+ return this.#traverseChildren(TraverseChildrenTypeEnum.first);
103
72
  }
104
73
 
105
74
  /**
@@ -108,19 +77,16 @@ export default class TreeWalker {
108
77
  * @returns Current node.
109
78
  */
110
79
  public lastChild(): Node {
111
- const childNodes = this.currentNode ? (<Node>this.currentNode)[PropertySymbol.nodeArray] : [];
112
-
113
- if (childNodes.length > 0) {
114
- this.currentNode = childNodes[childNodes.length - 1];
115
-
116
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
117
- return this.currentNode;
118
- }
119
-
120
- return this.previousSibling();
121
- }
80
+ return this.#traverseChildren(TraverseChildrenTypeEnum.last);
81
+ }
122
82
 
123
- return null;
83
+ /**
84
+ * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
85
+ *
86
+ * @returns Current node.
87
+ */
88
+ public nextSibling(): Node {
89
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.next);
124
90
  }
125
91
 
126
92
  /**
@@ -129,24 +95,46 @@ export default class TreeWalker {
129
95
  * @returns Current node.
130
96
  */
131
97
  public previousSibling(): Node {
132
- if (
133
- this.currentNode !== this.root &&
134
- this.currentNode &&
135
- this.currentNode[PropertySymbol.parentNode]
136
- ) {
137
- const siblings = (<Node>this.currentNode[PropertySymbol.parentNode])[
138
- PropertySymbol.nodeArray
139
- ];
140
- const index = siblings.indexOf(this.currentNode);
141
-
142
- if (index > 0) {
143
- this.currentNode = siblings[index - 1];
144
-
145
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
146
- return this.currentNode;
98
+ return this.#traverseSiblings(TraverseSiblingsTypeEnum.previous);
99
+ }
100
+
101
+ /**
102
+ * Moves the current Node to the previous visible node in the document order, and returns the found node. It also moves the current node to this one. If no such node exists, or if it is before that the root node defined at the object construction, returns null and the current node is not changed.
103
+ *
104
+ * @returns Current node.
105
+ */
106
+ public previousNode(): Node {
107
+ let node = this.currentNode;
108
+
109
+ while (node !== this.root) {
110
+ let sibling = node.previousSibling;
111
+
112
+ while (sibling !== null) {
113
+ let node = sibling;
114
+ let result = this[PropertySymbol.filterNode](node);
115
+
116
+ while (result !== NodeFilter.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
117
+ node = node.lastChild;
118
+ result = this[PropertySymbol.filterNode](node);
147
119
  }
148
120
 
149
- return this.previousSibling();
121
+ if (result === NodeFilter.FILTER_ACCEPT) {
122
+ this.currentNode = node;
123
+ return node;
124
+ }
125
+
126
+ sibling = node.previousSibling;
127
+ }
128
+
129
+ if (node === this.root || node.parentNode === null) {
130
+ return null;
131
+ }
132
+
133
+ node = node.parentNode;
134
+
135
+ if (this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
136
+ this.currentNode = node;
137
+ return node;
150
138
  }
151
139
  }
152
140
 
@@ -154,33 +142,51 @@ export default class TreeWalker {
154
142
  }
155
143
 
156
144
  /**
157
- * Moves the current Node to its next sibling, if any, and returns the found sibling. If there is no such node, null is returned and the current node is not changed.
145
+ * Moves the current Node to the next visible node in the document order.
158
146
  *
159
147
  * @returns Current node.
160
148
  */
161
- public nextSibling(): Node {
162
- if (
163
- this.currentNode !== this.root &&
164
- this.currentNode &&
165
- this.currentNode[PropertySymbol.parentNode]
166
- ) {
167
- const siblings = (<Node>this.currentNode[PropertySymbol.parentNode])[
168
- PropertySymbol.nodeArray
169
- ];
170
- const index = siblings.indexOf(this.currentNode);
171
-
172
- if (index + 1 < siblings.length) {
173
- this.currentNode = siblings[index + 1];
174
-
175
- if (this[PropertySymbol.filterNode](this.currentNode) === NodeFilter.FILTER_ACCEPT) {
176
- return this.currentNode;
149
+ public nextNode(): Node | null {
150
+ let node = this.currentNode;
151
+ let result = NodeFilter.FILTER_ACCEPT;
152
+
153
+ while (true) {
154
+ while (result !== NodeFilter.FILTER_REJECT && node[PropertySymbol.nodeArray].length) {
155
+ node = node.firstChild;
156
+ result = this[PropertySymbol.filterNode](node);
157
+
158
+ if (result === NodeFilter.FILTER_ACCEPT) {
159
+ this.currentNode = node;
160
+ return node;
177
161
  }
162
+ }
178
163
 
179
- return this.nextSibling();
164
+ while (node !== null) {
165
+ if (node === this.root) {
166
+ return null;
167
+ }
168
+
169
+ const sibling = node.nextSibling;
170
+
171
+ if (sibling !== null) {
172
+ node = sibling;
173
+ break;
174
+ }
175
+
176
+ node = node.parentNode;
180
177
  }
181
- }
182
178
 
183
- return null;
179
+ if (node === null) {
180
+ return null;
181
+ }
182
+
183
+ result = this[PropertySymbol.filterNode](node);
184
+
185
+ if (result === NodeFilter.FILTER_ACCEPT) {
186
+ this.currentNode = node;
187
+ return node;
188
+ }
189
+ }
184
190
  }
185
191
 
186
192
  /**
@@ -207,4 +213,95 @@ export default class TreeWalker {
207
213
 
208
214
  return NodeFilter.FILTER_ACCEPT;
209
215
  }
216
+
217
+ /**
218
+ * Traverses children.
219
+ *
220
+ * @param type Type.
221
+ * @returns Node.
222
+ */
223
+ #traverseChildren(type: TraverseChildrenTypeEnum): Node | null {
224
+ let node: Node = this.currentNode;
225
+ node = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
226
+
227
+ while (node !== null) {
228
+ const result = this[PropertySymbol.filterNode](node);
229
+
230
+ if (result === NodeFilter.FILTER_ACCEPT) {
231
+ this.currentNode = node;
232
+ return node;
233
+ }
234
+
235
+ if (result === NodeFilter.FILTER_SKIP) {
236
+ const child = type === TraverseChildrenTypeEnum.first ? node.firstChild : node.lastChild;
237
+
238
+ if (child !== null) {
239
+ node = child;
240
+ continue;
241
+ }
242
+ }
243
+
244
+ while (node !== null) {
245
+ const sibling =
246
+ type === TraverseChildrenTypeEnum.first ? node.nextSibling : node.previousSibling;
247
+ if (sibling !== null) {
248
+ node = sibling;
249
+ break;
250
+ }
251
+ const parent = node.parentNode;
252
+ if (parent === null || parent === this.root || parent === this.currentNode) {
253
+ return null;
254
+ }
255
+ node = parent;
256
+ }
257
+ }
258
+
259
+ return null;
260
+ }
261
+
262
+ /**
263
+ * Traverses siblings.
264
+ *
265
+ * @param type Type.
266
+ * @returns Node.
267
+ */
268
+ #traverseSiblings(type: TraverseSiblingsTypeEnum): Node | null {
269
+ let node: Node = this.currentNode;
270
+
271
+ if (node === this.root) {
272
+ return null;
273
+ }
274
+
275
+ while (true) {
276
+ let sibling =
277
+ type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
278
+
279
+ while (sibling !== null) {
280
+ const node = sibling;
281
+ const result = this[PropertySymbol.filterNode](node);
282
+
283
+ if (result === NodeFilter.FILTER_ACCEPT) {
284
+ this.currentNode = node;
285
+ return node;
286
+ }
287
+
288
+ sibling = type === TraverseSiblingsTypeEnum.next ? node.firstChild : node.lastChild;
289
+
290
+ if (result === NodeFilter.FILTER_REJECT || sibling === null) {
291
+ sibling =
292
+ type === TraverseSiblingsTypeEnum.next ? node.nextSibling : node.previousSibling;
293
+ }
294
+ }
295
+
296
+ node = node.parentNode;
297
+
298
+ if (node === null || node === this.root) {
299
+ return null;
300
+ }
301
+
302
+ if (this[PropertySymbol.filterNode](node) === NodeFilter.FILTER_ACCEPT) {
303
+ return null;
304
+ }
305
+ }
306
+ }
210
307
  }