@markuplint/ml-core 3.0.0-dev.24 → 3.0.0-dev.290

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 (95) hide show
  1. package/lib/configs.browser.js +1 -5
  2. package/lib/configs.js +33 -31
  3. package/lib/convert-ruleset.d.ts +1 -1
  4. package/lib/convert-ruleset.js +3 -8
  5. package/lib/debug.js +9 -14
  6. package/lib/index.d.ts +13 -12
  7. package/lib/index.js +13 -29
  8. package/lib/ml-core.d.ts +7 -7
  9. package/lib/ml-core.js +60 -66
  10. package/lib/ml-dom/helper/accname.d.ts +1 -1
  11. package/lib/ml-dom/helper/accname.js +23 -19
  12. package/lib/ml-dom/helper/create-node.d.ts +4 -4
  13. package/lib/ml-dom/helper/create-node.js +13 -15
  14. package/lib/ml-dom/helper/debug.d.ts +1 -1
  15. package/lib/ml-dom/helper/debug.js +8 -8
  16. package/lib/ml-dom/helper/getIndent.d.ts +2 -2
  17. package/lib/ml-dom/helper/getIndent.js +30 -28
  18. package/lib/ml-dom/helper/walkers.d.ts +6 -6
  19. package/lib/ml-dom/helper/walkers.js +23 -22
  20. package/lib/ml-dom/index.d.ts +9 -9
  21. package/lib/ml-dom/index.js +1 -5
  22. package/lib/ml-dom/manipulations/child-node-methods.d.ts +9 -9
  23. package/lib/ml-dom/manipulations/child-node-methods.js +31 -25
  24. package/lib/ml-dom/manipulations/get-children.d.ts +4 -4
  25. package/lib/ml-dom/manipulations/get-children.js +5 -7
  26. package/lib/ml-dom/node/attr.d.ts +7 -7
  27. package/lib/ml-dom/node/attr.js +33 -34
  28. package/lib/ml-dom/node/block.d.ts +6 -6
  29. package/lib/ml-dom/node/block.js +21 -15
  30. package/lib/ml-dom/node/character-data.d.ts +4 -4
  31. package/lib/ml-dom/node/character-data.js +20 -19
  32. package/lib/ml-dom/node/child-node.d.ts +9 -9
  33. package/lib/ml-dom/node/child-node.js +3 -5
  34. package/lib/ml-dom/node/comment.d.ts +4 -4
  35. package/lib/ml-dom/node/comment.js +2 -6
  36. package/lib/ml-dom/node/document-fragment.d.ts +4 -4
  37. package/lib/ml-dom/node/document-fragment.js +4 -9
  38. package/lib/ml-dom/node/document-type.d.ts +6 -6
  39. package/lib/ml-dom/node/document-type.js +21 -15
  40. package/lib/ml-dom/node/document.d.ts +32 -29
  41. package/lib/ml-dom/node/document.js +329 -246
  42. package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
  43. package/lib/ml-dom/node/dom-token-list.js +29 -33
  44. package/lib/ml-dom/node/element.d.ts +65 -16
  45. package/lib/ml-dom/node/element.js +396 -306
  46. package/lib/ml-dom/node/named-node-map.d.ts +4 -4
  47. package/lib/ml-dom/node/named-node-map.js +18 -18
  48. package/lib/ml-dom/node/node-list.d.ts +6 -6
  49. package/lib/ml-dom/node/node-list.js +25 -13
  50. package/lib/ml-dom/node/node-store.d.ts +5 -5
  51. package/lib/ml-dom/node/node-store.js +25 -10
  52. package/lib/ml-dom/node/node.d.ts +12 -12
  53. package/lib/ml-dom/node/node.js +101 -76
  54. package/lib/ml-dom/node/parent-node.d.ts +6 -6
  55. package/lib/ml-dom/node/parent-node.js +31 -29
  56. package/lib/ml-dom/node/rule-mapper.d.ts +5 -5
  57. package/lib/ml-dom/node/rule-mapper.js +20 -17
  58. package/lib/ml-dom/node/text.d.ts +4 -4
  59. package/lib/ml-dom/node/text.js +6 -11
  60. package/lib/ml-dom/node/types.d.ts +30 -16
  61. package/lib/ml-dom/node/types.js +1 -2
  62. package/lib/ml-dom/node/unexpected-call-error.js +1 -4
  63. package/lib/ml-dom/token/token.js +19 -23
  64. package/lib/ml-rule/create-rule.d.ts +3 -3
  65. package/lib/ml-rule/create-rule.js +1 -5
  66. package/lib/ml-rule/create-test-rule.d.ts +5 -5
  67. package/lib/ml-rule/create-test-rule.js +3 -7
  68. package/lib/ml-rule/index.d.ts +3 -3
  69. package/lib/ml-rule/index.js +3 -6
  70. package/lib/ml-rule/ml-rule-context.d.ts +4 -4
  71. package/lib/ml-rule/ml-rule-context.js +11 -13
  72. package/lib/ml-rule/ml-rule.d.ts +9 -9
  73. package/lib/ml-rule/ml-rule.js +48 -45
  74. package/lib/ml-rule/types.d.ts +12 -12
  75. package/lib/ml-rule/types.js +1 -2
  76. package/lib/plugin/index.d.ts +2 -2
  77. package/lib/plugin/index.js +2 -5
  78. package/lib/plugin/plugin.d.ts +2 -2
  79. package/lib/plugin/plugin.js +1 -5
  80. package/lib/plugin/types.d.ts +6 -6
  81. package/lib/plugin/types.js +1 -2
  82. package/lib/ruleset/index.d.ts +3 -3
  83. package/lib/ruleset/index.js +4 -8
  84. package/lib/test/index.d.ts +9 -9
  85. package/lib/test/index.js +14 -24
  86. package/lib/types.d.ts +11 -10
  87. package/lib/types.js +1 -2
  88. package/lib/utils/get-location-from-chars.d.ts +1 -1
  89. package/lib/utils/get-location-from-chars.js +1 -5
  90. package/lib/utils/index.d.ts +1 -1
  91. package/lib/utils/index.js +1 -5
  92. package/lib/utils/string-splice.js +1 -5
  93. package/package.json +25 -16
  94. package/tsconfig.test.json +0 -3
  95. package/tsconfig.tsbuildinfo +0 -1
