happy-dom 17.1.2 → 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.
Files changed (99) hide show
  1. package/cjs/PropertySymbol.cjs +4 -4
  2. package/cjs/PropertySymbol.cjs.map +1 -1
  3. package/cjs/PropertySymbol.d.ts +2 -2
  4. package/cjs/PropertySymbol.d.ts.map +1 -1
  5. package/cjs/dom/DOMStringMap.cjs +1 -1
  6. package/cjs/dom/DOMStringMap.cjs.map +1 -1
  7. package/cjs/exception/DOMExceptionNameEnum.cjs +1 -0
  8. package/cjs/exception/DOMExceptionNameEnum.cjs.map +1 -1
  9. package/cjs/exception/DOMExceptionNameEnum.d.ts +2 -1
  10. package/cjs/exception/DOMExceptionNameEnum.d.ts.map +1 -1
  11. package/cjs/html-serializer/HTMLSerializer.cjs +5 -5
  12. package/cjs/html-serializer/HTMLSerializer.cjs.map +1 -1
  13. package/cjs/nodes/document/Document.cjs +12 -1
  14. package/cjs/nodes/document/Document.cjs.map +1 -1
  15. package/cjs/nodes/document/Document.d.ts.map +1 -1
  16. package/cjs/nodes/element/Element.cjs +9 -5
  17. package/cjs/nodes/element/Element.cjs.map +1 -1
  18. package/cjs/nodes/element/Element.d.ts.map +1 -1
  19. package/cjs/nodes/element/NamedNodeMap.cjs +34 -26
  20. package/cjs/nodes/element/NamedNodeMap.cjs.map +1 -1
  21. package/cjs/nodes/element/NamedNodeMap.d.ts +3 -2
  22. package/cjs/nodes/element/NamedNodeMap.d.ts.map +1 -1
  23. package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs +22 -16
  24. package/cjs/nodes/element/NamedNodeMapProxyFactory.cjs.map +1 -1
  25. package/cjs/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
  26. package/cjs/nodes/html-element/HTMLElement.cjs +10 -7
  27. package/cjs/nodes/html-element/HTMLElement.cjs.map +1 -1
  28. package/cjs/nodes/html-element/HTMLElement.d.ts.map +1 -1
  29. package/cjs/nodes/node/Node.cjs +3 -3
  30. package/cjs/nodes/node/Node.cjs.map +1 -1
  31. package/cjs/nodes/node/NodeUtility.cjs +7 -8
  32. package/cjs/nodes/node/NodeUtility.cjs.map +1 -1
  33. package/cjs/nodes/node/NodeUtility.d.ts.map +1 -1
  34. package/cjs/tree-walker/TreeWalker.cjs +160 -70
  35. package/cjs/tree-walker/TreeWalker.cjs.map +1 -1
  36. package/cjs/tree-walker/TreeWalker.d.ts +18 -14
  37. package/cjs/tree-walker/TreeWalker.d.ts.map +1 -1
  38. package/cjs/xml-parser/XMLParser.cjs +2 -2
  39. package/cjs/xml-parser/XMLParser.cjs.map +1 -1
  40. package/cjs/xml-serializer/XMLSerializer.cjs +5 -8
  41. package/cjs/xml-serializer/XMLSerializer.cjs.map +1 -1
  42. package/cjs/xml-serializer/XMLSerializer.d.ts.map +1 -1
  43. package/lib/PropertySymbol.d.ts +2 -2
  44. package/lib/PropertySymbol.d.ts.map +1 -1
  45. package/lib/PropertySymbol.js +2 -2
  46. package/lib/PropertySymbol.js.map +1 -1
  47. package/lib/dom/DOMStringMap.js +1 -1
  48. package/lib/dom/DOMStringMap.js.map +1 -1
  49. package/lib/exception/DOMExceptionNameEnum.d.ts +2 -1
  50. package/lib/exception/DOMExceptionNameEnum.d.ts.map +1 -1
  51. package/lib/exception/DOMExceptionNameEnum.js +1 -0
  52. package/lib/exception/DOMExceptionNameEnum.js.map +1 -1
  53. package/lib/html-serializer/HTMLSerializer.js +5 -5
  54. package/lib/html-serializer/HTMLSerializer.js.map +1 -1
  55. package/lib/nodes/document/Document.d.ts.map +1 -1
  56. package/lib/nodes/document/Document.js +12 -1
  57. package/lib/nodes/document/Document.js.map +1 -1
  58. package/lib/nodes/element/Element.d.ts.map +1 -1
  59. package/lib/nodes/element/Element.js +9 -5
  60. package/lib/nodes/element/Element.js.map +1 -1
  61. package/lib/nodes/element/NamedNodeMap.d.ts +3 -2
  62. package/lib/nodes/element/NamedNodeMap.d.ts.map +1 -1
  63. package/lib/nodes/element/NamedNodeMap.js +34 -26
  64. package/lib/nodes/element/NamedNodeMap.js.map +1 -1
  65. package/lib/nodes/element/NamedNodeMapProxyFactory.d.ts.map +1 -1
  66. package/lib/nodes/element/NamedNodeMapProxyFactory.js +22 -16
  67. package/lib/nodes/element/NamedNodeMapProxyFactory.js.map +1 -1
  68. package/lib/nodes/html-element/HTMLElement.d.ts.map +1 -1
  69. package/lib/nodes/html-element/HTMLElement.js +10 -7
  70. package/lib/nodes/html-element/HTMLElement.js.map +1 -1
  71. package/lib/nodes/node/Node.js +3 -3
  72. package/lib/nodes/node/Node.js.map +1 -1
  73. package/lib/nodes/node/NodeUtility.d.ts.map +1 -1
  74. package/lib/nodes/node/NodeUtility.js +7 -8
  75. package/lib/nodes/node/NodeUtility.js.map +1 -1
  76. package/lib/tree-walker/TreeWalker.d.ts +18 -14
  77. package/lib/tree-walker/TreeWalker.d.ts.map +1 -1
  78. package/lib/tree-walker/TreeWalker.js +160 -70
  79. package/lib/tree-walker/TreeWalker.js.map +1 -1
  80. package/lib/xml-parser/XMLParser.js +2 -2
  81. package/lib/xml-parser/XMLParser.js.map +1 -1
  82. package/lib/xml-serializer/XMLSerializer.d.ts.map +1 -1
  83. package/lib/xml-serializer/XMLSerializer.js +5 -8
  84. package/lib/xml-serializer/XMLSerializer.js.map +1 -1
  85. package/package.json +1 -1
  86. package/src/PropertySymbol.ts +2 -2
  87. package/src/dom/DOMStringMap.ts +1 -1
  88. package/src/exception/DOMExceptionNameEnum.ts +2 -1
  89. package/src/html-serializer/HTMLSerializer.ts +5 -5
  90. package/src/nodes/document/Document.ts +22 -1
  91. package/src/nodes/element/Element.ts +20 -5
  92. package/src/nodes/element/NamedNodeMap.ts +42 -27
  93. package/src/nodes/element/NamedNodeMapProxyFactory.ts +22 -17
  94. package/src/nodes/html-element/HTMLElement.ts +11 -10
  95. package/src/nodes/node/Node.ts +5 -5
  96. package/src/nodes/node/NodeUtility.ts +7 -8
  97. package/src/tree-walker/TreeWalker.ts +195 -98
  98. package/src/xml-parser/XMLParser.ts +2 -2
  99. package/src/xml-serializer/XMLSerializer.ts +9 -12
