@xmldom/xmldom 0.9.3 → 0.9.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
6
6
 
7
+ ## [0.9.5](https://github.com/xmldom/xmldom/compare/0.9.4...0.9.5)
8
+
9
+ ### Fixed
10
+
11
+ - fix: re-index childNodes on insertBefore [`#763`](https://github.com/xmldom/xmldom/issues/763) / [`#766`](https://github.com/xmldom/xmldom/pull/766)
12
+
13
+ Thank you,
14
+ [@mureinik](https://github.com/mureinik),
15
+ for your contributions.
16
+
17
+
18
+ ## [0.9.4](https://github.com/xmldom/xmldom/compare/0.9.3...0.9.4)
19
+
20
+ ### Fixed
21
+
22
+ - restore performance for large amount of child nodes [`#748`](https://github.com/xmldom/xmldom/issues/748) / [`#760`](https://github.com/xmldom/xmldom/pull/760)
23
+ - types: correct error handler level to `warning` (#759) [`#754`](https://github.com/xmldom/xmldom/issues/754) / [`#759`](https://github.com/xmldom/xmldom/pull/759)
24
+
25
+ ### Docs
26
+
27
+ - test: verify BOM handling [`#758`](https://github.com/xmldom/xmldom/pull/758)
28
+
29
+ Thank you,
30
+ [@luffynando](https://github.com/luffynando),
31
+ [@mattiasw](https://github.com/mattiasw),
32
+ [@JoinerDev](https://github.com/JoinerDev),
33
+ for your contributions.
34
+
35
+
7
36
  ## [0.9.3](https://github.com/xmldom/xmldom/compare/0.9.2...0.9.3)
8
37
 
9
38
  ### Fixed
package/index.d.ts CHANGED
@@ -1565,7 +1565,11 @@ declare module '@xmldom/xmldom' {
1565
1565
  }
1566
1566
 
1567
1567
  interface ErrorHandlerFunction {
1568
- (level: 'warn' | 'error' | 'fatalError', msg: string, context: any): void;
1568
+ (
1569
+ level: 'warning' | 'error' | 'fatalError',
1570
+ msg: string,
1571
+ context: any
1572
+ ): void;
1569
1573
  }
1570
1574
 
1571
1575
  /**
package/lib/dom.js CHANGED
@@ -1623,37 +1623,39 @@ function _onRemoveAttribute(doc, el, newAttr, remove) {
1623
1623
  }
1624
1624
 
1625
1625
  /**
1626
- * Updates `el.childNodes`, adjusting the indexed items and its `length`.
1627
- * If `newChild` is provided, it will be appended to the childNodes list.
1628
- * Otherwise, it's assumed that an item has been removed,
1629
- * and `el.firstNode` and its `.nextSibling` are used to iterate over the current list of child
1630
- * nodes, effectively reindexing them.
1626
+ * Updates `parent.childNodes`, adjusting the indexed items and its `length`.
1627
+ * If `newChild` is provided and has no nextSibling, it will be appended.
1628
+ * Otherwise, it's assumed that an item has been removed or inserted,
1629
+ * and `parent.firstNode` and its `.nextSibling` to re-indexing all child nodes of `parent`.
1631
1630
  *
1632
1631
  * @param {Document} doc
1633
1632
  * The parent document of `el`.
1634
- * @param {Node} el
1633
+ * @param {Node} parent
1635
1634
  * The parent node whose childNodes list needs to be updated.
1636
1635
  * @param {Node} [newChild]
1637
1636
  * The new child node to be appended. If not provided, the function assumes a node has been
1638
1637
  * removed.
1639
1638
  * @private
1640
1639
  */
1641
- function _onUpdateChild(doc, el, newChild) {
1640
+ function _onUpdateChild(doc, parent, newChild) {
1642
1641
  if (doc && doc._inc) {
1643
1642
  doc._inc++;
1644
- //update childNodes
1645
- var cs = el.childNodes;
1646
- if (newChild) {
1647
- cs[cs.length++] = newChild;
1643
+ var childNodes = parent.childNodes;
1644
+ // assumes nextSibling and previousSibling were already configured upfront
1645
+ if (newChild && !newChild.nextSibling) {
1646
+ // if an item has been appended, we only need to update the last index and the length
1647
+ childNodes[childNodes.length++] = newChild;
1648
1648
  } else {
1649
- var child = el.firstChild;
1649
+ // otherwise we need to reindex all items,
1650
+ // which can take a while when processing nodes with a lot of children
1651
+ var child = parent.firstChild;
1650
1652
  var i = 0;
1651
1653
  while (child) {
1652
- cs[i++] = child;
1654
+ childNodes[i++] = child;
1653
1655
  child = child.nextSibling;
1654
1656
  }
1655
- cs.length = i;
1656
- delete cs[cs.length];
1657
+ childNodes.length = i;
1658
+ delete childNodes[childNodes.length];
1657
1659
  }
1658
1660
  }
1659
1661
  }
@@ -2054,7 +2056,7 @@ function _insertBefore(parent, node, child, _inDocumentAssertion) {
2054
2056
  do {
2055
2057
  newFirst.parentNode = parent;
2056
2058
  } while (newFirst !== newLast && (newFirst = newFirst.nextSibling));
2057
- _onUpdateChild(parent.ownerDocument || parent, parent);
2059
+ _onUpdateChild(parent.ownerDocument || parent, parent, node);
2058
2060
  if (node.nodeType == DOCUMENT_FRAGMENT_NODE) {
2059
2061
  node.firstChild = node.lastChild = null;
2060
2062
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xmldom/xmldom",
3
- "version": "0.9.3",
3
+ "version": "0.9.5",
4
4
  "description": "A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.",
5
5
  "keywords": [
6
6
  "w3c",
@@ -51,11 +51,11 @@
51
51
  "eslint-config-prettier": "9.1.0",
52
52
  "eslint-plugin-anti-trojan-source": "1.1.1",
53
53
  "eslint-plugin-es5": "1.5.0",
54
- "eslint-plugin-n": "17.10.3",
54
+ "eslint-plugin-n": "17.11.1",
55
55
  "eslint-plugin-prettier": "5.2.1",
56
56
  "get-stream": "6.0.1",
57
57
  "jest": "29.7.0",
58
- "nodemon": "3.1.5",
58
+ "nodemon": "3.1.7",
59
59
  "np": "8.0.4",
60
60
  "prettier": "3.3.3",
61
61
  "rxjs": "7.8.1",