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/cjs/core.js CHANGED
@@ -1753,7 +1753,31 @@ class DOMNode {
1753
1753
  return text;
1754
1754
  }
1755
1755
  append(node) {
1756
+ const oldParent = node._setParent(this);
1757
+ if (oldParent && this.isSameNode(oldParent)) {
1758
+ return;
1759
+ }
1756
1760
  this.childNodes.push(node);
1761
+ if (oldParent) {
1762
+ oldParent._removeChild(node);
1763
+ }
1764
+ }
1765
+ /**
1766
+ * Insert a node before a reference node.
1767
+ *
1768
+ * @internal
1769
+ */
1770
+ insertBefore(node, reference) {
1771
+ const index = reference ? this.childNodes.findIndex((it) => it.isSameNode(reference)) : -1;
1772
+ if (index >= 0) {
1773
+ this.childNodes.splice(index, 0, node);
1774
+ } else {
1775
+ this.childNodes.push(node);
1776
+ }
1777
+ const oldParent = node._setParent(this);
1778
+ if (oldParent) {
1779
+ oldParent._removeChild(node);
1780
+ }
1757
1781
  }
1758
1782
  isRootElement() {
1759
1783
  return this.nodeType === NodeType.DOCUMENT_NODE;
@@ -1780,6 +1804,14 @@ class DOMNode {
1780
1804
  get lastChild() {
1781
1805
  return this.childNodes[this.childNodes.length - 1] || null;
1782
1806
  }
1807
+ /**
1808
+ * @internal
1809
+ */
1810
+ removeChild(node) {
1811
+ this._removeChild(node);
1812
+ node._setParent(null);
1813
+ return node;
1814
+ }
1783
1815
  /**
1784
1816
  * Block a rule for this node.
1785
1817
  *
@@ -1854,6 +1886,22 @@ class DOMNode {
1854
1886
  generateSelector() {
1855
1887
  return null;
1856
1888
  }
1889
+ /**
1890
+ * @internal
1891
+ *
1892
+ * @returns Old parent, if set.
1893
+ */
1894
+ _setParent(_node) {
1895
+ return null;
1896
+ }
1897
+ _removeChild(node) {
1898
+ const index = this.childNodes.findIndex((it) => it.isSameNode(node));
1899
+ if (index >= 0) {
1900
+ this.childNodes.splice(index, 1);
1901
+ } else {
1902
+ throw new Error("DOMException: _removeChild(..) could not find child to remove");
1903
+ }
1904
+ }
1857
1905
  }
1858
1906
 
1859
1907
  function parse(text, baseLocation) {
@@ -2373,7 +2421,7 @@ class HtmlElement extends DOMNode {
2373
2421
  throw new Error(`The tag name provided ("${tagName}") is not a valid name`);
2374
2422
  }
2375
2423
  this.tagName = tagName ?? "#document";
2376
- this.parent = parent ?? null;
2424
+ this._parent = null;
2377
2425
  this.attr = {};
2378
2426
  this.metaElement = meta ?? null;
2379
2427
  this.closed = closed;
@@ -2382,7 +2430,7 @@ class HtmlElement extends DOMNode {
2382
2430
  this.annotation = null;
2383
2431
  this._adapter = createAdapter(this);
2384
2432
  if (parent) {
2385
- parent.childNodes.push(this);
2433
+ parent.append(this);
2386
2434
  let cur = parent;
2387
2435
  while (cur.parent) {
2388
2436
  this.depth++;
@@ -2606,6 +2654,9 @@ class HtmlElement extends DOMNode {
2606
2654
  get meta() {
2607
2655
  return this.metaElement;
2608
2656
  }
2657
+ get parent() {
2658
+ return this._parent;
2659
+ }
2609
2660
  /**
2610
2661
  * Get current role for this element (explicit with `role` attribute or mapped
2611
2662
  * with implicit role).
@@ -2866,6 +2917,14 @@ class HtmlElement extends DOMNode {
2866
2917
  }
2867
2918
  return visit(this);
2868
2919
  }
2920
+ /**
2921
+ * @internal
2922
+ */
2923
+ _setParent(node) {
2924
+ const oldParent = this._parent;
2925
+ this._parent = node instanceof HtmlElement ? node : null;
2926
+ return oldParent;
2927
+ }
2869
2928
  }
2870
2929
  function isClosed(endToken, meta) {
2871
2930
  let closed = 0 /* Open */;
@@ -2890,20 +2949,22 @@ function dumpTree(root) {
2890
2949
  }
2891
2950
  return output;
2892
2951
  }
2893
- function writeNode(node, level, sibling) {
2952
+ function writeNode(node, level, indent, sibling) {
2953
+ const numSiblings = node.parent ? node.parent.childElements.length : 0;
2954
+ const lastSibling = sibling === numSiblings - 1;
2894
2955
  if (node.parent) {
2895
- const indent = " ".repeat(level - 1);
2896
- const l = node.childElements.length > 0 ? "\u252C" : "\u2500";
2897
- const b = sibling < node.parent.childElements.length - 1 ? "\u251C" : "\u2514";
2898
- lines.push(`${indent}${b}\u2500${l} ${node.tagName}${decoration(node)}`);
2956
+ const b = lastSibling ? "\u2514" : "\u251C";
2957
+ lines.push(`${indent}${b}\u2500\u2500 ${node.tagName}${decoration(node)}`);
2899
2958
  } else {
2900
2959
  lines.push("(root)");
2901
2960
  }
2902
2961
  node.childElements.forEach((child, index) => {
2903
- writeNode(child, level + 1, index);
2962
+ const s = lastSibling ? " " : "\u2502";
2963
+ const i = level > 0 ? `${indent}${s} ` : "";
2964
+ writeNode(child, level + 1, i, index);
2904
2965
  });
2905
2966
  }
2906
- writeNode(root, 0, 0);
2967
+ writeNode(root, 0, "", 0);
2907
2968
  return lines;
2908
2969
  }
2909
2970
 
@@ -7262,8 +7323,9 @@ Omitted end tags can be ambigious for humans to read and many editors have troub
7262
7323
  if (closed.closed !== NodeClosed.ImplicitClosed) {
7263
7324
  return;
7264
7325
  }
7265
- const closedByParent = closed.parent && closed.parent.tagName === by.tagName;
7266
- const closedByDocument = closedByParent && closed.parent.isRootElement();
7326
+ const parent = closed.parent;
7327
+ const closedByParent = parent && parent.tagName === by.tagName;
7328
+ const closedByDocument = closedByParent && parent.isRootElement();
7267
7329
  const sameTag = closed.tagName === by.tagName;
7268
7330
  if (closedByDocument) {
7269
7331
  this.report(
@@ -12895,7 +12957,7 @@ class HtmlValidate {
12895
12957
  }
12896
12958
 
12897
12959
  const name = "html-validate";
12898
- const version = "8.25.0";
12960
+ const version = "8.25.1";
12899
12961
  const bugs = "https://gitlab.com/html-validate/html-validate/issues/new";
12900
12962
 
12901
12963
  function definePlugin(plugin) {