@@ -50,6 +50,7 @@ import SVGElementConfig from '../../config/SVGElementConfig.js';
50
50
  import StringUtility from '../../utilities/StringUtility.js';
51
51
  import HTMLParser from '../../html-parser/HTMLParser.js';
52
52
  import PreloadEntry from '../../fetch/preload/PreloadEntry.js';
53
+ import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum.js';
53
54
 
54
55
  const PROCESSING_INSTRUCTION_TARGET_REGEXP = /^[a-z][a-z0-9-]+$/;
55
56
 
@@ -1222,7 +1223,17 @@ export default class Document extends Node {
1222
1223
  * @returns Attribute.
1223
1224
  */
1224
1225
  public createAttribute(qualifiedName: string): Attr {
1225
- return this.createAttributeNS(null, StringUtility.asciiLowerCase(qualifiedName));
1226
+ // We should use the NodeFactory and not the class constructor, so that owner document will be this document
1227
+ const attribute = NodeFactory.createNode(this, this[PropertySymbol.window].Attr);
1228
+
1229
+ const name = StringUtility.asciiLowerCase(qualifiedName);
1230
+ const parts = name.split(':');
1231
+
1232
+ attribute[PropertySymbol.name] = name;
1233
+ attribute[PropertySymbol.localName] = parts[1] ?? name;
1234
+ attribute[PropertySymbol.prefix] = parts[1] ? parts[0] : null;
1235
+
1236
+ return attribute;
1226
1237
  }
1227
1238
 
1228
1239
  /**
@@ -1237,11 +1248,21 @@ export default class Document extends Node {
1237
1248
  const attribute = NodeFactory.createNode(this, this[PropertySymbol.window].Attr);
1238
1249
 
1239
1250
  const parts = qualifiedName.split(':');
1251
+
1240
1252
  attribute[PropertySymbol.namespaceURI] = namespaceURI;
1241
1253
  attribute[PropertySymbol.name] = qualifiedName;
1242
1254
  attribute[PropertySymbol.localName] = parts[1] ?? qualifiedName;
1243
1255
  attribute[PropertySymbol.prefix] = parts[1] ? parts[0] : null;
1244
1256
 
1257
+ if (!namespaceURI && attribute[PropertySymbol.prefix]) {
1258
+ throw new this[PropertySymbol.window].DOMException(
1259
+ `Failed to execute 'createAttributeNS' on 'Document': The namespace URI provided ('${
1260
+ namespaceURI || ''
1261
+ }') is not valid for the qualified name provided ('${qualifiedName}').`,
1262
+ DOMExceptionNameEnum.namespaceError
1263
+ );
1264
+ }
1265
+
1245
1266
  return attribute;
1246
1267
  }
1247
1268
 
@@ -33,6 +33,7 @@ import HTMLSerializer from '../../html-serializer/HTMLSerializer.js';
33
33
  import HTMLParser from '../../html-parser/HTMLParser.js';
34
34
  import IScrollToOptions from '../../window/IScrollToOptions.js';
35
35
  import { AttributeUtility } from '../../utilities/AttributeUtility.js';
36
+ import DOMExceptionNameEnum from '../../exception/DOMExceptionNameEnum.js';
36
37
 
37
38
  type InsertAdjacentPosition = 'beforebegin' | 'afterbegin' | 'beforeend' | 'afterend';
38
39
 
@@ -545,9 +546,17 @@ export default class Element
545
546
  clone[PropertySymbol.shadowRoot][PropertySymbol.host] = clone;
546
547
  }
547
548
 
548
- for (const item of this[PropertySymbol.attributes][PropertySymbol.namespaceItems].values()) {
549
- clone[PropertySymbol.attributes].setNamedItem(item.cloneNode());
550
- }
549
+ clone[PropertySymbol.attributes][PropertySymbol.itemsByNamespaceURI] = new Map(
550
+ this[PropertySymbol.attributes][PropertySymbol.itemsByNamespaceURI]
551
+ );
552
+
553
+ clone[PropertySymbol.attributes][PropertySymbol.itemsByName] = new Map(
554
+ this[PropertySymbol.attributes][PropertySymbol.itemsByName]
555
+ );
556
+
557
+ clone[PropertySymbol.attributes][PropertySymbol.items] = new Map(
558
+ this[PropertySymbol.attributes][PropertySymbol.items]
559
+ );
551
560
 
552
561
  return <Element>clone;
553
562
  }
@@ -704,6 +713,12 @@ export default class Element
704
713
  */
705
714
  public setAttributeNS(namespaceURI: string, name: string, value: string): void {
706
715
  const attribute = this[PropertySymbol.ownerDocument].createAttributeNS(namespaceURI, name);
716
+ if (!namespaceURI && attribute[PropertySymbol.prefix]) {
717
+ throw new this[PropertySymbol.window].DOMException(
718
+ `Failed to execute 'setAttributeNS' on 'Element': '' is an invalid namespace for attributes.`,
719
+ DOMExceptionNameEnum.namespaceError
720
+ );
721
+ }
707
722
  attribute[PropertySymbol.value] = String(value);
708
723
  this[PropertySymbol.attributes].setNamedItemNS(attribute);
709
724
  }
@@ -715,7 +730,7 @@ export default class Element
715
730
  */
716
731
  public getAttributeNames(): string[] {
717
732
  const names = [];
718
- for (const item of this[PropertySymbol.attributes][PropertySymbol.namespaceItems].values()) {
733
+ for (const item of this[PropertySymbol.attributes][PropertySymbol.items].values()) {
719
734
  names.push(item[PropertySymbol.name]);
720
735
  }
721
736
  return names;
@@ -799,7 +814,7 @@ export default class Element
799
814
  * @returns "true" if the element has attributes.
800
815
  */
801
816
  public hasAttributes(): boolean {
802
- return this[PropertySymbol.attributes][PropertySymbol.namespaceItems].size > 0;
817
+ return this[PropertySymbol.attributes][PropertySymbol.items].size > 0;
803
818
  }
804
819
 
805
820
  /**
@@ -14,11 +14,14 @@ import StringUtility from '../../utilities/StringUtility.js';
14
14
  export default class NamedNodeMap {
15
15
  [index: number]: Attr;
16
16
 
17
- // All items with the namespaceURI as prefix
18
- public [PropertySymbol.namespaceItems]: Map<string, Attr> = new Map();
17
+ // Items by attribute namespaceURI
18
+ public [PropertySymbol.itemsByNamespaceURI]: Map<string, Attr> = new Map();
19
19
 
20
- // Items without namespaceURI as prefix, where the HTML namespace is the default namespace
21
- public [PropertySymbol.namedItems]: Map<string, Attr[]> = new Map();
20
+ // Items by attribute name
21
+ public [PropertySymbol.itemsByName]: Map<string, Attr[]> = new Map();
22
+
23
+ // All items
24
+ public [PropertySymbol.items]: Map<string, Attr> = new Map();
22
25
 
23
26
  public declare [PropertySymbol.ownerElement]: Element;
24
27
 
@@ -37,7 +40,7 @@ export default class NamedNodeMap {
37
40
  * @returns Length.
38
41
  */
39
42
  public get length(): number {
40
- return this[PropertySymbol.namespaceItems].size;
43
+ return this[PropertySymbol.items].size;
41
44
  }
42
45
 
43
46
  /**
@@ -64,7 +67,7 @@ export default class NamedNodeMap {
64
67
  * @returns Iterator.
65
68
  */
66
69
  public [Symbol.iterator](): IterableIterator<Attr> {
67
- return this[PropertySymbol.namespaceItems].values();
70
+ return this[PropertySymbol.items].values();
68
71
  }
69
72
 
70
73
  /**
@@ -73,7 +76,7 @@ export default class NamedNodeMap {
73
76
  * @param index Index.
74
77
  */
75
78
  public item(index: number): Attr | null {
76
- const items = Array.from(this[PropertySymbol.namespaceItems].values());
79
+ const items = Array.from(this[PropertySymbol.items].values());
77
80
  return index >= 0 && items[index] ? items[index] : null;
78
81
  }
79
82
 
@@ -91,9 +94,9 @@ export default class NamedNodeMap {
91
94
  PropertySymbol.contentType
92
95
  ] === 'text/html'
93
96
  ) {
94
- return this[PropertySymbol.namedItems].get(StringUtility.asciiLowerCase(name))?.[0] || null;
97
+ return this[PropertySymbol.itemsByName].get(StringUtility.asciiLowerCase(name))?.[0] || null;
95
98
  }
96
- return this[PropertySymbol.namedItems].get(name)?.[0] || null;
99
+ return this[PropertySymbol.itemsByName].get(name)?.[0] || null;
97
100
  }
98
101
 
99
102
  /**
@@ -104,11 +107,17 @@ export default class NamedNodeMap {
104
107
  * @returns Item.
105
108
  */
106
109
  public getNamedItemNS(namespace: string, localName: string): Attr | null {
107
- if (namespace === '') {
108
- namespace = null;
110
+ const item = this[PropertySymbol.itemsByNamespaceURI].get(`${namespace || ''}:${localName}`);
111
+
112
+ // It seems like an item cant have a prefix without a namespaceURI
113
+ // E.g. element.setAttribute('ns1:key', 'value1');
114
+ // expect(element.attributes.getNamedItemNS(null, 'key')).toBeNull();
115
+
116
+ if (item && (!item[PropertySymbol.prefix] || item[PropertySymbol.namespaceURI])) {
117
+ return item;
109
118
  }
110
119
 
111
- return this[PropertySymbol.namespaceItems].get(`${namespace || ''}:${localName}`) || null;
120
+ return null;
112
121
  }
113
122
 
114
123
  /**
@@ -199,26 +208,29 @@ export default class NamedNodeMap {
199
208
  const replacedItem =
200
209
  this.getNamedItemNS(item[PropertySymbol.namespaceURI], item[PropertySymbol.localName]) ||
201
210
  null;
202
-
203
- const namedItems = this[PropertySymbol.namedItems].get(item[PropertySymbol.name]);
211
+ const itemsByName = this[PropertySymbol.itemsByName].get(item[PropertySymbol.name]);
204
212
 
205
213
  if (replacedItem === item) {
206
214
  return item;
207
215
  }
208
216
 
209
- this[PropertySymbol.namespaceItems].set(
217
+ this[PropertySymbol.itemsByNamespaceURI].set(
210
218
  `${item[PropertySymbol.namespaceURI] || ''}:${item[PropertySymbol.localName]}`,
211
219
  item
212
220
  );
221
+ this[PropertySymbol.items].set(
222
+ `${item[PropertySymbol.namespaceURI] || ''}:${item[PropertySymbol.name]}`,
223
+ item
224
+ );
213
225
 
214
- if (!namedItems?.length) {
215
- this[PropertySymbol.namedItems].set(item[PropertySymbol.name], [item]);
226
+ if (!itemsByName?.length) {
227
+ this[PropertySymbol.itemsByName].set(item[PropertySymbol.name], [item]);
216
228
  } else {
217
- const index = namedItems.indexOf(replacedItem);
229
+ const index = itemsByName.indexOf(replacedItem);
218
230
  if (index !== -1) {
219
- namedItems.splice(index, 1);
231
+ itemsByName.splice(index, 1);
220
232
  }
221
- namedItems.push(item);
233
+ itemsByName.push(item);
222
234
  }
223
235
 
224
236
  if (!ignoreListeners) {
@@ -237,19 +249,22 @@ export default class NamedNodeMap {
237
249
  public [PropertySymbol.removeNamedItem](item: Attr, ignoreListeners = false): void {
238
250
  item[PropertySymbol.ownerElement] = null;
239
251
 
240
- this[PropertySymbol.namespaceItems].delete(
252
+ this[PropertySymbol.itemsByNamespaceURI].delete(
241
253
  `${item[PropertySymbol.namespaceURI] || ''}:${item[PropertySymbol.localName]}`
242
254
  );
255
+ this[PropertySymbol.items].delete(
256
+ `${item[PropertySymbol.namespaceURI] || ''}:${item[PropertySymbol.name]}`
257
+ );
243
258
 
244
- const namedItems = this[PropertySymbol.namedItems].get(item[PropertySymbol.name]);
259
+ const itemsByName = this[PropertySymbol.itemsByName].get(item[PropertySymbol.name]);
245
260
 
246
- if (namedItems?.length) {
247
- const index = namedItems.indexOf(item);
261
+ if (itemsByName?.length) {
262
+ const index = itemsByName.indexOf(item);
248
263
  if (index !== -1) {
249
- namedItems.splice(index, 1);
264
+ itemsByName.splice(index, 1);
250
265
  }
251
- if (!namedItems.length) {
252
- this[PropertySymbol.namedItems].delete(item[PropertySymbol.name]);
266
+ if (!itemsByName.length) {
267
+ this[PropertySymbol.itemsByName].delete(item[PropertySymbol.name]);
253
268
  }
254
269
  }
255
270
 
@@ -21,7 +21,7 @@ export default class NamedNodeMapProxyFactory {
21
21
  return new Proxy<NamedNodeMap>(namedNodeMap, {
22
22
  get: (target, property) => {
23
23
  if (property === 'length') {
24
- return namedNodeMap[PropertySymbol.namedItems].size;
24
+ return namedNodeMap[PropertySymbol.items].size;
25
25
  }
26
26
  if (property in target || typeof property === 'symbol') {
27
27
  methodBinder.bind(property);
@@ -29,7 +29,7 @@ export default class NamedNodeMapProxyFactory {
29
29
  }
30
30
  const index = Number(property);
31
31
  if (!isNaN(index)) {
32
- return Array.from(namedNodeMap[PropertySymbol.namedItems].values())[index]?.[0];
32
+ return target.item(index);
33
33
  }
34
34
  return target.getNamedItem(<string>property) || undefined;
35
35
  },
@@ -57,8 +57,8 @@ export default class NamedNodeMapProxyFactory {
57
57
  return true;
58
58
  },
59
59
  ownKeys(): string[] {
60
- const keys = Array.from(namedNodeMap[PropertySymbol.namedItems].keys());
61
- for (let i = 0, max = namedNodeMap[PropertySymbol.namedItems].size; i < max; i++) {
60
+ const keys = Array.from(namedNodeMap[PropertySymbol.items].keys());
61
+ for (let i = 0, max = namedNodeMap[PropertySymbol.items].size; i < max; i++) {
62
62
  keys.push(String(i));
63
63
  }
64
64
  return keys;
@@ -68,13 +68,13 @@ export default class NamedNodeMapProxyFactory {
68
68
  return false;
69
69
  }
70
70
 
71
- if (property in target || namedNodeMap[PropertySymbol.namedItems].has(property)) {
71
+ if (property in target || namedNodeMap[PropertySymbol.items].has(property)) {
72
72
  return true;
73
73
  }
74
74
 
75
75
  const index = Number(property);
76
76
 
77
- if (!isNaN(index) && index >= 0 && index < namedNodeMap[PropertySymbol.namedItems].size) {
77
+ if (!isNaN(index) && index >= 0 && index < namedNodeMap[PropertySymbol.items].size) {
78
78
  return true;
79
79
  }
80
80
 
@@ -96,21 +96,26 @@ export default class NamedNodeMapProxyFactory {
96
96
  }
97
97
 
98
98
  const index = Number(property);
99
-
100
- if (!isNaN(index) && index >= 0 && index < namedNodeMap[PropertySymbol.namedItems].size) {
101
- return {
102
- value: Array.from(namedNodeMap[PropertySymbol.namedItems].values())[index][0],
103
- writable: false,
104
- enumerable: true,
105
- configurable: true
106
- };
99
+ if (!isNaN(index)) {
100
+ if (index >= 0) {
101
+ const itemByIndex = target.item(index);
102
+ if (itemByIndex) {
103
+ return {
104
+ value: itemByIndex,
105
+ writable: false,
106
+ enumerable: true,
107
+ configurable: true
108
+ };
109
+ }
110
+ }
111
+ return;
107
112
  }
108
113
 
109
- const namedItems = namedNodeMap[PropertySymbol.namedItems].get(<string>property);
114
+ const items = namedNodeMap[PropertySymbol.items].get(<string>property);
110
115
 
111
- if (namedItems) {
116
+ if (items) {
112
117
  return {
113
- value: namedItems[0],
118
+ value: items,
114
119
  writable: false,
115
120
  enumerable: true,
116
121
  configurable: true
@@ -649,14 +649,14 @@ export default class HTMLElement extends Element {
649
649
  newElement[PropertySymbol.isValue] = this[PropertySymbol.isValue];
650
650
  newElement[PropertySymbol.cache] = this[PropertySymbol.cache];
651
651
  newElement[PropertySymbol.affectsCache] = this[PropertySymbol.affectsCache];
652
- newElement[PropertySymbol.attributes][PropertySymbol.namedItems] =
653
- this[PropertySymbol.attributes][PropertySymbol.namedItems];
654
- newElement[PropertySymbol.attributes][PropertySymbol.namespaceItems] =
655
- this[PropertySymbol.attributes][PropertySymbol.namespaceItems];
656
-
657
- for (const attr of newElement[PropertySymbol.attributes][
658
- PropertySymbol.namespaceItems
659
- ].values()) {
652
+ newElement[PropertySymbol.attributes][PropertySymbol.itemsByNamespaceURI] =
653
+ this[PropertySymbol.attributes][PropertySymbol.itemsByNamespaceURI];
654
+ newElement[PropertySymbol.attributes][PropertySymbol.itemsByName] =
655
+ this[PropertySymbol.attributes][PropertySymbol.itemsByName];
656
+ newElement[PropertySymbol.attributes][PropertySymbol.items] =
657
+ this[PropertySymbol.attributes][PropertySymbol.items];
658
+
659
+ for (const attr of newElement[PropertySymbol.attributes][PropertySymbol.items].values()) {
660
660
  attr[PropertySymbol.ownerElement] = newElement;
661
661
  }
662
662
 
@@ -677,8 +677,9 @@ export default class HTMLElement extends Element {
677
677
  this[PropertySymbol.isValue] = null;
678
678
  this[PropertySymbol.cache] = newCache;
679
679
  this[PropertySymbol.affectsCache] = [];
680
- this[PropertySymbol.attributes][PropertySymbol.namedItems] = new Map();
681
- this[PropertySymbol.attributes][PropertySymbol.namespaceItems] = new Map();
680
+ this[PropertySymbol.attributes][PropertySymbol.itemsByNamespaceURI] = new Map();
681
+ this[PropertySymbol.attributes][PropertySymbol.itemsByName] = new Map();
682
+ this[PropertySymbol.attributes][PropertySymbol.items] = new Map();
682
683
 
683
684
  for (const node of newElement[PropertySymbol.nodeArray]) {
684
685
  node[PropertySymbol.parentNode] = newElement;
@@ -1102,13 +1102,13 @@ export default class Node extends EventTarget {
1102
1102
  /**
1103
1103
  * 5.2.1. For each attr in node2’s attribute list:
1104
1104
  */
1105
- for (const attributes of Array.from(
1106
- (<Element>node2)[PropertySymbol.attributes][PropertySymbol.namedItems].values()
1107
- )) {
1105
+ for (const attribute of (<Element>node2)[PropertySymbol.attributes][
1106
+ PropertySymbol.items
1107
+ ].values()) {
1108
1108
  /**
1109
1109
  * 5.2.1.1. If attr equals attr1, then return the result of adding DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC and DOCUMENT_POSITION_PRECEDING.
1110
1110
  */
1111
- if (NodeUtility.isEqualNode(attributes[0], attr1)) {
1111
+ if (NodeUtility.isEqualNode(attribute, attr1)) {
1112
1112
  return (
1113
1113
  Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_PRECEDING
1114
1114
  );
@@ -1117,7 +1117,7 @@ export default class Node extends EventTarget {
1117
1117
  /**
1118
1118
  * 5.2.1.2. If attr equals attr2, then return the result of adding DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC and DOCUMENT_POSITION_FOLLOWING.
1119
1119
  */
1120
- if (NodeUtility.isEqualNode(attributes[0], attr2)) {
1120
+ if (NodeUtility.isEqualNode(attribute, attr2)) {
1121
1121
  return (
1122
1122
  Node.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC | Node.DOCUMENT_POSITION_FOLLOWING
1123
1123
  );
@@ -200,19 +200,18 @@ export default class NodeUtility {
200
200
  */
201
201
  public static attributeListsEqual(elementA: Element, elementB: Element): boolean {
202
202
  const attributesA = Array.from(
203
- elementA[PropertySymbol.attributes][PropertySymbol.namedItems].values()
203
+ elementA[PropertySymbol.attributes][PropertySymbol.items].values()
204
204
  );
205
205
  const attributesB = Array.from(
206
- elementB[PropertySymbol.attributes][PropertySymbol.namedItems].values()
206
+ elementB[PropertySymbol.attributes][PropertySymbol.items].values()
207
207
  );
208
208
  for (const attributeA of attributesA) {
209
209
  let found = false;
210
210
  for (const attributeB of attributesB) {
211
211
  if (
212
- attributeA[0][PropertySymbol.namespaceURI] ===
213
- attributeB[0][PropertySymbol.namespaceURI] &&
214
- attributeA[0].localName === attributeB[0].localName &&
215
- attributeA[0][PropertySymbol.value] === attributeB[0][PropertySymbol.value]
212
+ attributeA[PropertySymbol.namespaceURI] === attributeB[PropertySymbol.namespaceURI] &&
213
+ attributeA.localName === attributeB.localName &&
214
+ attributeA[PropertySymbol.value] === attributeB[PropertySymbol.value]
216
215
  ) {
217
216
  found = true;
218
217
  break;
@@ -258,8 +257,8 @@ export default class NodeUtility {
258
257
  elementA[PropertySymbol.namespaceURI] !== elementB[PropertySymbol.namespaceURI] ||
259
258
  elementA[PropertySymbol.prefix] !== elementB[PropertySymbol.prefix] ||
260
259
  elementA[PropertySymbol.localName] !== elementB[PropertySymbol.localName] ||
261
- elementA[PropertySymbol.attributes][PropertySymbol.namespaceItems].size !==
262
- elementB[PropertySymbol.attributes][PropertySymbol.namespaceItems].size
260
+ elementA[PropertySymbol.attributes][PropertySymbol.items].size !==
261
+ elementB[PropertySymbol.attributes][PropertySymbol.items].size
263
262
  ) {
264
263
  return false;
265
264
  }