happy-dom 10.10.4 → 10.11.1

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.

Potentially problematic release.


This version of happy-dom might be problematic. Click here for more details.

Files changed (144) hide show
  1. package/cjs/dom-parser/DOMParser.cjs +5 -5
  2. package/cjs/dom-parser/DOMParser.cjs.map +1 -1
  3. package/cjs/dom-parser/DOMParser.d.ts.map +1 -1
  4. package/cjs/nodes/child-node/ChildNodeUtility.cjs +3 -3
  5. package/cjs/nodes/child-node/ChildNodeUtility.cjs.map +1 -1
  6. package/cjs/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
  7. package/cjs/nodes/document/Document.cjs +24 -18
  8. package/cjs/nodes/document/Document.cjs.map +1 -1
  9. package/cjs/nodes/document/Document.d.ts +5 -1
  10. package/cjs/nodes/document/Document.d.ts.map +1 -1
  11. package/cjs/nodes/document-fragment/DocumentFragment.cjs +14 -8
  12. package/cjs/nodes/document-fragment/DocumentFragment.cjs.map +1 -1
  13. package/cjs/nodes/document-fragment/DocumentFragment.d.ts +5 -1
  14. package/cjs/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
  15. package/cjs/nodes/element/Element.cjs +17 -11
  16. package/cjs/nodes/element/Element.cjs.map +1 -1
  17. package/cjs/nodes/element/Element.d.ts +5 -1
  18. package/cjs/nodes/element/Element.d.ts.map +1 -1
  19. package/cjs/nodes/element/ElementNamedNodeMap.cjs +5 -5
  20. package/cjs/nodes/element/ElementNamedNodeMap.cjs.map +1 -1
  21. package/cjs/nodes/element/ElementUtility.cjs +37 -28
  22. package/cjs/nodes/element/ElementUtility.cjs.map +1 -1
  23. package/cjs/nodes/element/ElementUtility.d.ts.map +1 -1
  24. package/cjs/nodes/html-element/HTMLElement.cjs +2 -2
  25. package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
  26. package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs +3 -3
  27. package/cjs/nodes/html-slot-element/HTMLSlotElement.cjs.map +1 -1
  28. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs +2 -2
  29. package/cjs/nodes/html-template-element/HTMLTemplateElement.cjs.map +1 -1
  30. package/cjs/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  31. package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs +11 -11
  32. package/cjs/nodes/html-unknown-element/HTMLUnknownElement.cjs.map +1 -1
  33. package/cjs/nodes/node/Node.cjs +29 -21
  34. package/cjs/nodes/node/Node.cjs.map +1 -1
  35. package/cjs/nodes/node/Node.d.ts +7 -1
  36. package/cjs/nodes/node/Node.d.ts.map +1 -1
  37. package/cjs/nodes/node/NodeUtility.cjs +17 -17
  38. package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
  39. package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
  40. package/cjs/nodes/parent-node/ParentNodeUtility.cjs +7 -7
  41. package/cjs/nodes/parent-node/ParentNodeUtility.cjs.map +1 -1
  42. package/cjs/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  43. package/cjs/nodes/shadow-root/ShadowRoot.cjs +2 -2
  44. package/cjs/nodes/shadow-root/ShadowRoot.cjs.map +1 -1
  45. package/cjs/query-selector/QuerySelector.cjs +10 -8
  46. package/cjs/query-selector/QuerySelector.cjs.map +1 -1
  47. package/cjs/query-selector/QuerySelector.d.ts.map +1 -1
  48. package/cjs/query-selector/SelectorItem.cjs +15 -14
  49. package/cjs/query-selector/SelectorItem.cjs.map +1 -1
  50. package/cjs/query-selector/SelectorItem.d.ts.map +1 -1
  51. package/cjs/range/Range.cjs +12 -12
  52. package/cjs/range/Range.cjs.map +1 -1
  53. package/cjs/range/Range.d.ts.map +1 -1
  54. package/cjs/range/RangeUtility.cjs +1 -1
  55. package/cjs/range/RangeUtility.cjs.map +1 -1
  56. package/cjs/range/RangeUtility.d.ts.map +1 -1
  57. package/cjs/tree-walker/TreeWalker.cjs +4 -4
  58. package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
  59. package/cjs/xml-serializer/XMLSerializer.cjs +4 -4
  60. package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
  61. package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
  62. package/lib/dom-parser/DOMParser.d.ts.map +1 -1
  63. package/lib/dom-parser/DOMParser.js +5 -5
  64. package/lib/dom-parser/DOMParser.js.map +1 -1
  65. package/lib/nodes/child-node/ChildNodeUtility.d.ts.map +1 -1
  66. package/lib/nodes/child-node/ChildNodeUtility.js +3 -3
  67. package/lib/nodes/child-node/ChildNodeUtility.js.map +1 -1
  68. package/lib/nodes/document/Document.d.ts +5 -1
  69. package/lib/nodes/document/Document.d.ts.map +1 -1
  70. package/lib/nodes/document/Document.js +24 -18
  71. package/lib/nodes/document/Document.js.map +1 -1
  72. package/lib/nodes/document-fragment/DocumentFragment.d.ts +5 -1
  73. package/lib/nodes/document-fragment/DocumentFragment.d.ts.map +1 -1
  74. package/lib/nodes/document-fragment/DocumentFragment.js +14 -8
  75. package/lib/nodes/document-fragment/DocumentFragment.js.map +1 -1
  76. package/lib/nodes/element/Element.d.ts +5 -1
  77. package/lib/nodes/element/Element.d.ts.map +1 -1
  78. package/lib/nodes/element/Element.js +17 -11
  79. package/lib/nodes/element/Element.js.map +1 -1
  80. package/lib/nodes/element/ElementNamedNodeMap.js +5 -5
  81. package/lib/nodes/element/ElementNamedNodeMap.js.map +1 -1
  82. package/lib/nodes/element/ElementUtility.d.ts.map +1 -1
  83. package/lib/nodes/element/ElementUtility.js +37 -28
  84. package/lib/nodes/element/ElementUtility.js.map +1 -1
  85. package/lib/nodes/html-element/HTMLElement.js +2 -2
  86. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  87. package/lib/nodes/html-slot-element/HTMLSlotElement.js +3 -3
  88. package/lib/nodes/html-slot-element/HTMLSlotElement.js.map +1 -1
  89. package/lib/nodes/html-template-element/HTMLTemplateElement.d.ts.map +1 -1
  90. package/lib/nodes/html-template-element/HTMLTemplateElement.js +2 -2
  91. package/lib/nodes/html-template-element/HTMLTemplateElement.js.map +1 -1
  92. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js +11 -11
  93. package/lib/nodes/html-unknown-element/HTMLUnknownElement.js.map +1 -1
  94. package/lib/nodes/node/Node.d.ts +7 -1
  95. package/lib/nodes/node/Node.d.ts.map +1 -1
  96. package/lib/nodes/node/Node.js +29 -21
  97. package/lib/nodes/node/Node.js.map +1 -1
  98. package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
  99. package/lib/nodes/node/NodeUtility.js +17 -17
  100. package/lib/nodes/node/NodeUtility.js.map +1 -1
  101. package/lib/nodes/parent-node/ParentNodeUtility.d.ts.map +1 -1
  102. package/lib/nodes/parent-node/ParentNodeUtility.js +7 -7
  103. package/lib/nodes/parent-node/ParentNodeUtility.js.map +1 -1
  104. package/lib/nodes/shadow-root/ShadowRoot.js +2 -2
  105. package/lib/nodes/shadow-root/ShadowRoot.js.map +1 -1
  106. package/lib/query-selector/QuerySelector.d.ts.map +1 -1
  107. package/lib/query-selector/QuerySelector.js +10 -8
  108. package/lib/query-selector/QuerySelector.js.map +1 -1
  109. package/lib/query-selector/SelectorItem.d.ts.map +1 -1
  110. package/lib/query-selector/SelectorItem.js +15 -14
  111. package/lib/query-selector/SelectorItem.js.map +1 -1
  112. package/lib/range/Range.d.ts.map +1 -1
  113. package/lib/range/Range.js +12 -12
  114. package/lib/range/Range.js.map +1 -1
  115. package/lib/range/RangeUtility.d.ts.map +1 -1
  116. package/lib/range/RangeUtility.js +1 -1
  117. package/lib/range/RangeUtility.js.map +1 -1
  118. package/lib/tree-walker/TreeWalker.js +4 -4
  119. package/lib/tree-walker/TreeWalker.js.map +1 -1
  120. package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
  121. package/lib/xml-serializer/XMLSerializer.js +4 -4
  122. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  123. package/package.json +1 -1
  124. package/src/dom-parser/DOMParser.ts +9 -7
  125. package/src/nodes/child-node/ChildNodeUtility.ts +10 -12
  126. package/src/nodes/document/Document.ts +29 -22
  127. package/src/nodes/document-fragment/DocumentFragment.ts +16 -9
  128. package/src/nodes/element/Element.ts +23 -12
  129. package/src/nodes/element/ElementNamedNodeMap.ts +5 -5
  130. package/src/nodes/element/ElementUtility.ts +44 -43
  131. package/src/nodes/html-element/HTMLElement.ts +2 -2
  132. package/src/nodes/html-slot-element/HTMLSlotElement.ts +3 -3
  133. package/src/nodes/html-template-element/HTMLTemplateElement.ts +3 -2
  134. package/src/nodes/html-unknown-element/HTMLUnknownElement.ts +11 -11
  135. package/src/nodes/node/Node.ts +30 -21
  136. package/src/nodes/node/NodeUtility.ts +21 -17
  137. package/src/nodes/parent-node/ParentNodeUtility.ts +10 -10
  138. package/src/nodes/shadow-root/ShadowRoot.ts +2 -2
  139. package/src/query-selector/QuerySelector.ts +24 -8
  140. package/src/query-selector/SelectorItem.ts +15 -14
  141. package/src/range/Range.ts +13 -12
  142. package/src/range/RangeUtility.ts +2 -1
  143. package/src/tree-walker/TreeWalker.ts +4 -4
  144. package/src/xml-serializer/XMLSerializer.ts +6 -4
