@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.
- package/lib/configs.browser.js +1 -5
- package/lib/configs.js +33 -31
- package/lib/convert-ruleset.d.ts +1 -1
- package/lib/convert-ruleset.js +3 -8
- package/lib/debug.js +9 -14
- package/lib/index.d.ts +13 -12
- package/lib/index.js +13 -29
- package/lib/ml-core.d.ts +7 -7
- package/lib/ml-core.js +60 -66
- package/lib/ml-dom/helper/accname.d.ts +1 -1
- package/lib/ml-dom/helper/accname.js +23 -19
- package/lib/ml-dom/helper/create-node.d.ts +4 -4
- package/lib/ml-dom/helper/create-node.js +13 -15
- package/lib/ml-dom/helper/debug.d.ts +1 -1
- package/lib/ml-dom/helper/debug.js +8 -8
- package/lib/ml-dom/helper/getIndent.d.ts +2 -2
- package/lib/ml-dom/helper/getIndent.js +30 -28
- package/lib/ml-dom/helper/walkers.d.ts +6 -6
- package/lib/ml-dom/helper/walkers.js +23 -22
- package/lib/ml-dom/index.d.ts +9 -9
- package/lib/ml-dom/index.js +1 -5
- package/lib/ml-dom/manipulations/child-node-methods.d.ts +9 -9
- package/lib/ml-dom/manipulations/child-node-methods.js +31 -25
- package/lib/ml-dom/manipulations/get-children.d.ts +4 -4
- package/lib/ml-dom/manipulations/get-children.js +5 -7
- package/lib/ml-dom/node/attr.d.ts +7 -7
- package/lib/ml-dom/node/attr.js +33 -34
- package/lib/ml-dom/node/block.d.ts +6 -6
- package/lib/ml-dom/node/block.js +21 -15
- package/lib/ml-dom/node/character-data.d.ts +4 -4
- package/lib/ml-dom/node/character-data.js +20 -19
- package/lib/ml-dom/node/child-node.d.ts +9 -9
- package/lib/ml-dom/node/child-node.js +3 -5
- package/lib/ml-dom/node/comment.d.ts +4 -4
- package/lib/ml-dom/node/comment.js +2 -6
- package/lib/ml-dom/node/document-fragment.d.ts +4 -4
- package/lib/ml-dom/node/document-fragment.js +4 -9
- package/lib/ml-dom/node/document-type.d.ts +6 -6
- package/lib/ml-dom/node/document-type.js +21 -15
- package/lib/ml-dom/node/document.d.ts +32 -29
- package/lib/ml-dom/node/document.js +329 -246
- package/lib/ml-dom/node/dom-token-list.d.ts +3 -3
- package/lib/ml-dom/node/dom-token-list.js +29 -33
- package/lib/ml-dom/node/element.d.ts +65 -16
- package/lib/ml-dom/node/element.js +396 -306
- package/lib/ml-dom/node/named-node-map.d.ts +4 -4
- package/lib/ml-dom/node/named-node-map.js +18 -18
- package/lib/ml-dom/node/node-list.d.ts +6 -6
- package/lib/ml-dom/node/node-list.js +25 -13
- package/lib/ml-dom/node/node-store.d.ts +5 -5
- package/lib/ml-dom/node/node-store.js +25 -10
- package/lib/ml-dom/node/node.d.ts +12 -12
- package/lib/ml-dom/node/node.js +101 -76
- package/lib/ml-dom/node/parent-node.d.ts +6 -6
- package/lib/ml-dom/node/parent-node.js +31 -29
- package/lib/ml-dom/node/rule-mapper.d.ts +5 -5
- package/lib/ml-dom/node/rule-mapper.js +20 -17
- package/lib/ml-dom/node/text.d.ts +4 -4
- package/lib/ml-dom/node/text.js +6 -11
- package/lib/ml-dom/node/types.d.ts +30 -16
- package/lib/ml-dom/node/types.js +1 -2
- package/lib/ml-dom/node/unexpected-call-error.js +1 -4
- package/lib/ml-dom/token/token.js +19 -23
- package/lib/ml-rule/create-rule.d.ts +3 -3
- package/lib/ml-rule/create-rule.js +1 -5
- package/lib/ml-rule/create-test-rule.d.ts +5 -5
- package/lib/ml-rule/create-test-rule.js +3 -7
- package/lib/ml-rule/index.d.ts +3 -3
- package/lib/ml-rule/index.js +3 -6
- package/lib/ml-rule/ml-rule-context.d.ts +4 -4
- package/lib/ml-rule/ml-rule-context.js +11 -13
- package/lib/ml-rule/ml-rule.d.ts +9 -9
- package/lib/ml-rule/ml-rule.js +48 -45
- package/lib/ml-rule/types.d.ts +12 -12
- package/lib/ml-rule/types.js +1 -2
- package/lib/plugin/index.d.ts +2 -2
- package/lib/plugin/index.js +2 -5
- package/lib/plugin/plugin.d.ts +2 -2
- package/lib/plugin/plugin.js +1 -5
- package/lib/plugin/types.d.ts +6 -6
- package/lib/plugin/types.js +1 -2
- package/lib/ruleset/index.d.ts +3 -3
- package/lib/ruleset/index.js +4 -8
- package/lib/test/index.d.ts +9 -9
- package/lib/test/index.js +14 -24
- package/lib/types.d.ts +11 -10
- package/lib/types.js +1 -2
- package/lib/utils/get-location-from-chars.d.ts +1 -1
- package/lib/utils/get-location-from-chars.js +1 -5
- package/lib/utils/index.d.ts +1 -1
- package/lib/utils/index.js +1 -5
- package/lib/utils/string-splice.js +1 -5
- package/package.json +25 -16
- package/tsconfig.test.json +0 -3
- package/tsconfig.tsbuildinfo +0 -1
package/lib/configs.browser.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPreset = void 0;
|
|
4
|
-
async function getPreset(name) {
|
|
1
|
+
export async function getPreset(name) {
|
|
5
2
|
const res = await fetch(`@markuplint/config-presets/preset.${name}.json`).catch(() => new Error());
|
|
6
3
|
if (res instanceof Error) {
|
|
7
4
|
throw new ReferenceError(`Preset markuplint:${name} is not found`);
|
|
@@ -9,4 +6,3 @@ async function getPreset(name) {
|
|
|
9
6
|
const json = await res.json();
|
|
10
7
|
return json;
|
|
11
8
|
}
|
|
12
|
-
exports.getPreset = getPreset;
|
package/lib/configs.js
CHANGED
|
@@ -1,35 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var _a;
|
|
26
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
27
|
-
exports.getPreset = void 0;
|
|
28
|
-
async function getPreset(name) {
|
|
29
|
-
const json = await (_a = `@markuplint/config-presets/preset.${name}.json`, Promise.resolve().then(() => __importStar(require(_a)))).catch(() => new Error());
|
|
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`);
|
|
30
6
|
if (json instanceof Error) {
|
|
31
7
|
throw new ReferenceError(`Preset markuplint:${name} is not found`);
|
|
32
8
|
}
|
|
33
|
-
return json
|
|
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;
|
|
34
37
|
}
|
|
35
|
-
exports.getPreset = getPreset;
|
package/lib/convert-ruleset.d.ts
CHANGED
package/lib/convert-ruleset.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const ruleset_1 = tslib_1.__importDefault(require("./ruleset"));
|
|
6
|
-
function convertRuleset(config = {}) {
|
|
7
|
-
return new ruleset_1.default(config);
|
|
1
|
+
import Ruleset from './ruleset/index.js';
|
|
2
|
+
export function convertRuleset(config = {}) {
|
|
3
|
+
return new Ruleset(config);
|
|
8
4
|
}
|
|
9
|
-
exports.convertRuleset = convertRuleset;
|
package/lib/debug.js
CHANGED
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.enableDebug = exports.log = void 0;
|
|
4
|
-
const tslib_1 = require("tslib");
|
|
5
|
-
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
1
|
+
import debug from 'debug';
|
|
6
2
|
const CLI_NS = 'markuplint-cli';
|
|
7
|
-
|
|
8
|
-
function enableDebug() {
|
|
9
|
-
if (!
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (!
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
export const log = debug('ml-core');
|
|
4
|
+
export function enableDebug() {
|
|
5
|
+
if (!log.enabled) {
|
|
6
|
+
debug.enable(`${log.namespace}*`);
|
|
7
|
+
log(`Debug enable: ${log.namespace}`);
|
|
8
|
+
if (!debug.enabled(CLI_NS)) {
|
|
9
|
+
debug.enable(`${log.namespace}*,${CLI_NS}*`);
|
|
10
|
+
log(`Debug enable: ${log.namespace}, ${CLI_NS}`);
|
|
15
11
|
}
|
|
16
12
|
}
|
|
17
13
|
}
|
|
18
|
-
exports.enableDebug = enableDebug;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
export { RuleInfo, RuleConfig, RuleConfigValue } from '@markuplint/ml-config';
|
|
2
2
|
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
3
|
-
export { default as Ruleset } from './ruleset';
|
|
4
|
-
export { enableDebug } from './debug';
|
|
5
|
-
export { getIndent } from './ml-dom/helper/getIndent';
|
|
6
|
-
export * from './configs';
|
|
7
|
-
export * from './convert-ruleset';
|
|
8
|
-
export * from './ml-core';
|
|
9
|
-
export * from './ml-dom';
|
|
10
|
-
export * from './ml-rule';
|
|
11
|
-
export * from './plugin';
|
|
12
|
-
export * from './test';
|
|
13
|
-
export * from './types';
|
|
14
|
-
export * from './utils';
|
|
3
|
+
export { default as Ruleset } from './ruleset/index.js';
|
|
4
|
+
export { enableDebug } from './debug.js';
|
|
5
|
+
export { getIndent } from './ml-dom/helper/getIndent.js';
|
|
6
|
+
export * from './configs.js';
|
|
7
|
+
export * from './convert-ruleset.js';
|
|
8
|
+
export * from './ml-core.js';
|
|
9
|
+
export * from './ml-dom/index.js';
|
|
10
|
+
export * from './ml-rule/index.js';
|
|
11
|
+
export * from './plugin/index.js';
|
|
12
|
+
export * from './test/index.js';
|
|
13
|
+
export * from './types.js';
|
|
14
|
+
export * from './utils/index.js';
|
|
15
|
+
export { AccessibilityProperties } from './ml-dom/node/types.js';
|
package/lib/index.js
CHANGED
|
@@ -1,29 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.defineProperty(exports, "resolveNamespace", { enumerable: true, get: function () { return ml_spec_1.resolveNamespace; } });
|
|
15
|
-
var ruleset_1 = require("./ruleset");
|
|
16
|
-
Object.defineProperty(exports, "Ruleset", { enumerable: true, get: function () { return tslib_1.__importDefault(ruleset_1).default; } });
|
|
17
|
-
var debug_1 = require("./debug");
|
|
18
|
-
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return debug_1.enableDebug; } });
|
|
19
|
-
var getIndent_1 = require("./ml-dom/helper/getIndent");
|
|
20
|
-
Object.defineProperty(exports, "getIndent", { enumerable: true, get: function () { return getIndent_1.getIndent; } });
|
|
21
|
-
tslib_1.__exportStar(require("./configs"), exports);
|
|
22
|
-
tslib_1.__exportStar(require("./convert-ruleset"), exports);
|
|
23
|
-
tslib_1.__exportStar(require("./ml-core"), exports);
|
|
24
|
-
tslib_1.__exportStar(require("./ml-dom"), exports);
|
|
25
|
-
tslib_1.__exportStar(require("./ml-rule"), exports);
|
|
26
|
-
tslib_1.__exportStar(require("./plugin"), exports);
|
|
27
|
-
tslib_1.__exportStar(require("./test"), exports);
|
|
28
|
-
tslib_1.__exportStar(require("./types"), exports);
|
|
29
|
-
tslib_1.__exportStar(require("./utils"), exports);
|
|
1
|
+
export { ariaSpecs, contentModelCategoryToTagNames, getAttrSpecs, getComputedRole, getImplicitRole, getPermittedRoles, getRoleSpec, getSpec, resolveNamespace, } from '@markuplint/ml-spec';
|
|
2
|
+
export { default as Ruleset } from './ruleset/index.js';
|
|
3
|
+
export { enableDebug } from './debug.js';
|
|
4
|
+
export { getIndent } from './ml-dom/helper/getIndent.js';
|
|
5
|
+
export * from './configs.js';
|
|
6
|
+
export * from './convert-ruleset.js';
|
|
7
|
+
export * from './ml-core.js';
|
|
8
|
+
export * from './ml-dom/index.js';
|
|
9
|
+
export * from './ml-rule/index.js';
|
|
10
|
+
export * from './plugin/index.js';
|
|
11
|
+
export * from './test/index.js';
|
|
12
|
+
export * from './types.js';
|
|
13
|
+
export * from './utils/index.js';
|
package/lib/ml-core.d.ts
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import type { MLFabric } from './types';
|
|
2
|
-
import type { RuleConfigValue, Violation } from '@markuplint/ml-config';
|
|
1
|
+
import type { MLFabric } from './types.js';
|
|
2
|
+
import type { PlainData, RuleConfigValue, Violation } from '@markuplint/ml-config';
|
|
3
3
|
import { ParserError } from '@markuplint/parser-utils';
|
|
4
|
-
import { Document } from './ml-dom';
|
|
4
|
+
import { Document } from './ml-dom/index.js';
|
|
5
5
|
export type MLCoreParams = {
|
|
6
|
-
sourceCode: string;
|
|
7
|
-
filename: string;
|
|
8
|
-
debug?: boolean;
|
|
6
|
+
readonly sourceCode: string;
|
|
7
|
+
readonly filename: string;
|
|
8
|
+
readonly debug?: boolean;
|
|
9
9
|
} & MLFabric;
|
|
10
10
|
export declare class MLCore {
|
|
11
11
|
#private;
|
|
12
12
|
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }: MLCoreParams);
|
|
13
|
-
get document(): Document<RuleConfigValue,
|
|
13
|
+
get document(): ParserError | Document<RuleConfigValue, PlainData>;
|
|
14
14
|
setCode(sourceCode: string): void;
|
|
15
15
|
update({ parser, ruleset, rules, locale, schemas, parserOptions }: Partial<MLFabric>): void;
|
|
16
16
|
verify(fix?: boolean): Promise<Violation[]>;
|
package/lib/ml-core.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var _MLCore_ast, _MLCore_document, _MLCore_filename, _MLCore_locale, _MLCore_parser, _MLCore_parserOptions, _MLCore_pretenders, _MLCore_rules, _MLCore_ruleset, _MLCore_schemas, _MLCore_sourceCode;
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
const resultLog = debug_1.log.extend('result');
|
|
10
|
-
class MLCore {
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import { ParserError } from '@markuplint/parser-utils';
|
|
4
|
+
import { log, enableDebug } from './debug.js';
|
|
5
|
+
import { Document } from './ml-dom/index.js';
|
|
6
|
+
const resultLog = log.extend('result');
|
|
7
|
+
export class MLCore {
|
|
11
8
|
constructor({ parser, sourceCode, ruleset, rules, locale, schemas, parserOptions, pretenders, filename, debug, }) {
|
|
12
|
-
var _a, _b, _c;
|
|
13
9
|
_MLCore_ast.set(this, null);
|
|
14
10
|
_MLCore_document.set(this, void 0);
|
|
15
11
|
_MLCore_filename.set(this, void 0);
|
|
@@ -22,79 +18,78 @@ class MLCore {
|
|
|
22
18
|
_MLCore_schemas.set(this, void 0);
|
|
23
19
|
_MLCore_sourceCode.set(this, void 0);
|
|
24
20
|
if (debug) {
|
|
25
|
-
|
|
21
|
+
enableDebug();
|
|
26
22
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
rules:
|
|
32
|
-
nodeRules:
|
|
33
|
-
childNodeRules:
|
|
23
|
+
__classPrivateFieldSet(this, _MLCore_parser, parser, "f");
|
|
24
|
+
__classPrivateFieldSet(this, _MLCore_sourceCode, sourceCode, "f");
|
|
25
|
+
__classPrivateFieldSet(this, _MLCore_parserOptions, parserOptions, "f");
|
|
26
|
+
__classPrivateFieldSet(this, _MLCore_ruleset, {
|
|
27
|
+
rules: ruleset.rules ?? {},
|
|
28
|
+
nodeRules: ruleset.nodeRules ?? [],
|
|
29
|
+
childNodeRules: ruleset.childNodeRules ?? [],
|
|
34
30
|
}, "f");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
31
|
+
__classPrivateFieldSet(this, _MLCore_locale, locale, "f");
|
|
32
|
+
__classPrivateFieldSet(this, _MLCore_schemas, schemas, "f");
|
|
33
|
+
__classPrivateFieldSet(this, _MLCore_filename, filename, "f");
|
|
34
|
+
__classPrivateFieldSet(this, _MLCore_rules, rules.slice(), "f");
|
|
35
|
+
__classPrivateFieldSet(this, _MLCore_pretenders, pretenders.slice(), "f");
|
|
40
36
|
this._parse();
|
|
41
37
|
this._createDocument();
|
|
42
38
|
}
|
|
43
39
|
get document() {
|
|
44
|
-
return
|
|
40
|
+
return __classPrivateFieldGet(this, _MLCore_document, "f");
|
|
45
41
|
}
|
|
46
42
|
setCode(sourceCode) {
|
|
47
|
-
|
|
43
|
+
__classPrivateFieldSet(this, _MLCore_sourceCode, sourceCode, "f");
|
|
48
44
|
this._parse();
|
|
49
45
|
this._createDocument();
|
|
50
46
|
}
|
|
51
47
|
update({ parser, ruleset, rules, locale, schemas, parserOptions }) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
childNodeRules: (_c = ruleset === null || ruleset === void 0 ? void 0 : ruleset.childNodeRules) !== null && _c !== void 0 ? _c : tslib_1.__classPrivateFieldGet(this, _MLCore_ruleset, "f").childNodeRules,
|
|
48
|
+
__classPrivateFieldSet(this, _MLCore_parser, parser ?? __classPrivateFieldGet(this, _MLCore_parser, "f"), "f");
|
|
49
|
+
__classPrivateFieldSet(this, _MLCore_ruleset, {
|
|
50
|
+
rules: ruleset?.rules ?? __classPrivateFieldGet(this, _MLCore_ruleset, "f").rules,
|
|
51
|
+
nodeRules: ruleset?.nodeRules ?? __classPrivateFieldGet(this, _MLCore_ruleset, "f").nodeRules,
|
|
52
|
+
childNodeRules: ruleset?.childNodeRules ?? __classPrivateFieldGet(this, _MLCore_ruleset, "f").childNodeRules,
|
|
58
53
|
}, "f");
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
54
|
+
__classPrivateFieldSet(this, _MLCore_rules, rules?.slice() ?? __classPrivateFieldGet(this, _MLCore_rules, "f"), "f");
|
|
55
|
+
__classPrivateFieldSet(this, _MLCore_locale, locale ?? __classPrivateFieldGet(this, _MLCore_locale, "f"), "f");
|
|
56
|
+
__classPrivateFieldSet(this, _MLCore_schemas, schemas ?? __classPrivateFieldGet(this, _MLCore_schemas, "f"), "f");
|
|
62
57
|
if (parserOptions &&
|
|
63
|
-
(parserOptions.ignoreFrontMatter !==
|
|
64
|
-
parserOptions.authoredElementName !==
|
|
58
|
+
(parserOptions.ignoreFrontMatter !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").ignoreFrontMatter ||
|
|
59
|
+
parserOptions.authoredElementName !== __classPrivateFieldGet(this, _MLCore_parserOptions, "f").authoredElementName)) {
|
|
65
60
|
this._parse();
|
|
66
61
|
}
|
|
67
62
|
this._createDocument();
|
|
68
63
|
}
|
|
69
64
|
async verify(fix = false) {
|
|
70
|
-
|
|
65
|
+
log('verify: start');
|
|
71
66
|
const violations = [];
|
|
72
|
-
if (
|
|
67
|
+
if (__classPrivateFieldGet(this, _MLCore_document, "f") instanceof ParserError) {
|
|
73
68
|
violations.push({
|
|
74
69
|
ruleId: 'parse-error',
|
|
75
70
|
severity: 'error',
|
|
76
|
-
message:
|
|
77
|
-
col:
|
|
78
|
-
line:
|
|
79
|
-
raw:
|
|
71
|
+
message: __classPrivateFieldGet(this, _MLCore_document, "f").message,
|
|
72
|
+
col: __classPrivateFieldGet(this, _MLCore_document, "f").col,
|
|
73
|
+
line: __classPrivateFieldGet(this, _MLCore_document, "f").line,
|
|
74
|
+
raw: __classPrivateFieldGet(this, _MLCore_document, "f").raw,
|
|
80
75
|
});
|
|
81
|
-
|
|
76
|
+
log('verify: error %o', __classPrivateFieldGet(this, _MLCore_document, "f").message);
|
|
82
77
|
return violations;
|
|
83
78
|
}
|
|
84
|
-
for (const rule of
|
|
85
|
-
const ruleInfo = rule.getRuleInfo(
|
|
79
|
+
for (const rule of __classPrivateFieldGet(this, _MLCore_rules, "f")) {
|
|
80
|
+
const ruleInfo = rule.getRuleInfo(__classPrivateFieldGet(this, _MLCore_ruleset, "f"), rule.name);
|
|
86
81
|
if (ruleInfo.disabled && ruleInfo.nodeRules.length === 0 && ruleInfo.childNodeRules.length === 0) {
|
|
87
82
|
continue;
|
|
88
83
|
}
|
|
89
|
-
|
|
90
|
-
const results = await rule.verify(
|
|
91
|
-
if (e instanceof
|
|
84
|
+
log('%s Rule: verify', rule.name);
|
|
85
|
+
const results = await rule.verify(__classPrivateFieldGet(this, _MLCore_document, "f"), __classPrivateFieldGet(this, _MLCore_locale, "f"), fix).catch(e => {
|
|
86
|
+
if (e instanceof ParserError) {
|
|
92
87
|
return e;
|
|
93
88
|
}
|
|
94
89
|
throw e;
|
|
95
90
|
});
|
|
96
|
-
if (results instanceof
|
|
97
|
-
|
|
91
|
+
if (results instanceof ParserError) {
|
|
92
|
+
log('%s Rule: verify error %o', rule.name, results.message);
|
|
98
93
|
violations.push({
|
|
99
94
|
ruleId: 'parse-error',
|
|
100
95
|
severity: 'error',
|
|
@@ -107,7 +102,7 @@ class MLCore {
|
|
|
107
102
|
else {
|
|
108
103
|
violations.push(...results);
|
|
109
104
|
}
|
|
110
|
-
|
|
105
|
+
log('%s Rule: verify end', rule.name);
|
|
111
106
|
}
|
|
112
107
|
if (resultLog.enabled) {
|
|
113
108
|
const { e, w, i } = violations.reduce((c, v) => {
|
|
@@ -123,24 +118,24 @@ class MLCore {
|
|
|
123
118
|
resultLog('Warning: %d', w);
|
|
124
119
|
resultLog('Info: %d', i);
|
|
125
120
|
}
|
|
126
|
-
|
|
121
|
+
log('verify: end');
|
|
127
122
|
return violations;
|
|
128
123
|
}
|
|
129
124
|
_createDocument() {
|
|
130
|
-
if (!
|
|
125
|
+
if (!__classPrivateFieldGet(this, _MLCore_ast, "f")) {
|
|
131
126
|
return;
|
|
132
127
|
}
|
|
133
128
|
try {
|
|
134
|
-
|
|
135
|
-
filename:
|
|
136
|
-
endTag:
|
|
137
|
-
booleanish:
|
|
138
|
-
pretenders:
|
|
129
|
+
__classPrivateFieldSet(this, _MLCore_document, new Document(__classPrivateFieldGet(this, _MLCore_ast, "f"), __classPrivateFieldGet(this, _MLCore_ruleset, "f"), __classPrivateFieldGet(this, _MLCore_schemas, "f"), {
|
|
130
|
+
filename: __classPrivateFieldGet(this, _MLCore_filename, "f"),
|
|
131
|
+
endTag: __classPrivateFieldGet(this, _MLCore_parser, "f").endTag,
|
|
132
|
+
booleanish: __classPrivateFieldGet(this, _MLCore_parser, "f").booleanish,
|
|
133
|
+
pretenders: __classPrivateFieldGet(this, _MLCore_pretenders, "f"),
|
|
139
134
|
}), "f");
|
|
140
135
|
}
|
|
141
136
|
catch (err) {
|
|
142
|
-
if (err instanceof
|
|
143
|
-
|
|
137
|
+
if (err instanceof ParserError) {
|
|
138
|
+
__classPrivateFieldSet(this, _MLCore_document, err, "f");
|
|
144
139
|
}
|
|
145
140
|
else {
|
|
146
141
|
throw err;
|
|
@@ -149,13 +144,13 @@ class MLCore {
|
|
|
149
144
|
}
|
|
150
145
|
_parse() {
|
|
151
146
|
try {
|
|
152
|
-
|
|
147
|
+
__classPrivateFieldSet(this, _MLCore_ast, __classPrivateFieldGet(this, _MLCore_parser, "f").parse(__classPrivateFieldGet(this, _MLCore_sourceCode, "f"), __classPrivateFieldGet(this, _MLCore_parserOptions, "f")), "f");
|
|
153
148
|
}
|
|
154
149
|
catch (err) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
if (err instanceof
|
|
158
|
-
|
|
150
|
+
log('Caught the parse error: %O', err);
|
|
151
|
+
__classPrivateFieldSet(this, _MLCore_ast, null, "f");
|
|
152
|
+
if (err instanceof ParserError) {
|
|
153
|
+
__classPrivateFieldSet(this, _MLCore_document, err, "f");
|
|
159
154
|
}
|
|
160
155
|
else {
|
|
161
156
|
throw err;
|
|
@@ -163,5 +158,4 @@ class MLCore {
|
|
|
163
158
|
}
|
|
164
159
|
}
|
|
165
160
|
}
|
|
166
|
-
exports.MLCore = MLCore;
|
|
167
161
|
_MLCore_ast = new WeakMap(), _MLCore_document = new WeakMap(), _MLCore_filename = new WeakMap(), _MLCore_locale = new WeakMap(), _MLCore_parser = new WeakMap(), _MLCore_parserOptions = new WeakMap(), _MLCore_pretenders = new WeakMap(), _MLCore_rules = new WeakMap(), _MLCore_ruleset = new WeakMap(), _MLCore_schemas = new WeakMap(), _MLCore_sourceCode = new WeakMap();
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
function getAccname(el, version) {
|
|
1
|
+
import { getAccname as get, getComputedRole } from '@markuplint/ml-spec';
|
|
2
|
+
import { log } from '../../debug.js';
|
|
3
|
+
const accnameLog = log.extend('accname');
|
|
4
|
+
export function getAccname(
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
|
+
el, version) {
|
|
8
7
|
let accname = safeGet(el);
|
|
9
8
|
if (accname) {
|
|
10
9
|
return accname;
|
|
@@ -23,7 +22,7 @@ function getAccname(el, version) {
|
|
|
23
22
|
return getAccname(child, version);
|
|
24
23
|
}
|
|
25
24
|
if (child.is(child.TEXT_NODE)) {
|
|
26
|
-
return child.textContent
|
|
25
|
+
return child.textContent ?? '';
|
|
27
26
|
}
|
|
28
27
|
return '';
|
|
29
28
|
})
|
|
@@ -31,10 +30,11 @@ function getAccname(el, version) {
|
|
|
31
30
|
}
|
|
32
31
|
return '';
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
function safeGet(
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
35
|
+
el) {
|
|
36
36
|
try {
|
|
37
|
-
const name = (
|
|
37
|
+
const name = get(el);
|
|
38
38
|
return name;
|
|
39
39
|
}
|
|
40
40
|
catch (err) {
|
|
@@ -43,9 +43,10 @@ function safeGet(el) {
|
|
|
43
43
|
return '';
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
|
-
function getAccnameFromPretender(
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
function getAccnameFromPretender(
|
|
47
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
48
|
+
el) {
|
|
49
|
+
if (el.pretenderContext?.type === 'pretender' && el.pretenderContext.aria?.name != null) {
|
|
49
50
|
if (typeof el.pretenderContext.aria.name === 'boolean') {
|
|
50
51
|
return 'some-name(Pretender Options)';
|
|
51
52
|
}
|
|
@@ -57,11 +58,14 @@ function getAccnameFromPretender(el) {
|
|
|
57
58
|
}
|
|
58
59
|
return '';
|
|
59
60
|
}
|
|
60
|
-
function isHidden(
|
|
61
|
+
function isHidden(
|
|
62
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
63
|
+
el) {
|
|
61
64
|
return el.getAttribute('aria-hidden') === 'true' || el.hasAttribute('hidden');
|
|
62
65
|
}
|
|
63
|
-
function isFromContent(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
function isFromContent(
|
|
67
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
68
|
+
el, version) {
|
|
69
|
+
const role = getComputedRole(el.ownerMLDocument.specs, el, version);
|
|
70
|
+
return !!role.role?.accessibleNameFromContent;
|
|
67
71
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MLDocument } from '../node/document';
|
|
2
|
-
import type { MappedNode } from '../node/types';
|
|
1
|
+
import type { MLDocument } from '../node/document.js';
|
|
2
|
+
import type { MappedNode } from '../node/types.js';
|
|
3
3
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
4
|
-
import type { RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
-
export declare function createNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O =
|
|
4
|
+
import type { PlainData, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
|
+
export declare function createNode<N extends MLASTAbstractNode, T extends RuleConfigValue, O extends PlainData = undefined>(astNode: N, document: MLDocument<T, O>): MappedNode<N, T, O>;
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
function createNode(astNode, document) {
|
|
1
|
+
import { MLBlock } from '../node/block.js';
|
|
2
|
+
import { MLComment } from '../node/comment.js';
|
|
3
|
+
import { MLDocumentType } from '../node/document-type.js';
|
|
4
|
+
import { MLElement } from '../node/element.js';
|
|
5
|
+
import { MLText } from '../node/text.js';
|
|
6
|
+
export function createNode(astNode,
|
|
7
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
|
+
document) {
|
|
10
9
|
const _astNode = astNode;
|
|
11
10
|
switch (_astNode.type) {
|
|
12
11
|
case 'doctype': {
|
|
13
|
-
return new
|
|
12
|
+
return new MLDocumentType(_astNode, document);
|
|
14
13
|
}
|
|
15
14
|
case 'starttag': {
|
|
16
|
-
return new
|
|
15
|
+
return new MLElement(_astNode, document);
|
|
17
16
|
}
|
|
18
17
|
case 'psblock': {
|
|
19
|
-
return new
|
|
18
|
+
return new MLBlock(_astNode, document);
|
|
20
19
|
}
|
|
21
20
|
case 'comment': {
|
|
22
|
-
return new
|
|
21
|
+
return new MLComment(_astNode, document);
|
|
23
22
|
}
|
|
24
23
|
case 'text': {
|
|
25
|
-
return new
|
|
24
|
+
return new MLText(_astNode, document);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
28
27
|
throw new TypeError(`Invalid AST node types "${astNode.type}"`);
|
|
29
28
|
}
|
|
30
|
-
exports.createNode = createNode;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { MLNode } from '../node/node';
|
|
1
|
+
import type { MLNode } from '../node/node.js';
|
|
2
2
|
export declare function nodeListToDebugMaps(nodeList: Readonly<MLNode<any, any>[]>, withAttr?: boolean): string[];
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function nodeListToDebugMaps(nodeList, withAttr = false) {
|
|
1
|
+
export function nodeListToDebugMaps(
|
|
2
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
3
|
+
nodeList, withAttr = false) {
|
|
5
4
|
return nodeList
|
|
6
5
|
.map(n => {
|
|
7
6
|
const r = [];
|
|
@@ -13,7 +12,7 @@ function nodeListToDebugMaps(nodeList, withAttr = false) {
|
|
|
13
12
|
if (n.is(n.ELEMENT_NODE)) {
|
|
14
13
|
r.push(` namespaceURI: ${!!n.namespaceURI}`);
|
|
15
14
|
r.push(` elementType: ${n.elementType}`);
|
|
16
|
-
r.push(` isInFragmentDocument: ${
|
|
15
|
+
r.push(` isInFragmentDocument: ${n.isInFragmentDocument()}`);
|
|
17
16
|
r.push(` isForeignElement: ${!!n.isForeignElement}`);
|
|
18
17
|
if (withAttr) {
|
|
19
18
|
r.push(...attributesToDebugMaps(n.attributes)
|
|
@@ -25,8 +24,9 @@ function nodeListToDebugMaps(nodeList, withAttr = false) {
|
|
|
25
24
|
})
|
|
26
25
|
.flat();
|
|
27
26
|
}
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
function attributesToDebugMaps(
|
|
28
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
29
|
+
attributes) {
|
|
30
30
|
return attributes
|
|
31
31
|
.map(n => {
|
|
32
32
|
const r = [
|
|
@@ -77,7 +77,7 @@ function attributesToDebugMaps(attributes) {
|
|
|
77
77
|
.flat();
|
|
78
78
|
}
|
|
79
79
|
function tokenDebug(n, type = '') {
|
|
80
|
-
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${n.nodeName
|
|
80
|
+
return `[${n.startLine}:${n.startCol}]>[${n.endLine}:${n.endCol}](${n.startOffset},${n.endOffset})${n.nodeName ?? n.potentialName ?? n.name ?? n.type ?? type}: ${visibleWhiteSpace(n.raw)}`;
|
|
81
81
|
}
|
|
82
82
|
function visibleWhiteSpace(chars) {
|
|
83
83
|
return chars.replace(/\n/g, '⏎').replace(/\t/g, '→').replace(/\s/g, '␣');
|