@markuplint/ml-core 4.0.0-alpha.1 → 4.0.0-alpha.10

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 (61) hide show
  1. package/LICENSE +1 -1
  2. package/lib/configs.browser.js +10 -6
  3. package/lib/convert-ruleset.d.ts +1 -1
  4. package/lib/convert-ruleset.js +1 -1
  5. package/lib/index.d.ts +3 -3
  6. package/lib/index.js +2 -3
  7. package/lib/ml-core.d.ts +2 -2
  8. package/lib/ml-core.js +44 -20
  9. package/lib/ml-dom/helper/accname.js +3 -3
  10. package/lib/ml-dom/helper/create-node.d.ts +2 -2
  11. package/lib/ml-dom/helper/create-node.js +32 -7
  12. package/lib/ml-dom/helper/debug.js +11 -15
  13. package/lib/ml-dom/helper/{getIndent.js → get-indent.js} +14 -4
  14. package/lib/ml-dom/helper/walkers.js +1 -1
  15. package/lib/ml-dom/manipulations/child-node-methods.js +1 -1
  16. package/lib/ml-dom/manipulations/get-children.js +1 -1
  17. package/lib/ml-dom/node/attr.d.ts +18 -0
  18. package/lib/ml-dom/node/attr.js +80 -32
  19. package/lib/ml-dom/node/block.js +1 -3
  20. package/lib/ml-dom/node/character-data.d.ts +2 -2
  21. package/lib/ml-dom/node/character-data.js +1 -1
  22. package/lib/ml-dom/node/child-node.d.ts +2 -2
  23. package/lib/ml-dom/node/document-fragment.d.ts +2 -2
  24. package/lib/ml-dom/node/document-fragment.js +1 -1
  25. package/lib/ml-dom/node/document-type.js +1 -3
  26. package/lib/ml-dom/node/document.d.ts +7 -5
  27. package/lib/ml-dom/node/document.js +105 -39
  28. package/lib/ml-dom/node/dom-token-list.js +15 -5
  29. package/lib/ml-dom/node/element-close-tag.d.ts +20 -0
  30. package/lib/ml-dom/node/element-close-tag.js +39 -0
  31. package/lib/ml-dom/node/element.d.ts +51 -6
  32. package/lib/ml-dom/node/element.js +139 -62
  33. package/lib/ml-dom/node/named-node-map.js +1 -1
  34. package/lib/ml-dom/node/node-list.js +2 -2
  35. package/lib/ml-dom/node/node-store.d.ts +3 -3
  36. package/lib/ml-dom/node/node-store.js +7 -3
  37. package/lib/ml-dom/node/node.d.ts +2 -2
  38. package/lib/ml-dom/node/node.js +31 -13
  39. package/lib/ml-dom/node/parent-node.d.ts +2 -2
  40. package/lib/ml-dom/node/parent-node.js +13 -3
  41. package/lib/ml-dom/node/rule-mapper.js +17 -7
  42. package/lib/ml-dom/node/text.js +3 -3
  43. package/lib/ml-dom/node/types.d.ts +23 -3
  44. package/lib/ml-dom/node/unexpected-call-error.d.ts +1 -1
  45. package/lib/ml-dom/node/unexpected-call-error.js +1 -1
  46. package/lib/ml-dom/token/token.d.ts +3 -3
  47. package/lib/ml-dom/token/token.js +16 -6
  48. package/lib/ml-rule/ml-rule-context.js +6 -2
  49. package/lib/ml-rule/ml-rule.d.ts +1 -1
  50. package/lib/ml-rule/ml-rule.js +12 -2
  51. package/lib/ml-rule/types.d.ts +3 -0
  52. package/lib/ruleset/index.d.ts +1 -1
  53. package/lib/ruleset/index.js +1 -1
  54. package/lib/test/index.d.ts +6 -4
  55. package/lib/test/index.js +7 -3
  56. package/lib/types.d.ts +3 -3
  57. package/lib/utils/get-location-from-chars.js +3 -3
  58. package/package.json +13 -14
  59. package/lib/configs.d.ts +0 -2
  60. package/lib/configs.js +0 -37
  61. /package/lib/ml-dom/helper/{getIndent.d.ts → get-indent.d.ts} +0 -0
@@ -1,5 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
1
12
  var _RuleMapper_nodeList, _RuleMapper_ruleMap;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
