@markuplint/ml-core 3.0.0-canary.5 → 3.0.0-dev.177

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 (74) hide show
  1. package/README.md +1 -1
  2. package/lib/configs.browser.d.ts +2 -0
  3. package/lib/configs.browser.js +12 -0
  4. package/lib/configs.js +1 -2
  5. package/lib/index.d.ts +11 -1
  6. package/lib/ml-core.d.ts +23 -12
  7. package/lib/ml-core.js +4 -4
  8. package/lib/ml-dom/helper/accname.js +18 -7
  9. package/lib/ml-dom/helper/create-node.d.ts +6 -2
  10. package/lib/ml-dom/helper/create-node.js +3 -1
  11. package/lib/ml-dom/helper/debug.js +9 -4
  12. package/lib/ml-dom/helper/getIndent.d.ts +7 -7
  13. package/lib/ml-dom/helper/getIndent.js +18 -12
  14. package/lib/ml-dom/helper/walkers.d.ts +15 -5
  15. package/lib/ml-dom/helper/walkers.js +22 -16
  16. package/lib/ml-dom/manipulations/child-node-methods.d.ts +20 -7
  17. package/lib/ml-dom/manipulations/child-node-methods.js +24 -6
  18. package/lib/ml-dom/manipulations/get-children.d.ts +4 -2
  19. package/lib/ml-dom/manipulations/get-children.js +3 -1
  20. package/lib/ml-dom/node/attr.d.ts +94 -91
  21. package/lib/ml-dom/node/attr.js +8 -4
  22. package/lib/ml-dom/node/block.d.ts +36 -32
  23. package/lib/ml-dom/node/block.js +14 -4
  24. package/lib/ml-dom/node/character-data.d.ts +60 -53
  25. package/lib/ml-dom/node/character-data.js +9 -3
  26. package/lib/ml-dom/node/child-node.d.ts +10 -3
  27. package/lib/ml-dom/node/child-node.js +3 -1
  28. package/lib/ml-dom/node/comment.d.ts +16 -13
  29. package/lib/ml-dom/node/document-fragment.d.ts +23 -20
  30. package/lib/ml-dom/node/document-type.d.ts +35 -32
  31. package/lib/ml-dom/node/document-type.js +14 -4
  32. package/lib/ml-dom/node/document.d.ts +1607 -1589
  33. package/lib/ml-dom/node/document.js +56 -19
  34. package/lib/ml-dom/node/dom-token-list.d.ts +26 -26
  35. package/lib/ml-dom/node/dom-token-list.js +9 -7
  36. package/lib/ml-dom/node/element.d.ts +1903 -1889
  37. package/lib/ml-dom/node/element.js +76 -27
  38. package/lib/ml-dom/node/named-node-map.d.ts +45 -40
  39. package/lib/ml-dom/node/named-node-map.js +13 -5
  40. package/lib/ml-dom/node/node-list.d.ts +10 -4
  41. package/lib/ml-dom/node/node-list.js +25 -5
  42. package/lib/ml-dom/node/node-store.d.ts +9 -4
  43. package/lib/ml-dom/node/node-store.js +19 -1
  44. package/lib/ml-dom/node/node.d.ts +493 -473
  45. package/lib/ml-dom/node/node.js +52 -19
  46. package/lib/ml-dom/node/parent-node.d.ts +67 -58
  47. package/lib/ml-dom/node/parent-node.js +15 -6
  48. package/lib/ml-dom/node/rule-mapper.d.ts +7 -7
  49. package/lib/ml-dom/node/rule-mapper.js +11 -3
  50. package/lib/ml-dom/node/text.d.ts +50 -47
  51. package/lib/ml-dom/node/types.d.ts +82 -14
  52. package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -2
  53. package/lib/ml-dom/token/token.d.ts +44 -44
  54. package/lib/ml-rule/create-rule.d.ts +4 -2
  55. package/lib/ml-rule/create-test-rule.d.ts +6 -4
  56. package/lib/ml-rule/ml-rule-context.d.ts +58 -50
  57. package/lib/ml-rule/ml-rule-context.js +4 -2
  58. package/lib/ml-rule/ml-rule.d.ts +36 -26
  59. package/lib/ml-rule/ml-rule.js +37 -32
  60. package/lib/ml-rule/types.d.ts +35 -17
  61. package/lib/plugin/plugin.d.ts +3 -1
  62. package/lib/plugin/types.d.ts +7 -7
  63. package/lib/ruleset/index.d.ts +4 -4
  64. package/lib/ruleset/index.js +4 -4
  65. package/lib/test/index.d.ts +20 -8
  66. package/lib/test/index.js +1 -1
  67. package/lib/types.d.ts +9 -8
  68. package/lib/utils/get-location-from-chars.d.ts +9 -4
  69. package/package.json +21 -15
  70. package/test/ml-dom/helper/accname.spec.js +85 -0
  71. package/test/ml-dom/helper/create-node.spec.js +18 -0
  72. package/test/ml-dom/index.spec.js +680 -0
  73. package/tsconfig.test.json +0 -3
  74. package/tsconfig.tsbuildinfo +0 -1