@@ -54,7 +54,6 @@ export default class Node extends EventTarget implements INode {
54
54
  public readonly ownerDocument: IDocument = null;
55
55
  public readonly parentNode: INode = null;
56
56
  public readonly nodeType: number;
57
- public readonly childNodes: INodeList<INode> = new NodeList<INode>();
58
57
  public readonly isConnected: boolean = false;
59
58
 
60
59
  // Custom Properties (not part of HTML standard)
@@ -63,6 +62,7 @@ export default class Node extends EventTarget implements INode {
63
62
  public _selectNode: INode = null;
64
63
  public _textAreaNode: INode = null;
65
64
  public _observers: MutationListener[] = [];
65
+ public readonly _childNodes: INodeList<INode> = new NodeList<INode>();
66
66
 
67
67
  /**
68
68
  * Constructor.
@@ -81,6 +81,15 @@ export default class Node extends EventTarget implements INode {
81
81
  return this.constructor.name;
82
82
  }
83
83
 
84
+ /**
85
+ * Get child nodes.
86
+ *
87
+ * @returns Child nodes list.
88
+ */
89
+ public get childNodes(): INodeList<INode> {
90
+ return this._childNodes;
91
+ }
92
+
84
93
  /**
85
94
  * Get text value of children.
86
95
  *
@@ -133,9 +142,9 @@ export default class Node extends EventTarget implements INode {
133
142
  */
134
143
  public get previousSibling(): INode {
135
144
  if (this.parentNode) {
136
- const index = this.parentNode.childNodes.indexOf(this);
145
+ const index = (<Node>this.parentNode)._childNodes.indexOf(this);
137
146
  if (index > 0) {
138
- return this.parentNode.childNodes[index - 1];
147
+ return (<Node>this.parentNode)._childNodes[index - 1];
139
148
  }
140
149
  }
141
150
  return null;
@@ -148,9 +157,9 @@ export default class Node extends EventTarget implements INode {
148
157
  */
149
158
  public get nextSibling(): INode {
150
159
  if (this.parentNode) {
151
- const index = this.parentNode.childNodes.indexOf(this);
152
- if (index > -1 && index + 1 < this.parentNode.childNodes.length) {
153
- return this.parentNode.childNodes[index + 1];
160
+ const index = (<Node>this.parentNode)._childNodes.indexOf(this);
161
+ if (index > -1 && index + 1 < (<Node>this.parentNode)._childNodes.length) {
162
+ return (<Node>this.parentNode)._childNodes[index + 1];
154
163
  }
155
164
  }
156
165
  return null;
@@ -162,8 +171,8 @@ export default class Node extends EventTarget implements INode {
162
171
  * @returns Node.
163
172
  */
164
173
  public get firstChild(): INode {
165
- if (this.childNodes.length > 0) {
166
- return this.childNodes[0];
174
+ if (this._childNodes.length > 0) {
175
+ return this._childNodes[0];
167
176
  }
168
177
  return null;
169
178
  }
@@ -174,8 +183,8 @@ export default class Node extends EventTarget implements INode {
174
183
  * @returns Node.
175
184
  */
176
185
  public get lastChild(): INode {
177
- if (this.childNodes.length > 0) {
178
- return this.childNodes[this.childNodes.length - 1];
186
+ if (this._childNodes.length > 0) {
187
+ return this._childNodes[this._childNodes.length - 1];
179
188
  }
180
189
  return null;
181
190
  }
@@ -222,7 +231,7 @@ export default class Node extends EventTarget implements INode {
222
231
  * @returns "true" if the node has child nodes.
223
232
  */
224
233
  public hasChildNodes(): boolean {
225
- return this.childNodes.length > 0;
234
+ return this._childNodes.length > 0;
226
235
  }
227
236
 
228
237
  /**
@@ -264,17 +273,17 @@ export default class Node extends EventTarget implements INode {
264
273
  const clone = new (<typeof Node>this.constructor)();
265
274
 
266
275
  // Document has childNodes directly when it is created
267
- if (clone.childNodes.length) {
268
- for (const node of clone.childNodes.slice()) {
276
+ if (clone._childNodes.length) {
277
+ for (const node of clone._childNodes.slice()) {
269
278
  node.parentNode.removeChild(node);
270
279
  }
271
280
  }
272
281
 
273
282
  if (deep) {
274
- for (const childNode of this.childNodes) {
283
+ for (const childNode of this._childNodes) {
275
284
  const childClone = childNode.cloneNode(true);
276
285
  (<Node>childClone.parentNode) = clone;
277
- clone.childNodes.push(childClone);
286
+ clone._childNodes.push(childClone);
278
287
  }
279
288
  }
280
289
 
@@ -351,7 +360,7 @@ export default class Node extends EventTarget implements INode {
351
360
  public _observe(listener: MutationListener): void {
352
361
  this._observers.push(listener);
353
362
  if (listener.options.subtree) {
354
- for (const node of this.childNodes) {
363
+ for (const node of this._childNodes) {
355
364
  (<Node>node)._observe(listener);
356
365
  }
357
366
  }
@@ -369,7 +378,7 @@ export default class Node extends EventTarget implements INode {
369
378
  this._observers.splice(index, 1);
370
379
  }
371
380
  if (listener.options.subtree) {
372
- for (const node of this.childNodes) {
381
+ for (const node of this._childNodes) {
373
382
  (<Node>node)._unobserve(listener);
374
383
  }
375
384
  }
@@ -418,7 +427,7 @@ export default class Node extends EventTarget implements INode {
418
427
  this.disconnectedCallback();
419
428
  }
420
429
 
421
- for (const child of this.childNodes) {
430
+ for (const child of this._childNodes) {
422
431
  (<Node>child)._connectToNode(this);
423
432
  }
424
433
 
@@ -432,7 +441,7 @@ export default class Node extends EventTarget implements INode {
432
441
  selectNode !== this._selectNode ||
433
442
  textAreaNode !== this._textAreaNode
434
443
  ) {
435
- for (const child of this.childNodes) {
444
+ for (const child of this._childNodes) {
436
445
  (<Node>child)._connectToNode(this);
437
446
  }
438
447
  }
@@ -584,7 +593,7 @@ export default class Node extends EventTarget implements INode {
584
593
 
585
594
  const computeNodeIndexes = (nodes: INode[]): void => {
586
595
  for (const childNode of nodes) {
587
- computeNodeIndexes(childNode.childNodes);
596
+ computeNodeIndexes((<Node>childNode)._childNodes);
588
597
 
589
598
  if (childNode === node2Node) {
590
599
  node2Index = indexes;
@@ -600,7 +609,7 @@ export default class Node extends EventTarget implements INode {
600
609
  }
601
610
  };
602
611
 
603
- computeNodeIndexes(commonAncestor.childNodes);
612
+ computeNodeIndexes((<Node>commonAncestor)._childNodes);
604
613
 
605
614
  /**
606
615
  * 9. If node1 is preceding node2, then return DOCUMENT_POSITION_PRECEDING.
@@ -47,7 +47,7 @@ export default class NodeUtility {
47
47
  // If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
48
48
  // See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
49
49
  if (node.nodeType === NodeTypeEnum.documentFragmentNode) {
50
- for (const child of node.childNodes.slice()) {
50
+ for (const child of (<Node>node)._childNodes.slice()) {
51
51
  ancestorNode.appendChild(child);
52
52
  }
53
53
  return node;
@@ -55,9 +55,9 @@ export default class NodeUtility {
55
55
 
56
56
  // Remove the node from its previous parent if it has any.
57
57
  if (node.parentNode) {
58
- const index = node.parentNode.childNodes.indexOf(node);
58
+ const index = (<Node>node.parentNode)._childNodes.indexOf(node);
59
59
  if (index !== -1) {
60
- node.parentNode.childNodes.splice(index, 1);
60
+ (<Node>node.parentNode)._childNodes.splice(index, 1);
61
61
  }
62
62
  }
63
63
 
@@ -65,7 +65,7 @@ export default class NodeUtility {
65
65
  (ancestorNode.ownerDocument || this)['_cacheID']++;
66
66
  }
67
67
 
68
- ancestorNode.childNodes.push(node);
68
+ (<Node>ancestorNode)._childNodes.push(node);
69
69
 
70
70
  (<Node>node)._connectToNode(ancestorNode);
71
71
 
@@ -97,7 +97,7 @@ export default class NodeUtility {
97
97
  * @returns Removed node.
98
98
  */
99
99
  public static removeChild(ancestorNode: INode, node: INode): INode {
100
- const index = ancestorNode.childNodes.indexOf(node);
100
+ const index = (<Node>ancestorNode)._childNodes.indexOf(node);
101
101
 
102
102
  if (index === -1) {
103
103
  throw new DOMException('Failed to remove node. Node is not child of parent.');
@@ -107,7 +107,7 @@ export default class NodeUtility {
107
107
  (ancestorNode.ownerDocument || this)['_cacheID']++;
108
108
  }
109
109
 
110
- ancestorNode.childNodes.splice(index, 1);
110
+ (<Node>ancestorNode)._childNodes.splice(index, 1);
111
111
 
112
112
  (<Node>node)._connectToNode(null);
113
113
 
@@ -158,7 +158,7 @@ export default class NodeUtility {
158
158
  // If the type is DocumentFragment, then the child nodes of if it should be moved instead of the actual node.
159
159
  // See: https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment
160
160
  if (newNode.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
161
- for (const child of newNode.childNodes.slice()) {
161
+ for (const child of (<Node>newNode)._childNodes.slice()) {
162
162
  ancestorNode.insertBefore(child, referenceNode);
163
163
  }
164
164
  return newNode;
@@ -171,7 +171,7 @@ export default class NodeUtility {
171
171
  return newNode;
172
172
  }
173
173
 
174
- if (ancestorNode.childNodes.indexOf(referenceNode) === -1) {
174
+ if ((<Node>ancestorNode)._childNodes.indexOf(referenceNode) === -1) {
175
175
  throw new DOMException(
176
176
  "Failed to execute 'insertBefore' on 'Node': The node before which the new node is to be inserted is not a child of this node."
177
177
  );
@@ -182,13 +182,17 @@ export default class NodeUtility {
182
182
  }
183
183
 
184
184
  if (newNode.parentNode) {
185
- const index = newNode.parentNode.childNodes.indexOf(newNode);
185
+ const index = (<Node>newNode.parentNode)._childNodes.indexOf(newNode);
186
186
  if (index !== -1) {
187
- newNode.parentNode.childNodes.splice(index, 1);
187
+ (<Node>newNode.parentNode)._childNodes.splice(index, 1);
188
188
  }
189
189
  }
190
190
 
191
- ancestorNode.childNodes.splice(ancestorNode.childNodes.indexOf(referenceNode), 0, newNode);
191
+ (<Node>ancestorNode)._childNodes.splice(
192
+ (<Node>ancestorNode)._childNodes.indexOf(referenceNode),
193
+ 0,
194
+ newNode
195
+ );
192
196
 
193
197
  (<Node>newNode)._connectToNode(ancestorNode);
194
198
 
@@ -247,7 +251,7 @@ export default class NodeUtility {
247
251
  return true;
248
252
  }
249
253
 
250
- if (!ancestorNode.childNodes.length) {
254
+ if (!(<Node>ancestorNode)._childNodes.length) {
251
255
  return false;
252
256
  }
253
257
 
@@ -330,7 +334,7 @@ export default class NodeUtility {
330
334
  return (<IText | IComment>node).data.length;
331
335
 
332
336
  default:
333
- return node.childNodes.length;
337
+ return (<Node>node)._childNodes.length;
334
338
  }
335
339
  }
336
340
 
@@ -488,13 +492,13 @@ export default class NodeUtility {
488
492
  return false;
489
493
  }
490
494
 
491
- if (nodeA.childNodes.length !== nodeB.childNodes.length) {
495
+ if ((<Node>nodeA)._childNodes.length !== (<Node>nodeB)._childNodes.length) {
492
496
  return false;
493
497
  }
494
498
 
495
- for (let i = 0; i < nodeA.childNodes.length; i++) {
496
- const childNodeA = nodeA.childNodes[i];
497
- const childNodeB = nodeB.childNodes[i];
499
+ for (let i = 0; i < (<Node>nodeA)._childNodes.length; i++) {
500
+ const childNodeA = (<Node>nodeA)._childNodes[i];
501
+ const childNodeB = (<Node>nodeB)._childNodes[i];
498
502
 
499
503
  if (!NodeUtility.isEqualNode(childNodeA, childNodeB)) {
500
504
  return false;
@@ -5,6 +5,7 @@ import IElement from '../element/IElement.js';
5
5
  import IHTMLCollection from '../element/IHTMLCollection.js';
6
6
  import INode from '../node/INode.js';
7
7
  import HTMLCollection from '../element/HTMLCollection.js';
8
+ import DocumentFragment from '../document-fragment/DocumentFragment.js';
8
9
 
9
10
  /**
10
11
  * Parent node utility.
@@ -42,10 +43,9 @@ export default class ParentNodeUtility {
42
43
  const firstChild = parentNode.firstChild;
43
44
  for (const node of nodes) {
44
45
  if (typeof node === 'string') {
45
- const newChildNodes = XMLParser.parse(
46
- <IDocument>parentNode.ownerDocument,
47
- node
48
- ).childNodes.slice();
46
+ const newChildNodes = (<DocumentFragment>(
47
+ XMLParser.parse(<IDocument>parentNode.ownerDocument, node)
48
+ ))._childNodes.slice();
49
49
  for (const newChildNode of newChildNodes) {
50
50
  parentNode.insertBefore(newChildNode, firstChild);
51
51
  }
@@ -65,7 +65,7 @@ export default class ParentNodeUtility {
65
65
  parentNode: IElement | IDocument | IDocumentFragment,
66
66
  ...nodes: (string | INode)[]
67
67
  ): void {
68
- for (const node of parentNode.childNodes.slice()) {
68
+ for (const node of (<DocumentFragment>parentNode)._childNodes.slice()) {
69
69
  parentNode.removeChild(node);
70
70
  }
71
71
 
@@ -84,7 +84,7 @@ export default class ParentNodeUtility {
84
84
  ): IHTMLCollection<IElement> {
85
85
  let matches = new HTMLCollection<IElement>();
86
86
 
87
- for (const child of parentNode.children) {
87
+ for (const child of (<DocumentFragment>parentNode)._children) {
88
88
  if (child.className.split(' ').includes(className)) {
89
89
  matches.push(child);
90
90
  }
@@ -111,7 +111,7 @@ export default class ParentNodeUtility {
111
111
  const includeAll = tagName === '*';
112
112
  let matches = new HTMLCollection<IElement>();
113
113
 
114
- for (const child of parentNode.children) {
114
+ for (const child of (<DocumentFragment>parentNode)._children) {
115
115
  if (includeAll || child.tagName === upperTagName) {
116
116
  matches.push(child);
117
117
  }
@@ -140,7 +140,7 @@ export default class ParentNodeUtility {
140
140
  const includeAll = tagName === '*';
141
141
  let matches = new HTMLCollection<IElement>();
142
142
 
143
- for (const child of parentNode.children) {
143
+ for (const child of (<DocumentFragment>parentNode)._children) {
144
144
  if ((includeAll || child.tagName === upperTagName) && child.namespaceURI === namespaceURI) {
145
145
  matches.push(child);
146
146
  }
@@ -166,7 +166,7 @@ export default class ParentNodeUtility {
166
166
  ): IElement {
167
167
  const upperTagName = tagName.toUpperCase();
168
168
 
169
- for (const child of parentNode.children) {
169
+ for (const child of (<DocumentFragment>parentNode)._children) {
170
170
  if (child.tagName === upperTagName) {
171
171
  return <IElement>child;
172
172
  }
@@ -191,7 +191,7 @@ export default class ParentNodeUtility {
191
191
  id: string
192
192
  ): IElement {
193
193
  id = String(id);
194
- for (const child of parentNode.children) {
194
+ for (const child of (<DocumentFragment>parentNode)._children) {
195
195
  if (child.id === id) {
196
196
  return <IElement>child;
197
197
  }
@@ -28,7 +28,7 @@ export default class ShadowRoot extends DocumentFragment implements IShadowRoot
28
28
  escapeEntities: false
29
29
  });
30
30
  let xml = '';
31
- for (const node of this.childNodes) {
31
+ for (const node of this._childNodes) {
32
32
  xml += xmlSerializer.serializeToString(node);
33
33
  }
34
34
  return xml;
@@ -40,7 +40,7 @@ export default class ShadowRoot extends DocumentFragment implements IShadowRoot
40
40
  * @param html HTML.
41
41
  */
42
42
  public set innerHTML(html: string) {
43
- for (const child of this.childNodes.slice()) {
43
+ for (const child of this._childNodes.slice()) {
44
44
  this.removeChild(child);
45
45
  }
46
46
 
@@ -8,6 +8,7 @@ import IDocument from '../nodes/document/IDocument.js';
8
8
  import IDocumentFragment from '../nodes/document-fragment/IDocumentFragment.js';
9
9
  import SelectorParser from './SelectorParser.js';
10
10
  import ISelectorMatch from './ISelectorMatch.js';
11
+ import Element from '../nodes/element/Element.js';
11
12
 
12
13
  type IDocumentPositionAndElement = {
13
14
  documentPosition: string;
@@ -48,7 +49,7 @@ export default class QuerySelector {
48
49
  matches = matches.concat(
49
50
  node.nodeType === NodeTypeEnum.elementNode
50
51
  ? this.findAll(<IElement>node, [<IElement>node], items)
51
- : this.findAll(null, node.children, items)
52
+ : this.findAll(null, (<Element>node)._children, items)
52
53
  );
53
54
  }
54
55
 
@@ -92,7 +93,7 @@ export default class QuerySelector {
92
93
  const match =
93
94
  node.nodeType === NodeTypeEnum.elementNode
94
95
  ? this.findFirst(<IElement>node, [<IElement>node], items)
95
- : this.findFirst(null, node.children, items);
96
+ : this.findFirst(null, (<Element>node)._children, items);
96
97
 
97
98
  if (match) {
98
99
  return match;
@@ -248,16 +249,24 @@ export default class QuerySelector {
248
249
  case SelectorCombinatorEnum.descendant:
249
250
  case SelectorCombinatorEnum.child:
250
251
  matched = matched.concat(
251
- this.findAll(rootElement, child.children, selectorItems.slice(1), position)
252
+ this.findAll(
253
+ rootElement,
254
+ (<Element>child)._children,
255
+ selectorItems.slice(1),
256
+ position
257
+ )
252
258
  );
253
259
  break;
254
260
  }
255
261
  }
256
262
  }
257
263
 
258
- if (selectorItem.combinator === SelectorCombinatorEnum.descendant && child.children.length) {
264
+ if (
265
+ selectorItem.combinator === SelectorCombinatorEnum.descendant &&
266
+ (<Element>child)._children.length
267
+ ) {
259
268
  matched = matched.concat(
260
- this.findAll(rootElement, child.children, selectorItems, position)
269
+ this.findAll(rootElement, (<Element>child)._children, selectorItems, position)
261
270
  );
262
271
  }
263
272
  }
@@ -303,7 +312,11 @@ export default class QuerySelector {
303
312
  break;
304
313
  case SelectorCombinatorEnum.descendant:
305
314
  case SelectorCombinatorEnum.child:
306
- const match = this.findFirst(rootElement, child.children, selectorItems.slice(1));
315
+ const match = this.findFirst(
316
+ rootElement,
317
+ (<Element>child)._children,
318
+ selectorItems.slice(1)
319
+ );
307
320
  if (match) {
308
321
  return match;
309
322
  }
@@ -312,8 +325,11 @@ export default class QuerySelector {
312
325
  }
313
326
  }
314
327
 
315
- if (selectorItem.combinator === SelectorCombinatorEnum.descendant && child.children.length) {
316
- const match = this.findFirst(rootElement, child.children, selectorItems);
328
+ if (
329
+ selectorItem.combinator === SelectorCombinatorEnum.descendant &&
330
+ (<Element>child)._children.length
331
+ ) {
332
+ const match = this.findFirst(rootElement, (<Element>child)._children, selectorItems);
317
333
 
318
334
  if (match) {
319
335
  return match;
@@ -112,6 +112,7 @@ export default class SelectorItem {
112
112
  */
113
113
  private matchPsuedo(element: IElement): boolean {
114
114
  const parent = <IElement>element.parentNode;
115
+ const parentChildren = element.parentNode ? (<Element>element.parentNode)._children : [];
115
116
 
116
117
  if (!this.pseudos) {
117
118
  return true;
@@ -150,21 +151,21 @@ export default class SelectorItem {
150
151
 
151
152
  switch (psuedo.name) {
152
153
  case 'first-child':
153
- return parent.children[0] === element;
154
+ return parentChildren[0] === element;
154
155
  case 'last-child':
155
- return parent.children.length && parent.children[parent.children.length - 1] === element;
156
+ return parentChildren.length && parentChildren[parentChildren.length - 1] === element;
156
157
  case 'only-child':
157
- return parent.children.length === 1 && parent.children[0] === element;
158
+ return parentChildren.length === 1 && parentChildren[0] === element;
158
159
  case 'first-of-type':
159
- for (const child of parent.children) {
160
+ for (const child of parentChildren) {
160
161
  if (child.tagName === element.tagName) {
161
162
  return child === element;
162
163
  }
163
164
  }
164
165
  return false;
165
166
  case 'last-of-type':
166
- for (let i = parent.children.length - 1; i >= 0; i--) {
167
- const child = parent.children[i];
167
+ for (let i = parentChildren.length - 1; i >= 0; i--) {
168
+ const child = parentChildren[i];
168
169
  if (child.tagName === element.tagName) {
169
170
  return child === element;
170
171
  }
@@ -172,7 +173,7 @@ export default class SelectorItem {
172
173
  return false;
173
174
  case 'only-of-type':
174
175
  let isFound = false;
175
- for (const child of parent.children) {
176
+ for (const child of parentChildren) {
176
177
  if (child.tagName === element.tagName) {
177
178
  if (isFound || child !== element) {
178
179
  return false;
@@ -184,34 +185,34 @@ export default class SelectorItem {
184
185
  case 'checked':
185
186
  return element.tagName === 'INPUT' && (<IHTMLInputElement>element).checked;
186
187
  case 'empty':
187
- return !element.children.length;
188
+ return !(<Element>element)._children.length;
188
189
  case 'root':
189
190
  return element.tagName === 'HTML';
190
191
  case 'not':
191
192
  return !psuedo.selectorItem.match(element);
192
193
  case 'nth-child':
193
194
  const nthChildIndex = psuedo.selectorItem
194
- ? parent.children.filter((child) => psuedo.selectorItem.match(child)).indexOf(element)
195
- : parent.children.indexOf(element);
195
+ ? parentChildren.filter((child) => psuedo.selectorItem.match(child)).indexOf(element)
196
+ : parentChildren.indexOf(element);
196
197
  return nthChildIndex !== -1 && psuedo.nthFunction(nthChildIndex + 1);
197
198
  case 'nth-of-type':
198
199
  if (!element.parentNode) {
199
200
  return false;
200
201
  }
201
- const nthOfTypeIndex = parent.children
202
+ const nthOfTypeIndex = parentChildren
202
203
  .filter((child) => child.tagName === element.tagName)
203
204
  .indexOf(element);
204
205
  return nthOfTypeIndex !== -1 && psuedo.nthFunction(nthOfTypeIndex + 1);
205
206
  case 'nth-last-child':
206
207
  const nthLastChildIndex = psuedo.selectorItem
207
- ? parent.children
208
+ ? parentChildren
208
209
  .filter((child) => psuedo.selectorItem.match(child))
209
210
  .reverse()
210
211
  .indexOf(element)
211
- : parent.children.reverse().indexOf(element);
212
+ : parentChildren.reverse().indexOf(element);
212
213
  return nthLastChildIndex !== -1 && psuedo.nthFunction(nthLastChildIndex + 1);
213
214
  case 'nth-last-of-type':
214
- const nthLastOfTypeIndex = parent.children
215
+ const nthLastOfTypeIndex = parentChildren
215
216
  .filter((child) => child.tagName === element.tagName)
216
217
  .reverse()
217
218
  .indexOf(element);
@@ -1,4 +1,5 @@
1
1
  import INode from '../nodes/node/INode.js';
2
+ import Node from '../nodes/node/Node.js';
2
3
  import IDocument from '../nodes/document/IDocument.js';
3
4
  import IDocumentFragment from '../nodes/document-fragment/IDocumentFragment.js';
4
5
  import DOMRect from '../nodes/element/DOMRect.js';
@@ -309,7 +310,7 @@ export default class Range {
309
310
 
310
311
  const containedChildren = [];
311
312
 
312
- for (const node of commonAncestor.childNodes) {
313
+ for (const node of (<Node>commonAncestor)._childNodes) {
313
314
  if (RangeUtility.isContained(node, this)) {
314
315
  if (node.nodeType === NodeTypeEnum.documentTypeNode) {
315
316
  throw new DOMException(
@@ -462,7 +463,7 @@ export default class Range {
462
463
  }
463
464
 
464
465
  newNode = referenceNode.parentNode;
465
- newOffset = referenceNode.parentNode.childNodes.indexOf(referenceNode) + 1;
466
+ newOffset = (<Node>referenceNode.parentNode)._childNodes.indexOf(referenceNode) + 1;
466
467
  }
467
468
 
468
469
  if (
@@ -567,7 +568,7 @@ export default class Range {
567
568
 
568
569
  const containedChildren = [];
569
570
 
570
- for (const node of commonAncestor.childNodes) {
571
+ for (const node of (<Node>commonAncestor)._childNodes) {
571
572
  if (RangeUtility.isContained(node, this)) {
572
573
  if (node.nodeType === NodeTypeEnum.documentTypeNode) {
573
574
  throw new DOMException(
@@ -595,7 +596,7 @@ export default class Range {
595
596
  }
596
597
 
597
598
  newNode = referenceNode.parentNode;
598
- newOffset = referenceNode.parentNode.childNodes.indexOf(referenceNode) + 1;
599
+ newOffset = (<Node>referenceNode.parentNode)._childNodes.indexOf(referenceNode) + 1;
599
600
  }
600
601
 
601
602
  if (
@@ -741,7 +742,7 @@ export default class Range {
741
742
  let referenceNode =
742
743
  this._start.node.nodeType === NodeTypeEnum.textNode
743
744
  ? this._start.node
744
- : this._start.node.childNodes[this.startOffset] || null;
745
+ : (<Node>this._start.node)._childNodes[this.startOffset] || null;
745
746
  const parent = !referenceNode ? this._start.node : referenceNode.parentNode;
746
747
 
747
748
  if (this._start.node.nodeType === NodeTypeEnum.textNode) {
@@ -759,7 +760,7 @@ export default class Range {
759
760
 
760
761
  let newOffset = !referenceNode
761
762
  ? NodeUtility.getNodeLength(parent)
762
- : referenceNode.parentNode.childNodes.indexOf(referenceNode);
763
+ : (<Node>referenceNode.parentNode)._childNodes.indexOf(referenceNode);
763
764
  newOffset +=
764
765
  newNode.nodeType === NodeTypeEnum.documentFragmentNode
765
766
  ? NodeUtility.getNodeLength(newNode)
@@ -791,7 +792,7 @@ export default class Range {
791
792
  return true;
792
793
  }
793
794
 
794
- const offset = parent.childNodes.indexOf(node);
795
+ const offset = (<Node>parent)._childNodes.indexOf(node);
795
796
 
796
797
  return (
797
798
  RangeUtility.compareBoundaryPointsPosition(
@@ -819,7 +820,7 @@ export default class Range {
819
820
  );
820
821
  }
821
822
 
822
- const index = node.parentNode.childNodes.indexOf(node);
823
+ const index = (<Node>node.parentNode)._childNodes.indexOf(node);
823
824
 
824
825
  this._start.node = node.parentNode;
825
826
  this._start.offset = index;
@@ -914,7 +915,7 @@ export default class Range {
914
915
  DOMExceptionNameEnum.invalidNodeTypeError
915
916
  );
916
917
  }
917
- this.setEnd(node.parentNode, node.parentNode.childNodes.indexOf(node) + 1);
918
+ this.setEnd(node.parentNode, (<Node>node.parentNode)._childNodes.indexOf(node) + 1);
918
919
  }
919
920
 
920
921
  /**
@@ -930,7 +931,7 @@ export default class Range {
930
931
  DOMExceptionNameEnum.invalidNodeTypeError
931
932
  );
932
933
  }
933
- this.setEnd(node.parentNode, node.parentNode.childNodes.indexOf(node));
934
+ this.setEnd(node.parentNode, (<Node>node.parentNode)._childNodes.indexOf(node));
934
935
  }
935
936
 
936
937
  /**
@@ -946,7 +947,7 @@ export default class Range {
946
947
  DOMExceptionNameEnum.invalidNodeTypeError
947
948
  );
948
949
  }
949
- this.setStart(node.parentNode, node.parentNode.childNodes.indexOf(node) + 1);
950
+ this.setStart(node.parentNode, (<Node>node.parentNode)._childNodes.indexOf(node) + 1);
950
951
  }
951
952
 
952
953
  /**
@@ -962,7 +963,7 @@ export default class Range {
962
963
  DOMExceptionNameEnum.invalidNodeTypeError
963
964
  );
964
965
  }
965
- this.setStart(node.parentNode, node.parentNode.childNodes.indexOf(node));
966
+ this.setStart(node.parentNode, (<Node>node.parentNode)._childNodes.indexOf(node));
966
967
  }
967
968
 
968
969
  /**
@@ -2,6 +2,7 @@ import DOMException from '../exception/DOMException.js';
2
2
  import DOMExceptionNameEnum from '../exception/DOMExceptionNameEnum.js';
3
3
  import NodeTypeEnum from '../nodes/node/NodeTypeEnum.js';
4
4
  import INode from '../nodes/node/INode.js';
5
+ import Node from '../nodes/node/Node.js';
5
6
  import NodeUtility from '../nodes/node/NodeUtility.js';
6
7
  import Range from './Range.js';
7
8
  import IRangeBoundaryPoint from './IRangeBoundaryPoint.js';
@@ -49,7 +50,7 @@ export default class RangeUtility {
49
50
  child = child.parentNode;
50
51
  }
51
52
 
52
- if (child.parentNode.childNodes.indexOf(child) < pointA.offset) {
53
+ if ((<Node>child.parentNode)._childNodes.indexOf(child) < pointA.offset) {
53
54
  return 1;
54
55
  }
55
56
  }