13
  import { compareSpecificity } from '@markuplint/selector';
4
14
  import { log as coreLog } from '../../debug.js';
5
15
  const ruleMapperLog = coreLog.extend('rule-mapper');
@@ -15,21 +25,21 @@ export class RuleMapper {
15
25
  }
16
26
  apply() {
17
27
  ruleMapperLog('ruleTree:');
18
- __classPrivateFieldGet(this, _RuleMapper_nodeList, "f").forEach(node => {
28
+ for (const node of __classPrivateFieldGet(this, _RuleMapper_nodeList, "f")) {
19
29
  const rules = __classPrivateFieldGet(this, _RuleMapper_ruleMap, "f").get(node.uuid);
20
30
  if (!rules) {
21
- return;
31
+ continue;
22
32
  }
23
33
  ruleMapperNodeLog('<%s>', node.nodeName);
24
- Object.keys(rules).forEach(ruleName => {
34
+ for (const ruleName of Object.keys(rules)) {
25
35
  const rule = rules[ruleName];
26
36
  if (!rule) {
27
- return;
37
+ continue;
28
38
  }
29
39
  node.rules[ruleName] = rule.rule;
30
40
  ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
31
- });
32
- });
41
+ }
42
+ }
33
43
  }
34
44
  set(
35
45
  // eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
@@ -1,11 +1,11 @@
1
1
  import { MLCharacterData } from './character-data.js';
2
- import UnexpectedCallError from './unexpected-call-error.js';
2
+ import { UnexpectedCallError } from './unexpected-call-error.js';
3
3
  /**
4
4
  * Raw text elements
5
5
  *
6
6
  * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
7
7
  */
8
- const rawTextElements = ['script', 'style'];
8
+ const rawTextElements = new Set(['script', 'style']);
9
9
  export class MLText extends MLCharacterData {
10
10
  /**
11
11
  * **IT THROWS AN ERROR WHEN CALLING THIS.**
@@ -50,7 +50,7 @@ export class MLText extends MLCharacterData {
50
50
  * @see https://html.spec.whatwg.org/multipage/syntax.html#raw-text-elements
51
51
  */
52
52
  isRawTextElementContent() {
53
- return this.parentElement ? rawTextElements.includes(this.parentElement.nodeName.toLowerCase()) : false;
53
+ return this.parentElement ? rawTextElements.has(this.parentElement.nodeName.toLowerCase()) : false;
54
54
  }
55
55
  /**
56
56
  * @implements `@markuplint/ml-core` API: `MLText`
@@ -5,12 +5,11 @@ import type { MLDocumentFragment } from './document-fragment.js';
5
5
  import type { MLDocumentType } from './document-type.js';
6
6
  import type { MLDocument } from './document.js';
7
7
  import type { MLElement } from './element.js';
8
- import type { MLNode } from './node.js';
9
8
  import type { MLText } from './text.js';
10
9
  import type { MLToken } from '../token/token.js';
11
- import type { MLASTAbstractNode, MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLToken as MLASTToken } from '@markuplint/ml-ast/';
10
+ import type { MLASTAttr, MLASTComment, MLASTDoctype, MLASTElement, MLASTInvalid, MLASTParentNode, MLASTPreprocessorSpecificBlock, MLASTText, MLASTToken as MLASTToken } from '@markuplint/ml-ast/';
12
11
  import type { PlainData, PretenderARIA, RuleConfigValue } from '@markuplint/ml-config';
13
- export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAbstractNode ? MLNode<T, O, MLASTAbstractNode> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTToken ? MLToken : never;
12
+ export type MappedNode<N, T extends RuleConfigValue, O extends PlainData = undefined> = N extends MLASTElement ? MLElement<T, O> : N extends MLASTParentNode ? MLElement<T, O> : N extends MLASTComment ? MLComment<T, O> : N extends MLASTText ? MLText<T, O> : N extends MLASTDoctype ? MLDocumentType<T, O> : N extends MLASTPreprocessorSpecificBlock ? MLBlock<T, O> : N extends MLASTAttr ? MLAttr<T, O> : N extends MLASTInvalid ? MLText<T, O> : N extends MLASTToken ? MLToken : never;
14
13
  export type NodeTypeOf<NT extends NodeType, T extends RuleConfigValue, O extends PlainData = undefined> = NT extends ElementNodeType ? MLElement<T, O> : NT extends CommentNodeType ? MLComment<T, O> : NT extends TextNodeType ? MLText<T, O> : NT extends DocumentNodeType ? MLDocument<T, O> : NT extends DocumentTypeNodeType ? MLDocumentType<T, O> : NT extends DocumentFragmentNodeType ? MLDocumentFragment<T, O> : NT extends MarkuplintPreprocessorBlockType ? MLBlock<T, O> : NT extends AttributeNodeType ? MLAttr<T, O> : never;
15
14
  export type ElementNodeType = 1;
16
15
  export type AttributeNodeType = 2;
@@ -33,3 +32,24 @@ export type PretenderContextPretended<N extends MLElement<T, O>, T extends RuleC
33
32
  readonly type: 'origin';
34
33
  readonly origin: N;
35
34
  };
35
+ export type AccessibilityProperties = ClearlyAccessibilityProperties | UnknownAccessibilityProperties;
36
+ export type ClearlyAccessibilityProperties = {
37
+ unknown: false;
38
+ exposedToTree: boolean;
39
+ role?: string;
40
+ roleDescription?: string;
41
+ name?: string | {
42
+ unknown: true;
43
+ };
44
+ nameRequired?: boolean;
45
+ nameProhibited?: boolean;
46
+ focusable?: boolean;
47
+ props?: Record<string, AccessibilityProperty>;
48
+ };
49
+ export type UnknownAccessibilityProperties = {
50
+ unknown: true;
51
+ };
52
+ export type AccessibilityProperty = {
53
+ value: string | null;
54
+ required: boolean;
55
+ };
@@ -1,2 +1,2 @@
1
- export default class UnexpectedCallError extends Error {
1
+ export declare class UnexpectedCallError extends Error {
2
2
  }
@@ -1,2 +1,2 @@
1
- export default class UnexpectedCallError extends Error {
1
+ export class UnexpectedCallError extends Error {
2
2
  }
@@ -1,4 +1,4 @@
1
- import type { MLToken as MLASTToken } from '@markuplint/ml-ast';
1
+ import type { MLASTToken } from '@markuplint/ml-ast';
2
2
  export declare class MLToken<A extends MLASTToken = MLASTToken> {
3
3
  #private;
4
4
  readonly uuid: string;
@@ -19,7 +19,7 @@ export declare class MLToken<A extends MLASTToken = MLASTToken> {
19
19
  /**
20
20
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
21
21
  */
22
- get originRaw(): string;
22
+ get fixed(): string;
23
23
  /**
24
24
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
25
25
  */
@@ -43,5 +43,5 @@ export declare class MLToken<A extends MLASTToken = MLASTToken> {
43
43
  /**
44
44
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
45
45
  */
46
- toString(): string;
46
+ toString(fixed?: boolean): string;
47
47
  }
@@ -1,5 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
1
12
  var _MLToken_endCol, _MLToken_endLine, _MLToken_endOffset, _MLToken_fixed, _MLToken_raw, _MLToken_startCol, _MLToken_startLine, _MLToken_startOffset;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
13
  export class MLToken {
4
14
  constructor(astToken) {
5
15
  _MLToken_endCol.set(this, void 0);
@@ -42,14 +52,14 @@ export class MLToken {
42
52
  /**
43
53
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
44
54
  */
45
- get originRaw() {
46
- return __classPrivateFieldGet(this, _MLToken_raw, "f");
55
+ get fixed() {
56
+ return __classPrivateFieldGet(this, _MLToken_fixed, "f");
47
57
  }
48
58
  /**
49
59
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
50
60
  */
51
61
  get raw() {
52
- return __classPrivateFieldGet(this, _MLToken_fixed, "f");
62
+ return __classPrivateFieldGet(this, _MLToken_raw, "f");
53
63
  }
54
64
  /**
55
65
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
@@ -78,8 +88,8 @@ export class MLToken {
78
88
  /**
79
89
  * @implements `@markuplint/ml-core` API: `MLDOMToken`
80
90
  */
81
- toString() {
82
- return this.raw;
91
+ toString(fixed = false) {
92
+ return fixed ? __classPrivateFieldGet(this, _MLToken_fixed, "f") : __classPrivateFieldGet(this, _MLToken_raw, "f");
83
93
  }
84
94
  }
85
95
  _MLToken_endCol = new WeakMap(), _MLToken_endLine = new WeakMap(), _MLToken_endOffset = new WeakMap(), _MLToken_fixed = new WeakMap(), _MLToken_raw = new WeakMap(), _MLToken_startCol = new WeakMap(), _MLToken_startLine = new WeakMap(), _MLToken_startOffset = new WeakMap();
@@ -1,5 +1,9 @@
1
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
+ };
1
6
  var _MLRuleContext_reports;
2
- import { __classPrivateFieldGet } from "tslib";
3
7
  import { translator } from '@markuplint/i18n';
4
8
  export class MLRuleContext {
5
9
  constructor(
@@ -37,7 +41,7 @@ export class MLRuleContext {
37
41
  this._push(report);
38
42
  }
39
43
  _push(report) {
40
- if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").find(r => is(r, report))) {
44
+ if (!__classPrivateFieldGet(this, _MLRuleContext_reports, "f").some(r => is(r, report))) {
41
45
  __classPrivateFieldGet(this, _MLRuleContext_reports, "f").push(report);
42
46
  }
43
47
  }
@@ -1,6 +1,6 @@
1
1
  import type { RuleSeed } from './types.js';
2
2
  import type { MLDocument } from '../ml-dom/node/document.js';
3
- import type Ruleset from '../ruleset/index.js';
3
+ import type { Ruleset } from '../ruleset/index.js';
4
4
  import type { LocaleSet } from '@markuplint/i18n';
5
5
  import type { GlobalRuleInfo, PlainData, Rule, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
6
6
  export declare class MLRule<T extends RuleConfigValue, O extends PlainData = undefined> {
@@ -1,5 +1,15 @@
1
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
2
+ if (kind === "m") throw new TypeError("Private method is not writable");
3
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
4
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
5
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
6
+ };
7
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
8
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
9
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
+ };
1
12
  var _MLRule_f, _MLRule_v;
2
- import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
3
13
  import { deleteUndefProp } from '@markuplint/ml-config';
4
14
  // @ts-ignore
5
15
  import { isPlainObject } from 'is-plain-object';
@@ -11,7 +21,7 @@ export class MLRule {
11
21
  this.name = o.name;
12
22
  this.defaultSeverity = o.defaultSeverity ?? 'error';
13
23
  // TODO: https://github.com/markuplint/markuplint/issues/808
14
- this.defaultValue = (o.defaultValue !== undefined ? o.defaultValue : true);
24
+ this.defaultValue = (o.defaultValue === undefined ? true : o.defaultValue);
15
25
  this.defaultOptions = o.defaultOptions;
16
26
  __classPrivateFieldSet(this, _MLRule_v, o.verify, "f");
17
27
  __classPrivateFieldSet(this, _MLRule_f, o.fix, "f");
@@ -3,6 +3,9 @@ import type { Attr, Element } from '../ml-dom/index.js';
3
3
  import type { Translator } from '@markuplint/i18n';
4
4
  import type { PlainData, Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
5
5
  export type RuleSeed<T extends RuleConfigValue = boolean, O extends PlainData = undefined> = {
6
+ readonly meta?: {
7
+ readonly category?: 'validation' | 'style' | 'naming-convention' | 'a11y' | 'maintainability';
8
+ };
6
9
  readonly defaultSeverity?: Severity;
7
10
  readonly defaultValue?: T;
8
11
  readonly defaultOptions?: O;
@@ -1,5 +1,5 @@
1
1
  import type { ChildNodeRule, Config, NodeRule, Rules } from '@markuplint/ml-config';
2
- export default class Ruleset {
2
+ export declare class Ruleset {
3
3
  readonly childNodeRules: readonly ChildNodeRule[];
4
4
  readonly nodeRules: readonly NodeRule[];
5
5
  readonly rules: Rules;
@@ -1,4 +1,4 @@
1
- export default class Ruleset {
1
+ export class Ruleset {
2
2
  constructor(config) {
3
3
  this.rules = config.rules ?? {};
4
4
  this.nodeRules = config.nodeRules ?? [];
@@ -1,15 +1,17 @@
1
- import type { MLMarkupLanguageParser } from '@markuplint/ml-ast';
1
+ import type { MLParser } from '@markuplint/ml-ast';
2
2
  import type { Config, PlainData, RuleConfigValue } from '@markuplint/ml-config';
3
3
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
4
4
  import { Document } from '../ml-dom/index.js';
5
5
  export type CreateTestOptions = {
6
6
  readonly config?: Config;
7
- readonly parser?: Readonly<MLMarkupLanguageParser>;
7
+ readonly parser?: {
8
+ readonly parser: Readonly<MLParser>;
9
+ } | Readonly<MLParser>;
8
10
  readonly specs?: MLMLSpec;
9
11
  };
10
12
  export declare function createTestDocument<T extends RuleConfigValue = any, O extends PlainData = any>(sourceCode: string, options?: CreateTestOptions): Document<T, O>;
11
- export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTAbstractNode>[];
12
- export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLToken>[];
13
+ export declare function createTestNodeList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/node/node.js").MLNode<any, any, import("@markuplint/ml-ast").MLASTNode>[];
14
+ export declare function createTestTokenList(sourceCode: string, options?: CreateTestOptions): readonly import("../ml-dom/token/token.js").MLToken<import("@markuplint/ml-ast").MLASTToken>[];
13
15
  export declare function createTestElement(sourceCode: string, options?: CreateTestOptions): import("../ml-dom/index.js").Element<any, any>;
14
16
  /**
15
17
  * for test suite
package/lib/test/index.js CHANGED
@@ -1,9 +1,13 @@
1
- import { parse } from '@markuplint/html-parser';
1
+ import { parser } from '@markuplint/html-parser';
2
2
  import spec from '@markuplint/html-spec';
3
3
  import { convertRuleset } from '../convert-ruleset.js';
4
4
  import { Document } from '../ml-dom/index.js';
5
5
  export function createTestDocument(sourceCode, options) {
6
- const ast = options?.parser ? options.parser.parse(sourceCode) : parse(sourceCode);
6
+ const ast = options?.parser
7
+ ? 'parser' in options.parser
8
+ ? options.parser.parser.parse(sourceCode, options.config?.parserOptions)
9
+ : options.parser.parse(sourceCode, options.config?.parserOptions)
10
+ : parser.parse(sourceCode, options?.config?.parserOptions);
7
11
  const ruleset = convertRuleset(options?.config);
8
12
  const document = new Document(ast, ruleset, [options?.specs ?? {}, {}]);
9
13
  return document;
@@ -22,7 +26,7 @@ export function createTestElement(sourceCode, options) {
22
26
  if (el && el.is(el.ELEMENT_NODE)) {
23
27
  return el;
24
28
  }
25
- throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
29
+ throw new TypeError(`Could not parse it to be an element from: ${sourceCode}`);
26
30
  }
27
31
  /**
28
32
  * for test suite
package/lib/types.d.ts CHANGED
@@ -1,12 +1,12 @@
1
1
  import type { AnyMLRule } from './ml-rule/index.js';
2
- import type Ruleset from './ruleset/index.js';
2
+ import type { Ruleset } from './ruleset/index.js';
3
3
  import type { LocaleSet } from '@markuplint/i18n';
4
- import type { MLMarkupLanguageParser, ParserOptions } from '@markuplint/ml-ast';
4
+ import type { MLParser, ParserOptions } from '@markuplint/ml-ast';
5
5
  import type { Pretender } from '@markuplint/ml-config';
6
6
  import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
7
7
  export type MLSchema = readonly [MLMLSpec, ...ExtendedSpec[]];
8
8
  export type MLFabric = {
9
- readonly parser: Readonly<MLMarkupLanguageParser>;
9
+ readonly parser: Readonly<MLParser>;
10
10
  readonly ruleset: Partial<Readonly<Ruleset>>;
11
11
  readonly rules: readonly Readonly<AnyMLRule>[];
12
12
  readonly locale: LocaleSet;
@@ -1,7 +1,7 @@
1
1
  export function getLocationFromChars(searches, text, currentLine, currentCol) {
2
- const lines = text.split(/\r?\n/g);
2
+ const lines = text.split(/\r?\n/);
3
3
  const foundLocations = [];
4
- lines.forEach((lineText, i) => {
4
+ for (const [i, lineText] of lines.entries()) {
5
5
  let offset = 0;
6
6
  for (const char of lineText) {
7
7
  if (searches.includes(char)) {
@@ -19,6 +19,6 @@ export function getLocationFromChars(searches, text, currentLine, currentCol) {
19
19
  }
20
20
  offset++;
21
21
  }
22
- });
22
+ }
23
23
  return foundLocations;
24
24
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@markuplint/ml-core",
3
- "version": "4.0.0-alpha.1",
3
+ "version": "4.0.0-alpha.10",
4
4
  "description": "The core module of markuplint",
5
5
  "repository": "git@github.com:markuplint/markuplint.git",
6
6
  "author": "Yusuke Hirao <yusukehirao@me.com>",
@@ -28,20 +28,19 @@
28
28
  "./lib/configs.js": "./lib/configs.browser.js"
29
29
  },
30
30
  "dependencies": {
31
- "@markuplint/config-presets": "4.0.0-alpha.1",
32
- "@markuplint/html-parser": "4.0.0-alpha.1",
33
- "@markuplint/html-spec": "4.0.0-alpha.1",
34
- "@markuplint/i18n": "4.0.0-alpha.1",
35
- "@markuplint/ml-ast": "4.0.0-alpha.1",
36
- "@markuplint/ml-config": "4.0.0-alpha.1",
37
- "@markuplint/ml-spec": "4.0.0-alpha.1",
38
- "@markuplint/parser-utils": "4.0.0-alpha.1",
39
- "@markuplint/selector": "4.0.0-alpha.1",
40
- "@types/debug": "^4.1.8",
31
+ "@markuplint/config-presets": "4.0.0-alpha.10",
32
+ "@markuplint/html-parser": "4.0.0-alpha.10",
33
+ "@markuplint/html-spec": "4.0.0-alpha.10",
34
+ "@markuplint/i18n": "4.0.0-alpha.10",
35
+ "@markuplint/ml-ast": "4.0.0-alpha.10",
36
+ "@markuplint/ml-config": "4.0.0-alpha.10",
37
+ "@markuplint/ml-spec": "4.0.0-alpha.10",
38
+ "@markuplint/parser-utils": "4.0.0-alpha.10",
39
+ "@markuplint/selector": "4.0.0-alpha.10",
40
+ "@types/debug": "^4.1.12",
41
41
  "debug": "^4.3.4",
42
42
  "is-plain-object": "^5.0.0",
43
- "tslib": "^2.6.1",
44
- "type-fest": "^4.1.0"
43
+ "type-fest": "^4.10.1"
45
44
  },
46
- "gitHead": "22502ee22a378ae766033d687dbc0443e5ed35dc"
45
+ "gitHead": "b41153ea665aa8f091daf6114a06047f4ccb8350"
47
46
  }
package/lib/configs.d.ts DELETED
@@ -1,2 +0,0 @@
1
- import type { Config } from '@markuplint/ml-config';
2
- export declare function getPreset(name: string): Promise<Config>;
package/lib/configs.js DELETED
@@ -1,37 +0,0 @@
1
- import { readFile } from 'node:fs/promises';
2
- import path from 'node:path';
3
- import { log } from './debug.js';
4
- export async function getPreset(name) {
5
- const json = await forceImportJsonInModule(`@markuplint/config-presets/preset.${name}.json`);
6
- if (json instanceof Error) {
7
- throw new ReferenceError(`Preset markuplint:${name} is not found`);
8
- }
9
- return json;
10
- }
11
- async function forceImportJsonInModule(modPath) {
12
- const error = await import(modPath).catch(error => error);
13
- if (error instanceof Error) {
14
- log('Error in forceImportJsonInModule: %O', error);
15
- if (!('code' in error)) {
16
- throw error;
17
- }
18
- if (error.code !== 'ERR_IMPORT_ASSERTION_TYPE_MISSING') {
19
- throw error;
20
- }
21
- const searchPath = /Module\s"([^"]+)"\sneeds/i.exec(error.message);
22
- const absPath = searchPath?.[1] ?? null;
23
- log('Extract path: %s', absPath);
24
- if (!absPath) {
25
- throw error;
26
- }
27
- const normalizePath = absPath
28
- .replace(/^file:\/\//, '')
29
- .replace(/\//g, path.sep)
30
- // Windows
31
- .replace(/^[\\/][a-z]:/i, '');
32
- log('Find JSON file path: %s', normalizePath);
33
- const fileContent = await readFile(normalizePath, { encoding: 'utf8' });
34
- return JSON.parse(fileContent);
35
- }
36
- return error.default ? error.default : error;
37
- }