@@ -1,6 +1,6 @@
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 {
1
+ import type { MLAttr } from './attr.js';
2
+ import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
+ export declare class MLNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined> extends Array<MLAttr<T, O>> implements NamedNodeMap {
4
4
  getNamedItem(qualifiedName: string): MLAttr<T, O> | null;
5
5
  /**
6
6
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -39,4 +39,4 @@ export declare class MLNamedNodeMap<T extends RuleConfigValue, O = null> extends
39
39
  */
40
40
  setNamedItemNS(attr: MLAttr<T, O>): MLAttr<T, O> | null;
41
41
  }
42
- export declare function toNamedNodeMap<T extends RuleConfigValue, O = null>(nodes: ReadonlyArray<MLAttr<T, O>>): MLNamedNodeMap<T, O>;
42
+ export declare function toNamedNodeMap<T extends RuleConfigValue, O extends PlainData = undefined>(nodes: ReadonlyArray<MLAttr<T, O>>): MLNamedNodeMap<T, O>;
@@ -1,11 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.toNamedNodeMap = exports.MLNamedNodeMap = void 0;
4
- const tslib_1 = require("tslib");
5
- const unexpected_call_error_1 = tslib_1.__importDefault(require("./unexpected-call-error"));
6
- class MLNamedNodeMap extends Array {
1
+ import UnexpectedCallError from './unexpected-call-error.js';
2
+ export class MLNamedNodeMap extends Array {
7
3
  getNamedItem(qualifiedName) {
8
- return this.find(attr => attr.name === qualifiedName) || null;
4
+ return this.find(attr => attr.name === qualifiedName) ?? null;
9
5
  }
10
6
  /**
11
7
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -14,10 +10,10 @@ class MLNamedNodeMap extends Array {
14
10
  * @implements DOM API: `NamedNodeMap`
15
11
  */
16
12
  getNamedItemNS(namespace, localName) {
17
- throw new unexpected_call_error_1.default('Not supported "getNamedItemNS" method');
13
+ throw new UnexpectedCallError('Not supported "getNamedItemNS" method');
18
14
  }
19
15
  item(index) {
20
- return this[index];
16
+ return this[index] ?? null;
21
17
  }
22
18
  /**
23
19
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -26,7 +22,7 @@ class MLNamedNodeMap extends Array {
26
22
  * @implements DOM API: `NamedNodeMap`
27
23
  */
28
24
  removeNamedItem(qualifiedName) {
29
- throw new unexpected_call_error_1.default('Not supported "removeNamedItem" method');
25
+ throw new UnexpectedCallError('Not supported "removeNamedItem" method');
30
26
  }
31
27
  /**
32
28
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -35,7 +31,7 @@ class MLNamedNodeMap extends Array {
35
31
  * @implements DOM API: `NamedNodeMap`
36
32
  */
37
33
  removeNamedItemNS(namespace, localName) {
38
- throw new unexpected_call_error_1.default('Not supported "removeNamedItemNS" method');
34
+ throw new UnexpectedCallError('Not supported "removeNamedItemNS" method');
39
35
  }
40
36
  /**
41
37
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -43,8 +39,10 @@ class MLNamedNodeMap extends Array {
43
39
  * @unsupported
44
40
  * @implements DOM API: `NamedNodeMap`
45
41
  */
46
- setNamedItem(attr) {
47
- throw new unexpected_call_error_1.default('Not supported "setNamedItem" method');
42
+ setNamedItem(
43
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
44
+ attr) {
45
+ throw new UnexpectedCallError('Not supported "setNamedItem" method');
48
46
  }
49
47
  /**
50
48
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -52,13 +50,15 @@ class MLNamedNodeMap extends Array {
52
50
  * @unsupported
53
51
  * @implements DOM API: `NamedNodeMap`
54
52
  */
55
- setNamedItemNS(attr) {
56
- throw new unexpected_call_error_1.default('Not supported "setNamedItemNS" method');
53
+ setNamedItemNS(
54
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
55
+ attr) {
56
+ throw new UnexpectedCallError('Not supported "setNamedItemNS" method');
57
57
  }
58
58
  }
59
- exports.MLNamedNodeMap = MLNamedNodeMap;
60
- function toNamedNodeMap(nodes) {
59
+ export function toNamedNodeMap(
60
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
61
+ nodes) {
61
62
  const namedNodeMap = new MLNamedNodeMap(...nodes);
62
63
  return namedNodeMap;
63
64
  }
64
- exports.toNamedNodeMap = toNamedNodeMap;
@@ -1,6 +1,6 @@
1
- import type { MLChildNode } from './child-node';
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>>;
1
+ import type { MLChildNode } from './child-node.js';
2
+ import type { MLElement } from './element.js';
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>>(nodes: ReadonlyArray<N>): NodeListOf<N>;
5
+ export declare function toHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(nodes: ReadonlyArray<MLElement<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
6
+ export declare function nodeListToHTMLCollection<T extends RuleConfigValue, O extends PlainData = undefined>(nodeList: NodeListOf<MLChildNode<T, O>>): HTMLCollectionOf<MLElement<T, O>>;
@@ -1,33 +1,46 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.nodeListToHTMLCollection = exports.toHTMLCollection = exports.toNodeList = void 0;
4
1
  class MLNodeList extends Array {
5
2
  forEach(callbackfn, thisArg) {
6
- return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg !== null && thisArg !== void 0 ? thisArg : this));
3
+ return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg ?? this));
7
4
  }
8
5
  item(index) {
9
- return this[index];
6
+ const node = this[index];
7
+ if (!node) {
8
+ /**
9
+ * ⚠ TYPE CONTRADICTION
10
+ *
11
+ * 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.
12
+ *
13
+ * @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-844377136
14
+ *
15
+ * > item
16
+ * > 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.
17
+ */
18
+ throw new ReferenceError('Invalid index');
19
+ }
20
+ return node;
10
21
  }
11
22
  }
12
- function toNodeList(nodes) {
23
+ export function toNodeList(nodes) {
13
24
  const nodeList = new MLNodeList(...nodes);
14
25
  return nodeList;
15
26
  }
16
- exports.toNodeList = toNodeList;
17
27
  class MLHTMLCollection extends Array {
18
28
  item(index) {
19
- return this[index];
29
+ return this[index] ?? null;
20
30
  }
21
31
  namedItem(name) {
22
- return this.find(el => el.getAttribute('name') === name) || null;
32
+ return this.find(el => el.getAttribute('name') === name) ?? null;
23
33
  }
24
34
  }
25
- function toHTMLCollection(nodes) {
35
+ export function toHTMLCollection(
36
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
37
+ nodes) {
26
38
  const collection = new MLHTMLCollection(...nodes);
27
39
  return collection;
28
40
  }
29
- exports.toHTMLCollection = toHTMLCollection;
30
- function nodeListToHTMLCollection(nodeList) {
41
+ export function nodeListToHTMLCollection(
42
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
43
+ nodeList) {
31
44
  const collection = new MLHTMLCollection();
32
45
  nodeList.forEach(node => {
33
46
  if (node.is(node.ELEMENT_NODE)) {
@@ -36,4 +49,3 @@ function nodeListToHTMLCollection(nodeList) {
36
49
  });
37
50
  return collection;
38
51
  }
39
- exports.nodeListToHTMLCollection = nodeListToHTMLCollection;
@@ -1,11 +1,11 @@
1
- import type { MLNode } from './node';
2
- import type { MappedNode } from './types';
1
+ import type { MLNode } from './node.js';
2
+ import type { MappedNode } from './types.js';
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
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;
7
+ getNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N): MappedNode<N, T, O>;
8
+ setNode<A extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: A, node: MLNode<T, O, A>): void;
9
9
  }
10
10
  /**
11
11
  * `NodeStore` Singleton
@@ -1,18 +1,23 @@
1
- "use strict";
2
1
  var _NodeStore_store;
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.nodeStore = void 0;
5
- const tslib_1 = require("tslib");
6
- const parser_utils_1 = require("@markuplint/parser-utils");
2
+ import { __classPrivateFieldGet } from "tslib";
3
+ import { TargetParserError } from '@markuplint/parser-utils';
4
+ import { log } from '../../debug.js';
5
+ const nodeStoreLog = log.extend('node-store');
6
+ const nodeStoreError = nodeStoreLog.extend('error');
7
7
  class NodeStore {
8
8
  constructor() {
9
9
  _NodeStore_store.set(this, new Map());
10
10
  }
11
11
  getNode(astNode) {
12
12
  // console.log(`Get: ${astNode.uuid} -> ${astNode.raw.trim()}(${astNode.type})`);
13
- const node = tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
13
+ const node = __classPrivateFieldGet(this, _NodeStore_store, "f").get(astNode.uuid);
14
14
  if (!node) {
15
- throw new parser_utils_1.ParserError('Broke mapping nodes.', {
15
+ nodeStoreError('Ref ID: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
16
+ nodeStoreError('Map: %O', Array.from(__classPrivateFieldGet(this, _NodeStore_store, "f").entries()).map(([id, node]) => ({
17
+ id,
18
+ name: node.nodeName,
19
+ })));
20
+ throw new TargetParserError('Broke mapping nodes.', {
16
21
  line: astNode.startLine,
17
22
  col: astNode.startCol,
18
23
  raw: astNode.raw,
@@ -21,12 +26,22 @@ class NodeStore {
21
26
  }
22
27
  return node;
23
28
  }
24
- setNode(astNode, node) {
25
- tslib_1.__classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
29
+ setNode(astNode,
30
+ // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
31
+ node) {
32
+ if (node.is(node.DOCUMENT_NODE)) {
33
+ return;
34
+ }
35
+ if (!astNode.uuid) {
36
+ nodeStoreError('UUID is invalid: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw);
37
+ nodeStoreError('Invalid node: %O', node);
38
+ }
39
+ nodeStoreLog('Mapped: %s (%s: "%s")', astNode.uuid, astNode.nodeName, astNode.raw.replace(/\n/g, '⏎').replace(/\t/g, '→'));
40
+ __classPrivateFieldGet(this, _NodeStore_store, "f").set(astNode.uuid, node);
26
41
  }
27
42
  }
28
43
  _NodeStore_store = new WeakMap();
29
44
  /**
30
45
  * `NodeStore` Singleton
31
46
  */
32
- exports.nodeStore = new NodeStore();
47
+ export const nodeStore = new NodeStore();
@@ -1,14 +1,14 @@
1
- import type { RuleInfo } from '../..';
2
- import type { MLBlock } from './block';
3
- import type { MLChildNode } from './child-node';
4
- import type { MLDocument } from './document';
5
- import type { MLDocumentFragment } from './document-fragment';
6
- import type { MLElement } from './element';
7
- import type { MarkuplintPreprocessorBlockType, NodeType, NodeTypeOf } from './types';
1
+ import type { MLBlock } from './block.js';
2
+ import type { MLChildNode } from './child-node.js';
3
+ import type { MLDocumentFragment } from './document-fragment.js';
4
+ import type { MLDocument } from './document.js';
5
+ import type { MLElement } from './element.js';
6
+ import type { MarkuplintPreprocessorBlockType, NodeType, NodeTypeOf } from './types.js';
7
+ import type { RuleInfo } from '../../index.js';
8
8
  import type { MLASTAbstractNode } from '@markuplint/ml-ast';
9
- import type { AnyRule, RuleConfigValue } from '@markuplint/ml-config';
10
- import { MLToken } from '../token/token';
11
- export declare abstract class MLNode<T extends RuleConfigValue, O = null, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLToken<A> implements Node {
9
+ import type { AnyRule, PlainData, RuleConfigValue } from '@markuplint/ml-config';
10
+ import { MLToken } from '../token/token.js';
11
+ export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainData = undefined, A extends MLASTAbstractNode = MLASTAbstractNode> extends MLToken<A> implements Node {
12
12
  #private;
13
13
  /**
14
14
  * @implements DOM API: `Node`
@@ -136,7 +136,7 @@ export declare abstract class MLNode<T extends RuleConfigValue, O = null, A exte
136
136
  * @implements DOM API: `Node`
137
137
  * @see https://dom.spec.whatwg.org/#ref-for-dom-node-firstchild%E2%91%A0
138
138
  */
139
- get firstChild(): MLChildNode<T, O>;
139
+ get firstChild(): MLChildNode<T, O> | null;
140
140
  /**
141
141
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
142
142
  *
@@ -152,7 +152,7 @@ export declare abstract class MLNode<T extends RuleConfigValue, O = null, A exte
152
152
  * @implements DOM API: `Node`
153
153
  * @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
154
154
  */
155
- get lastChild(): MLChildNode<T, O>;
155
+ get lastChild(): MLChildNode<T, O> | null;
156
156
  /**
157
157
  * @implements `@markuplint/ml-core` API: `MLNode`
158
158
  */