html-validate 8.25.0 → 8.25.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.
package/dist/es/core.js CHANGED
@@ -1743,7 +1743,31 @@ class DOMNode {
1743
1743
  return text;
1744
1744
  }
1745
1745
  append(node) {
1746
+ const oldParent = node._setParent(this);
1747
+ if (oldParent && this.isSameNode(oldParent)) {
1748
+ return;
1749
+ }
1746
1750
  this.childNodes.push(node);
1751
+ if (oldParent) {
1752
+ oldParent._removeChild(node);
1753
+ }
1754
+ }
1755
+ /**
1756
+ * Insert a node before a reference node.
1757
+ *
1758
+ * @internal
1759
+ */
1760
+ insertBefore(node, reference) {
1761
+ const index = reference ? this.childNodes.findIndex((it) => it.isSameNode(reference)) : -1;
1762
+ if (index >= 0) {
1763
+ this.childNodes.splice(index, 0, node);
1764
+ } else {
1765
+ this.childNodes.push(node);
1766
+ }
1767
+ const oldParent = node._setParent(this);
1768
+ if (oldParent) {
1769
+ oldParent._removeChild(node);
1770
+ }
1747
1771
  }
1748
1772
  isRootElement() {
1749
1773
  return this.nodeType === NodeType.DOCUMENT_NODE;
@@ -1770,6 +1794,14 @@ class DOMNode {
1770
1794
  get lastChild() {
1771
1795
  return this.childNodes[this.childNodes.length - 1] || null;
1772
1796
  }
1797
+ /**
1798
+ * @internal
1799
+ */
1800
+ removeChild(node) {
1801
+ this._removeChild(node);
1802
+ node._setParent(null);
1803
+ return node;
1804
+ }
1773
1805
  /**
1774
1806
  * Block a rule for this node.
1775
1807
  *
@@ -1844,6 +1876,22 @@ class DOMNode {
1844
1876
  generateSelector() {
1845
1877
  return null;
1846
1878
  }
1879
+ /**
1880
+ * @internal
1881
+ *
1882
+ * @returns Old parent, if set.
1883
+ */
1884
+ _setParent(_node) {
1885
+ return null;
1886
+ }
1887
+ _removeChild(node) {
1888
+ const index = this.childNodes.findIndex((it) => it.isSameNode(node));
1889
+ if (index >= 0) {
1890
+ this.childNodes.splice(index, 1);
1891
+ } else {
1892
+ throw new Error("DOMException: _removeChild(..) could not find child to remove");
1893
+ }
1894
+ }
1847
1895
  }
1848
1896
 
1849
1897
  function parse(text, baseLocation) {
@@ -2363,7 +2411,7 @@ class HtmlElement extends DOMNode {
2363
2411
  throw new Error(`The tag name provided ("${tagName}") is not a valid name`);
2364
2412
  }
2365
2413
  this.tagName = tagName ?? "#document";
2366
- this.parent = parent ?? null;
2414
+ this._parent = null;
2367
2415
  this.attr = {};
2368
2416
  this.metaElement = meta ?? null;
2369
2417
  this.closed = closed;
@@ -2372,7 +2420,7 @@ class HtmlElement extends DOMNode {
2372
2420
  this.annotation = null;
2373
2421
  this._adapter = createAdapter(this);
2374
2422
  if (parent) {
2375
- parent.childNodes.push(this);
2423
+ parent.append(this);
2376
2424
  let cur = parent;
2377
2425
  while (cur.parent) {
2378
2426
  this.depth++;
@@ -2596,6 +2644,9 @@ class HtmlElement extends DOMNode {
2596
2644
  get meta() {
2597
2645
  return this.metaElement;
2598
2646
  }
2647
+ get parent() {
2648
+ return this._parent;
2649
+ }
2599
2650
  /**
2600
2651
  * Get current role for this element (explicit with `role` attribute or mapped
2601
2652
  * with implicit role).
@@ -2856,6 +2907,14 @@ class HtmlElement extends DOMNode {
2856
2907
  }
2857
2908
  return visit(this);
2858
2909
  }
2910
+ /**
2911
+ * @internal
2912
+ */
2913
+ _setParent(node) {
2914
+ const oldParent = this._parent;
2915
+ this._parent = node instanceof HtmlElement ? node : null;
2916
+ return oldParent;
2917
+ }
2859
2918
  }
2860
2919
  function isClosed(endToken, meta) {
2861
2920
  let closed = 0 /* Open */;
@@ -2880,20 +2939,22 @@ function dumpTree(root) {
2880
2939
  }
2881
2940
  return output;
2882
2941
  }
2883
- function writeNode(node, level, sibling) {
2942
+ function writeNode(node, level, indent, sibling) {
2943
+ const numSiblings = node.parent ? node.parent.childElements.length : 0;
2944
+ const lastSibling = sibling === numSiblings - 1;
2884
2945
  if (node.parent) {
2885
- const indent = " ".repeat(level - 1);
2886
- const l = node.childElements.length > 0 ? "\u252C" : "\u2500";
2887
- const b = sibling < node.parent.childElements.length - 1 ? "\u251C" : "\u2514";
2888
- lines.push(`${indent}${b}\u2500${l} ${node.tagName}${decoration(node)}`);
2946
+ const b = lastSibling ? "\u2514" : "\u251C";
2947
+ lines.push(`${indent}${b}\u2500\u2500 ${node.tagName}${decoration(node)}`);
2889
2948
  } else {
2890
2949
  lines.push("(root)");
2891
2950
  }
2892
2951
  node.childElements.forEach((child, index) => {
2893
- writeNode(child, level + 1, index);
2952
+ const s = lastSibling ? " " : "\u2502";
2953
+ const i = level > 0 ? `${indent}${s} ` : "";
2954
+ writeNode(child, level + 1, i, index);
2894
2955
  });
2895
2956
  }
2896
- writeNode(root, 0, 0);
2957
+ writeNode(root, 0, "", 0);
2897
2958
  return lines;
2898
2959
  }
2899
2960
 
@@ -7252,8 +7313,9 @@ Omitted end tags can be ambigious for humans to read and many editors have troub
7252
7313
  if (closed.closed !== NodeClosed.ImplicitClosed) {
7253
7314
  return;
7254
7315
  }
7255
- const closedByParent = closed.parent && closed.parent.tagName === by.tagName;
7256
- const closedByDocument = closedByParent && closed.parent.isRootElement();
7316
+ const parent = closed.parent;
7317
+ const closedByParent = parent && parent.tagName === by.tagName;
7318
+ const closedByDocument = closedByParent && parent.isRootElement();
7257
7319
  const sameTag = closed.tagName === by.tagName;
7258
7320
  if (closedByDocument) {
7259
7321
  this.report(
@@ -12885,7 +12947,7 @@ class HtmlValidate {
12885
12947
  }
12886
12948
 
12887
12949
  const name = "html-validate";
12888
- const version = "8.25.0";
12950
+ const version = "8.25.1";
12889
12951
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
12890
12952
 
12891
12953
  function definePlugin(plugin) {