@@ -17,7 +17,11 @@ const parent_node_1 = require("./parent-node");
17
17
  const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
18
18
  const HTML_NAMESPACE = 'http://www.w3.org/1999/xhtml';
19
19
  class MLElement extends parent_node_1.MLParentNode {
20
- constructor(astNode, document) {
20
+ constructor(
21
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
22
+ astNode,
23
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
24
+ document) {
21
25
  super(astNode, document);
22
26
  _MLElement_attributes.set(this, void 0);
23
27
  _MLElement_fixedNodeName.set(this, void 0);
@@ -635,7 +639,8 @@ class MLElement extends parent_node_1.MLParentNode {
635
639
  * @see https://dom.spec.whatwg.org/#ref-for-dom-element-id%E2%91%A0
636
640
  */
637
641
  get id() {
638
- return this.getAttribute('id') || '';
642
+ var _a;
643
+ return (_a = this.getAttribute('id')) !== null && _a !== void 0 ? _a : '';
639
644
  }
640
645
  /**
641
646
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -1785,7 +1790,7 @@ class MLElement extends parent_node_1.MLParentNode {
1785
1790
  return (0, child_node_methods_1.previousElementSibling)(this);
1786
1791
  }
1787
1792
  get raw() {
1788
- var _a, _b;
1793
+ var _a, _b, _c;
1789
1794
  if (((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender') {
1790
1795
  return this.originRaw;
1791
1796
  }
@@ -1796,7 +1801,7 @@ class MLElement extends parent_node_1.MLParentNode {
1796
1801
  gap = gap + this.fixedNodeName.length - this.nodeName.length;
1797
1802
  }
1798
1803
  for (const attr of Array.from(this.attributes)) {
1799
- const startOffset = (((_b = attr.spacesBeforeName) === null || _b === void 0 ? void 0 : _b.startOffset) || attr.startOffset) - this.startOffset;
1804
+ const startOffset = ((_c = (_b = attr.spacesBeforeName) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : attr.startOffset) - this.startOffset;
1800
1805
  const fixedAttr = attr.toString();
1801
1806
  if (attr.originRaw !== fixedAttr) {
1802
1807
  fixed = (0, string_splice_1.stringSplice)(fixed, startOffset + gap, attr.originRaw.length, fixedAttr);
@@ -1886,7 +1891,8 @@ class MLElement extends parent_node_1.MLParentNode {
1886
1891
  * @see https://dom.spec.whatwg.org/#ref-for-dom-element-slot%E2%91%A0
1887
1892
  */
1888
1893
  get slot() {
1889
- return this.getAttribute('slot') || '';
1894
+ var _a;
1895
+ return (_a = this.getAttribute('slot')) !== null && _a !== void 0 ? _a : '';
1890
1896
  }
1891
1897
  /**
1892
1898
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -1943,7 +1949,7 @@ class MLElement extends parent_node_1.MLParentNode {
1943
1949
  }
1944
1950
  get textContent() {
1945
1951
  return Array.from(this.childNodes)
1946
- .map(child => child.textContent || '')
1952
+ .map(child => { var _a; return (_a = child.textContent) !== null && _a !== void 0 ? _a : ''; })
1947
1953
  .join('');
1948
1954
  }
1949
1955
  /**
@@ -1969,7 +1975,9 @@ class MLElement extends parent_node_1.MLParentNode {
1969
1975
  /**
1970
1976
  * @implements DOM API: `Element`
1971
1977
  */
1972
- after(...nodes) {
1978
+ after(
1979
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1980
+ ...nodes) {
1973
1981
  (0, child_node_methods_1.after)(this, ...nodes);
1974
1982
  }
1975
1983
  /**
@@ -1979,7 +1987,11 @@ class MLElement extends parent_node_1.MLParentNode {
1979
1987
  * @implements DOM API: `Element`
1980
1988
  * @see https://www.w3.org/TR/web-animations-1/#dom-animatable-animate
1981
1989
  */
1982
- animate(keyframes, options) {
1990
+ animate(
1991
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1992
+ keyframes,
1993
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
1994
+ options) {
1983
1995
  throw new unexpected_call_error_1.default('Not supported "animate" method');
1984
1996
  }
1985
1997
  /**
@@ -1999,13 +2011,17 @@ class MLElement extends parent_node_1.MLParentNode {
1999
2011
  * @implements DOM API: `Element`
2000
2012
  * @see https://dom.spec.whatwg.org/#ref-for-dom-element-attachshadow%E2%91%A0
2001
2013
  */
2002
- attachShadow(init) {
2014
+ attachShadow(
2015
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2016
+ init) {
2003
2017
  throw new unexpected_call_error_1.default('Not supported "attachShadow" method');
2004
2018
  }
2005
2019
  /**
2006
2020
  * @implements DOM API: `Element`
2007
2021
  */
2008
- before(...nodes) {
2022
+ before(
2023
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2024
+ ...nodes) {
2009
2025
  (0, child_node_methods_1.before)(this, ...nodes);
2010
2026
  }
2011
2027
  /**
@@ -2018,6 +2034,18 @@ class MLElement extends parent_node_1.MLParentNode {
2018
2034
  blur() {
2019
2035
  throw new unexpected_call_error_1.default('Not supported "blur" method');
2020
2036
  }
2037
+ /**
2038
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
2039
+ *
2040
+ * @deprecated
2041
+ * @unsupported
2042
+ * @implements DOM API: `Element`
2043
+ */
2044
+ checkVisibility(
2045
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2046
+ options) {
2047
+ throw new unexpected_call_error_1.default('Not supported "checkVisibility" method');
2048
+ }
2021
2049
  /**
2022
2050
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
2023
2051
  *
@@ -2052,7 +2080,9 @@ class MLElement extends parent_node_1.MLParentNode {
2052
2080
  * @unsupported
2053
2081
  * @implements DOM API: `Element`
2054
2082
  */
2055
- focus(options) {
2083
+ focus(
2084
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2085
+ options) {
2056
2086
  throw new unexpected_call_error_1.default('Not supported "focus" method');
2057
2087
  }
2058
2088
  /**
@@ -2068,7 +2098,9 @@ class MLElement extends parent_node_1.MLParentNode {
2068
2098
  * @implements DOM API: `Element`
2069
2099
  * @see https://www.w3.org/TR/web-animations-1/#dom-animatable-getanimations
2070
2100
  */
2071
- getAnimations(options) {
2101
+ getAnimations(
2102
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2103
+ options) {
2072
2104
  throw new unexpected_call_error_1.default('Not supported "getAnimations" method');
2073
2105
  }
2074
2106
  /**
@@ -2105,7 +2137,8 @@ class MLElement extends parent_node_1.MLParentNode {
2105
2137
  * @see https://dom.spec.whatwg.org/#dom-element-getattributenode
2106
2138
  */
2107
2139
  getAttributeNode(qualifiedName) {
2108
- return this.getAttributeToken(qualifiedName)[0] || null;
2140
+ var _a;
2141
+ return (_a = this.getAttributeToken(qualifiedName)[0]) !== null && _a !== void 0 ? _a : null;
2109
2142
  }
2110
2143
  /**
2111
2144
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -2254,7 +2287,7 @@ class MLElement extends parent_node_1.MLParentNode {
2254
2287
  * @see https://dom.spec.whatwg.org/#dom-element-hasattributes
2255
2288
  */
2256
2289
  hasAttributes() {
2257
- return !!this.attributes.length;
2290
+ return this.attributes.length > 0;
2258
2291
  }
2259
2292
  /**
2260
2293
  * @implements `@markuplint/ml-core` API: `MLElement`
@@ -2308,7 +2341,9 @@ class MLElement extends parent_node_1.MLParentNode {
2308
2341
  * @implements DOM API: `Element`
2309
2342
  * @see https://dom.spec.whatwg.org/#dom-element-insertadjacentelement
2310
2343
  */
2311
- insertAdjacentElement(where, element) {
2344
+ insertAdjacentElement(where,
2345
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2346
+ element) {
2312
2347
  // TODO:
2313
2348
  throw new unexpected_call_error_1.default('Does not implement "insertAdjacentElement" method yet');
2314
2349
  }
@@ -2368,14 +2403,15 @@ class MLElement extends parent_node_1.MLParentNode {
2368
2403
  */
2369
2404
  matches(selector) {
2370
2405
  var _a;
2371
- return !!(0, selector_1.createSelector)(selector, this.ownerMLDocument.specs).match(
2406
+ return ((0, selector_1.createSelector)(selector, this.ownerMLDocument.specs).match(
2372
2407
  // Prioritize the pretender
2373
- ((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender' ? this.pretenderContext.as : this);
2408
+ ((_a = this.pretenderContext) === null || _a === void 0 ? void 0 : _a.type) === 'pretender' ? this.pretenderContext.as : this) !== false);
2374
2409
  }
2375
2410
  /**
2376
2411
  * Pretenders Initialization
2377
2412
  */
2378
2413
  pretending(pretenders) {
2414
+ var _a;
2379
2415
  const pretenderConfig = pretenders === null || pretenders === void 0 ? void 0 : pretenders.find(option => this.matches(option.selector));
2380
2416
  if (!pretenderConfig) {
2381
2417
  return;
@@ -2389,16 +2425,17 @@ class MLElement extends parent_node_1.MLParentNode {
2389
2425
  }
2390
2426
  else {
2391
2427
  nodeName = pretenderConfig.as.element;
2392
- namespace = pretenderConfig.as.namespace || namespace;
2428
+ namespace = (_a = pretenderConfig.as.namespace) !== null && _a !== void 0 ? _a : namespace;
2393
2429
  if (pretenderConfig.as.inheritAttrs) {
2394
2430
  attributes.push(...this._astToken.attributes);
2395
2431
  }
2396
2432
  if (pretenderConfig.as.attrs) {
2397
2433
  attributes.push(...pretenderConfig.as.attrs.map(({ name, value }, i) => {
2398
- const _value = value
2434
+ var _a;
2435
+ const _value = value != null
2399
2436
  ? typeof value === 'string'
2400
2437
  ? value
2401
- : this.getAttribute(value.fromAttr) || ''
2438
+ : (_a = this.getAttribute(value.fromAttr)) !== null && _a !== void 0 ? _a : ''
2402
2439
  : '';
2403
2440
  return {
2404
2441
  ...this._astToken,
@@ -2511,13 +2548,17 @@ class MLElement extends parent_node_1.MLParentNode {
2511
2548
  * @implements DOM API: `Element`
2512
2549
  * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-D589198
2513
2550
  */
2514
- removeAttributeNode(attr) {
2551
+ removeAttributeNode(
2552
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2553
+ attr) {
2515
2554
  throw new unexpected_call_error_1.default('Not supported "removeAttributeNode" method');
2516
2555
  }
2517
2556
  /**
2518
2557
  * @implements DOM API: `Element`
2519
2558
  */
2520
- replaceWith(...nodes) {
2559
+ replaceWith(
2560
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2561
+ ...nodes) {
2521
2562
  (0, child_node_methods_1.replaceWith)(this, ...nodes);
2522
2563
  }
2523
2564
  /**
@@ -2527,7 +2568,9 @@ class MLElement extends parent_node_1.MLParentNode {
2527
2568
  * @implements DOM API: `Element`
2528
2569
  * @see https://fullscreen.spec.whatwg.org/#dom-element-requestfullscreen
2529
2570
  */
2530
- requestFullscreen(options) {
2571
+ requestFullscreen(
2572
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2573
+ options) {
2531
2574
  throw new unexpected_call_error_1.default('Not supported "requestFullscreen" method');
2532
2575
  }
2533
2576
  /**
@@ -2567,7 +2610,9 @@ class MLElement extends parent_node_1.MLParentNode {
2567
2610
  * @implements DOM API: `Element`
2568
2611
  * @see https://www.w3.org/TR/cssom-view-1/#dom-element-scrollintoview
2569
2612
  */
2570
- scrollIntoView(arg) {
2613
+ scrollIntoView(
2614
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2615
+ arg) {
2571
2616
  throw new unexpected_call_error_1.default('Not supported "scrollIntoView" method');
2572
2617
  }
2573
2618
  /**
@@ -2607,7 +2652,9 @@ class MLElement extends parent_node_1.MLParentNode {
2607
2652
  * @implements DOM API: `Element`
2608
2653
  * @see https://dom.spec.whatwg.org/#dom-element-setattributenode
2609
2654
  */
2610
- setAttributeNode(attr) {
2655
+ setAttributeNode(
2656
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2657
+ attr) {
2611
2658
  throw new unexpected_call_error_1.default('Not supported "setAttributeNode" method');
2612
2659
  }
2613
2660
  /**
@@ -2617,7 +2664,9 @@ class MLElement extends parent_node_1.MLParentNode {
2617
2664
  * @implements DOM API: `Element`
2618
2665
  * @see https://dom.spec.whatwg.org/#dom-element-setattributenodens
2619
2666
  */
2620
- setAttributeNodeNS(attr) {
2667
+ setAttributeNodeNS(
2668
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
2669
+ attr) {
2621
2670
  throw new unexpected_call_error_1.default('Not supported "setAttributeNodeNS" method');
2622
2671
  }
2623
2672
  /**
@@ -2639,7 +2688,7 @@ class MLElement extends parent_node_1.MLParentNode {
2639
2688
  }
2640
2689
  const children = this.getChildElementsAndTextNodeWithoutWhitespaces();
2641
2690
  const attrs = this.attributes.map(attr => attr.toNormalizeString());
2642
- const attrString = attrs.length ? ' ' + attrs.join('') : '';
2691
+ const attrString = attrs.length > 0 ? ' ' + attrs.join('') : '';
2643
2692
  const startTag = `<${this.nodeName}${attrString}>`;
2644
2693
  const childNodes = children.map(node => {
2645
2694
  if (node.is(node.ELEMENT_NODE)) {
@@ -1,42 +1,47 @@
1
1
  import type { MLAttr } from './attr';
2
- import type { RuleConfigValue } from '@markuplint/ml-config';
3
- export declare class MLNamedNodeMap<T extends RuleConfigValue, O = null> extends Array<MLAttr<T, O>> implements NamedNodeMap {
4
- getNamedItem(qualifiedName: string): MLAttr<T, O> | null;
5
- /**
6
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
7
- *
8
- * @unsupported
9
- * @implements DOM API: `NamedNodeMap`
10
- */
11
- getNamedItemNS(namespace: string | null, localName: string): Attr | null;
12
- item(index: number): MLAttr<T, O> | null;
13
- /**
14
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
15
- *
16
- * @unsupported
17
- * @implements DOM API: `NamedNodeMap`
18
- */
19
- removeNamedItem(qualifiedName: string): MLAttr<T, O>;
20
- /**
21
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
22
- *
23
- * @unsupported
24
- * @implements DOM API: `NamedNodeMap`
25
- */
26
- removeNamedItemNS(namespace: string | null, localName: string): MLAttr<T, O>;
27
- /**
28
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
29
- *
30
- * @unsupported
31
- * @implements DOM API: `NamedNodeMap`
32
- */
33
- setNamedItem(attr: MLAttr<T, O>): MLAttr<T, O> | null;
34
- /**
35
- * **IT THROWS AN ERROR WHEN CALLING THIS.**
36
- *
37
- * @unsupported
38
- * @implements DOM API: `NamedNodeMap`
39
- */
40
- setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
2
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
+ export declare class MLNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>
4
+ extends Array<MLAttr<T, O>>
5
+ implements NamedNodeMap
6
+ {
7
+ getNamedItem(qualifiedName: string): MLAttr<T, O> | null;
8
+ /**
9
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
10
+ *
11
+ * @unsupported
12
+ * @implements DOM API: `NamedNodeMap`
13
+ */
14
+ getNamedItemNS(namespace: string | null, localName: string): Attr | null;
15
+ item(index: number): MLAttr<T, O> | null;
16
+ /**
17
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
18
+ *
19
+ * @unsupported
20
+ * @implements DOM API: `NamedNodeMap`
21
+ */
22
+ removeNamedItem(qualifiedName: string): MLAttr<T, O>;
23
+ /**
24
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
25
+ *
26
+ * @unsupported
27
+ * @implements DOM API: `NamedNodeMap`
28
+ */
29
+ removeNamedItemNS(namespace: string | null, localName: string): MLAttr<T, O>;
30
+ /**
31
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
32
+ *
33
+ * @unsupported
34
+ * @implements DOM API: `NamedNodeMap`
35
+ */
36
+ setNamedItem(attr: MLAttr<T, O>): MLAttr<T, O> | null;
37
+ /**
38
+ * **IT THROWS AN ERROR WHEN CALLING THIS.**
39
+ *
40
+ * @unsupported
41
+ * @implements DOM API: `NamedNodeMap`
42
+ */
43
+ setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
41
44
  }
42
- export declare function toNamedNodeMap<T extends RuleConfigValue, O = null>(nodes: ReadonlyArray<MLAttr<T, O>>): MLNamedNodeMap<T, O>;
45
+ export declare function toNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>(
46
+ nodes: ReadonlyArray<MLAttr<T, O>>,
47
+ ): MLNamedNodeMap<T, O>;
@@ -5,7 +5,8 @@ const tslib_1 = require("tslib");
5
5
  const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
6
6
  class MLNamedNodeMap extends Array {
7
7
  getNamedItem(qualifiedName) {
8
- return this.find(attr => attr.name === qualifiedName) || null;
8
+ var _a;
9
+ return (_a = this.find(attr => attr.name === qualifiedName)) !== null && _a !== void 0 ? _a : null;
9
10
  }
10
11
  /**
11
12
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -17,7 +18,8 @@ class MLNamedNodeMap extends Array {
17
18
  throw new unexpected_call_error_1.default('Not supported "getNamedItemNS" method');
18
19
  }
19
20
  item(index) {
20
- return this[index];
21
+ var _a;
22
+ return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
21
23
  }
22
24
  /**
23
25
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -43,7 +45,9 @@ class MLNamedNodeMap extends Array {
43
45
  * @unsupported
44
46
  * @implements DOM API: `NamedNodeMap`
45
47
  */
46
- setNamedItem(attr) {
48
+ setNamedItem(
49
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
50
+ attr) {
47
51
  throw new unexpected_call_error_1.default('Not supported "setNamedItem" method');
48
52
  }
49
53
  /**
@@ -52,12 +56,16 @@ class MLNamedNodeMap extends Array {
52
56
  * @unsupported
53
57
  * @implements DOM API: `NamedNodeMap`
54
58
  */
55
- setNamedItemNS(attr) {
59
+ setNamedItemNS(
60
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
61
+ attr) {
56
62
  throw new unexpected_call_error_1.default('Not supported "setNamedItemNS" method');
57
63
  }
58
64
  }
59
65
  exports.MLNamedNodeMap = MLNamedNodeMap;
60
- function toNamedNodeMap(nodes) {
66
+ function toNamedNodeMap(
67
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
68
+ nodes) {
61
69
  const namedNodeMap = new MLNamedNodeMap(...nodes);
62
70
  return namedNodeMap;
63
71
  }
@@ -1,6 +1,12 @@
1
1
  import type { MLChildNode } from './child-node';
2
2
  import type { MLElement } from './element';
3
- import type { RuleConfigValue } from '@markuplint/ml-config';
4
- export declare function toNodeList<T extends RuleConfigValue, O, N extends MLChildNode<T, O>>(nodes: ReadonlyArray<N>): NodeListOf<N>;
5
- export declare function toHTMLCollection<T extends RuleConfigValue, O = null>(nodes: ReadonlyArray<MLElement<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
6
- export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O = null>(nodeList: NodeListOf<MLChildNode<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
3
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
4
+ export declare function toNodeList<T extends RuleConfigValue, O extends PlainData, N extends MLChildNode<T, O>>(
5
+ nodes: ReadonlyArray<N>,
6
+ ): NodeListOf<N>;
7
+ export declare function toHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
8
+ nodes: ReadonlyArray<MLElement<T, O>>,
9
+ ): HTMLCollectionOf<MLElement<T, O>>;
10
+ export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(
11
+ nodeList: NodeListOf<MLChildNode<T, O>>,
12
+ ): HTMLCollectionOf<MLElement<T, O>>;
@@ -6,7 +6,21 @@ class MLNodeList extends Array {
6
6
  return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg !== null && thisArg !== void 0 ? thisArg : this));
7
7
  }
8
8
  item(index) {
9
- return this[index];
9
+ const node = this[index];
10
+ if (!node) {
11
+ /**
12
+ * ⚠ TYPE CONTRADICTION
13
+ *
14
+ * It throws an error because it should return null but the `item` method of `NodeListOf` doesn't return null in the type definition of TypeScript.
15
+ *
16
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-844377136
17
+ *
18
+ * > item
19
+ * > Returns the index-th item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
20
+ */
21
+ throw new ReferenceError('Invalid index');
22
+ }
23
+ return node;
10
24
  }
11
25
  }
12
26
  function toNodeList(nodes) {
@@ -16,18 +30,24 @@ function toNodeList(nodes) {
16
30
  exports.toNodeList = toNodeList;
17
31
  class MLHTMLCollection extends Array {
18
32
  item(index) {
19
- return this[index];
33
+ var _a;
34
+ return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
20
35
  }
21
36
  namedItem(name) {
22
- return this.find(el => el.getAttribute('name') === name) || null;
37
+ var _a;
38
+ return (_a = this.find(el => el.getAttribute('name') === name)) !== null && _a !== void 0 ? _a : null;
23
39
  }
24
40
  }
25
- function toHTMLCollection(nodes) {
41
+ function toHTMLCollection(
42
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
43
+ nodes) {
26
44
  const collection = new MLHTMLCollection(...nodes);
27
45
  return collection;
28
46
  }
29
47
  exports.toHTMLCollection = toHTMLCollection;
30
- function nodeListToHTMLCollection(nodeList) {
48
+ function nodeListToHTMLCollection(
49
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
50
+ nodeList) {
31
51
  const collection = new MLHTMLCollection();
32
52
  nodeList.forEach(node => {
33
53
  if (node.is(node.ELEMENT_NODE)) {
@@ -1,11 +1,16 @@
1
1
  import type { MLNode } from './node';
2
2
  import type { MappedNode } from './types';
3
3
  import type { MLASTAbstractNode } from '@markuplint/ml-ast';
4
- import type { RuleConfigValue } from '@markuplint/ml-config';
4
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
5
5
  declare class NodeStore {
6
- #private;
7
- getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O = null>(astNode: N): MappedNode<N, T, O>;
8
- setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O = null>(astNode: A, node: MLNode<T, O, A>): void;
6
+ #private;
7
+ getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
8
+ astNode: N,
9
+ ): MappedNode<N, T, O>;
10
+ setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(
11
+ astNode: A,
12
+ node: MLNode<T, O, A>,
13
+ ): void;
9
14
  }
10
15
  /**
11
16
  * `NodeStore` Singleton
@@ -4,6 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.nodeStore = void 0;
5
5
  const tslib_1 = require("tslib");
6
6
  const parser_utils_1 = require("@markuplint/parser-utils");
7
+ const debug_1 = require("../../debug");
8
+ const nodeStoreLog = debug_1.log.extend('node-store');
9
+ const nodeStoreError = nodeStoreLog.extend('error');
7
10
  class NodeStore {
8
11
  constructor() {
9
12
  _NodeStore_store.set(this, new Map());
@@ -12,6 +15,11 @@ class NodeStore {
12
15
  // console.log(`Get: ${astNode.uuid} -> ${astNode.raw.trim()}(${astNode.type})`);
13
16
  const node = tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
14
17
  if (!node) {
18
+ nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
19
+ nodeStoreError('Map: %O', Array.from(tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").entries()).map(([id, node]) => ({
20
+ id,
21
+ name: node.nodeName,
22
+ })));
15
23
  throw new parser_utils_1.ParserError('Broke mapping nodes.', {
16
24
  line: astNode.startLine,
17
25
  col: astNode.startCol,
@@ -21,7 +29,17 @@ class NodeStore {
21
29
  }
22
30
  return node;
23
31
  }
24
- setNode(astNode, node) {
32
+ setNode(astNode,
33
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
34
+ node) {
35
+ if (node.is(node.DOCUMENT_NODE)) {
36
+ return;
37
+ }
38
+ if (!astNode.uuid) {
39
+ nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
40
+ nodeStoreError('Invalid node: %O', node);
41
+ }
42
+ nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replace(/\n/g, '⏎').replace(/\t/g, '→'));
25
43
  tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
26
44
  }
27
45
  }