@markuplint/rules 3.12.0 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/attr-check.js +14 -19
- package/lib/attr-duplication/index.js +3 -6
- package/lib/attr-value-quotes/index.js +5 -9
- package/lib/case-sensitive-attr-name/index.js +9 -13
- package/lib/case-sensitive-tag-name/index.js +2 -4
- package/lib/character-reference/index.js +6 -8
- package/lib/class-naming/index.js +9 -11
- package/lib/create-message.js +9 -16
- package/lib/debug.js +2 -6
- package/lib/deprecated-attr/index.js +6 -9
- package/lib/deprecated-element/index.js +3 -5
- package/lib/disallowed-element/index.js +2 -4
- package/lib/doctype/index.js +2 -4
- package/lib/end-tag/index.js +5 -8
- package/lib/helpers.d.ts +1 -1
- package/lib/helpers.js +17 -28
- package/lib/id-duplication/index.js +2 -4
- package/lib/index.d.ts +15 -15
- package/lib/index.js +63 -66
- package/lib/ineffective-attr/index.js +5 -7
- package/lib/invalid-attr/index.js +30 -33
- package/lib/label-has-control/index.js +2 -4
- package/lib/landmark-roles/index.js +3 -6
- package/lib/no-boolean-attr-value/index.js +6 -9
- package/lib/no-default-value/index.js +9 -12
- package/lib/no-empty-palpable-content/index.js +5 -7
- package/lib/no-hard-code-id/index.js +2 -4
- package/lib/no-refer-to-non-existent-id/index.js +26 -30
- package/lib/no-use-event-handler-attr/index.js +4 -6
- package/lib/permitted-contents/choice.d.ts +1 -1
- package/lib/permitted-contents/choice.js +13 -18
- package/lib/permitted-contents/complex-branch.d.ts +1 -1
- package/lib/permitted-contents/complex-branch.js +10 -14
- package/lib/permitted-contents/content-model.d.ts +1 -1
- package/lib/permitted-contents/content-model.js +5 -9
- package/lib/permitted-contents/count-pattern.d.ts +1 -1
- package/lib/permitted-contents/count-pattern.js +19 -24
- package/lib/permitted-contents/debug.browser.js +9 -12
- package/lib/permitted-contents/debug.d.ts +8 -1
- package/lib/permitted-contents/debug.js +12 -13
- package/lib/permitted-contents/index.d.ts +1 -1
- package/lib/permitted-contents/index.js +10 -13
- package/lib/permitted-contents/matches-selector.d.ts +1 -1
- package/lib/permitted-contents/matches-selector.js +12 -17
- package/lib/permitted-contents/order.d.ts +1 -1
- package/lib/permitted-contents/order.js +17 -22
- package/lib/permitted-contents/recursive-branch.d.ts +2 -2
- package/lib/permitted-contents/recursive-branch.js +9 -13
- package/lib/permitted-contents/represent-transparent-nodes.d.ts +1 -1
- package/lib/permitted-contents/represent-transparent-nodes.js +15 -20
- package/lib/permitted-contents/start.d.ts +1 -1
- package/lib/permitted-contents/start.js +13 -21
- package/lib/permitted-contents/transparent.d.ts +1 -1
- package/lib/permitted-contents/transparent.js +4 -9
- package/lib/permitted-contents/types.js +1 -2
- package/lib/permitted-contents/utils.d.ts +1 -1
- package/lib/permitted-contents/utils.js +55 -74
- package/lib/placeholder-label-option/index.js +5 -9
- package/lib/require-accessible-name/index.js +10 -13
- package/lib/require-datetime/index.d.ts +1 -1
- package/lib/require-datetime/index.js +6 -8
- package/lib/require-datetime/types.js +1 -2
- package/lib/require-datetime/utils.d.ts +1 -1
- package/lib/require-datetime/utils.js +4 -11
- package/lib/required-attr/index.js +8 -11
- package/lib/required-element/index.js +3 -6
- package/lib/required-h1/index.js +3 -6
- package/lib/use-list/index.js +6 -10
- package/lib/wai-aria/checkings/abstract-role.d.ts +1 -1
- package/lib/wai-aria/checkings/abstract-role.js +5 -10
- package/lib/wai-aria/checkings/default-value.d.ts +1 -1
- package/lib/wai-aria/checkings/default-value.js +2 -6
- package/lib/wai-aria/checkings/deprecated-props.d.ts +1 -1
- package/lib/wai-aria/checkings/deprecated-props.js +3 -8
- package/lib/wai-aria/checkings/disallowed-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/disallowed-prop.js +7 -12
- package/lib/wai-aria/checkings/implicit-props.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-props.js +6 -11
- package/lib/wai-aria/checkings/implicit-role.d.ts +1 -1
- package/lib/wai-aria/checkings/implicit-role.js +4 -9
- package/lib/wai-aria/checkings/interaction-in-hidden.d.ts +1 -1
- package/lib/wai-aria/checkings/interaction-in-hidden.js +4 -8
- package/lib/wai-aria/checkings/no-global-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/no-global-prop.js +2 -7
- package/lib/wai-aria/checkings/non-existent-role.d.ts +1 -1
- package/lib/wai-aria/checkings/non-existent-role.js +4 -9
- package/lib/wai-aria/checkings/permitted-roles.d.ts +1 -1
- package/lib/wai-aria/checkings/permitted-roles.js +4 -9
- package/lib/wai-aria/checkings/presentational-children.d.ts +1 -1
- package/lib/wai-aria/checkings/presentational-children.js +4 -9
- package/lib/wai-aria/checkings/required-owned-elements.d.ts +1 -1
- package/lib/wai-aria/checkings/required-owned-elements.js +4 -8
- package/lib/wai-aria/checkings/required-prop.d.ts +1 -1
- package/lib/wai-aria/checkings/required-prop.js +2 -7
- package/lib/wai-aria/checkings/value.d.ts +1 -1
- package/lib/wai-aria/checkings/value.js +4 -10
- package/lib/wai-aria/index.d.ts +1 -1
- package/lib/wai-aria/index.js +38 -40
- package/lib/wai-aria/types.js +1 -2
- package/package.json +17 -12
- package/test/attr-check.spec.js +0 -77
- package/test/attr-duplication/index.spec.js +0 -159
- package/test/attr-value-quotes/index.spec.js +0 -133
- package/test/case-sensitive-attr-name/index.spec.js +0 -65
- package/test/case-sensitive-tag-name/index.spec.js +0 -80
- package/test/character-reference/index.spec.js +0 -72
- package/test/class-naming/index.spec.js +0 -470
- package/test/create-message.spec.js +0 -497
- package/test/deprecated-attr/index.spec.js +0 -48
- package/test/deprecated-element/index.spec.js +0 -35
- package/test/disallowed-element/index.spec.js +0 -90
- package/test/doctype/index.spec.js +0 -50
- package/test/end-tag/index.spec.js +0 -162
- package/test/id-duplication/index.spec.js +0 -47
- package/test/ineffective-attr/index.spec.js +0 -31
- package/test/invalid-attr/index.spec.js +0 -1641
- package/test/label-has-control/index.spec.js +0 -29
- package/test/landmark-roles/index.spec.js +0 -187
- package/test/no-boolean-attr-value/index.spec.js +0 -41
- package/test/no-default-value/index.spec.js +0 -74
- package/test/no-empty-palpable-content/index.spec.js +0 -115
- package/test/no-hard-code-id/index.spec.js +0 -100
- package/test/no-refer-to-non-existent-id/index.spec.js +0 -254
- package/test/no-use-event-handler-attr/index.spec.js +0 -57
- package/test/permitted-contents/choice.spec.js +0 -174
- package/test/permitted-contents/count-pattern.spec.js +0 -308
- package/test/permitted-contents/index.spec.js +0 -1395
- package/test/permitted-contents/matches-selector.spec.js +0 -59
- package/test/permitted-contents/order.spec.js +0 -351
- package/test/permitted-contents/recursive-branch.spec.js +0 -41
- package/test/permitted-contents/represent-transparent-nodes.spec.js +0 -24
- package/test/permitted-contents/start.spec.js +0 -67
- package/test/placeholder-label-option/index.spec.js +0 -113
- package/test/require-accessible-name/index.spec.js +0 -444
- package/test/require-datetime/index.spec.js +0 -54
- package/test/require-datetime/utils.spec.js +0 -52
- package/test/required-attr/index.spec.js +0 -414
- package/test/required-element/index.spec.js +0 -188
- package/test/required-h1/index.spec.js +0 -69
- package/test/use-list/index.spec.js +0 -109
- package/test/wai-aria/checkings/value.spec.js +0 -33
- package/test/wai-aria/index.spec.js +0 -1203
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const debug_1 = require("./debug");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function matchesSelector(query,
|
|
1
|
+
import { contentModelCategoryToTagNames } from '@markuplint/ml-spec';
|
|
2
|
+
import { cmLog } from './debug.js';
|
|
3
|
+
import { cleanObject, matches } from './utils.js';
|
|
4
|
+
export function matchesSelector(query,
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
6
|
node, specs, depth) {
|
|
10
|
-
const nodeLog =
|
|
7
|
+
const nodeLog = cmLog.extend(`node#${depth}`);
|
|
11
8
|
const { selector, hasText, hasCustom } = optCondition(query, specs);
|
|
12
9
|
if (node == null) {
|
|
13
10
|
if (hasText) {
|
|
@@ -86,7 +83,7 @@ node, specs, depth) {
|
|
|
86
83
|
hint: {},
|
|
87
84
|
};
|
|
88
85
|
}
|
|
89
|
-
const result =
|
|
86
|
+
const result = matches(selector, node, specs);
|
|
90
87
|
nodeLog('%s.matches(%s) => %s', node.raw, query, result.matched);
|
|
91
88
|
if (result.matched) {
|
|
92
89
|
return {
|
|
@@ -105,7 +102,7 @@ node, specs, depth) {
|
|
|
105
102
|
unmatched: [node],
|
|
106
103
|
zeroMatch: true,
|
|
107
104
|
query,
|
|
108
|
-
hint:
|
|
105
|
+
hint: cleanObject({
|
|
109
106
|
not: result.not,
|
|
110
107
|
}),
|
|
111
108
|
};
|
|
@@ -116,7 +113,7 @@ node, specs, depth) {
|
|
|
116
113
|
unmatched: [node],
|
|
117
114
|
zeroMatch: false,
|
|
118
115
|
query,
|
|
119
|
-
hint:
|
|
116
|
+
hint: cleanObject({
|
|
120
117
|
not: result.not,
|
|
121
118
|
}),
|
|
122
119
|
};
|
|
@@ -130,7 +127,6 @@ node, specs, depth) {
|
|
|
130
127
|
hint: {},
|
|
131
128
|
};
|
|
132
129
|
}
|
|
133
|
-
exports.matchesSelector = matchesSelector;
|
|
134
130
|
const conditionWithoutSpecs = {
|
|
135
131
|
'#custom': {
|
|
136
132
|
selector: '#custom',
|
|
@@ -145,12 +141,11 @@ const conditionWithoutSpecs = {
|
|
|
145
141
|
};
|
|
146
142
|
const optConditionSpecsBaseCaches = new Map();
|
|
147
143
|
function optCondition(query, specs) {
|
|
148
|
-
var _a;
|
|
149
144
|
const condWithoutSpecs = conditionWithoutSpecs[query];
|
|
150
145
|
if (condWithoutSpecs) {
|
|
151
146
|
return condWithoutSpecs;
|
|
152
147
|
}
|
|
153
|
-
const queryCaches =
|
|
148
|
+
const queryCaches = optConditionSpecsBaseCaches.get(specs) ?? new Map();
|
|
154
149
|
const cached = queryCaches.get(query);
|
|
155
150
|
if (cached) {
|
|
156
151
|
return cached;
|
|
@@ -158,9 +153,9 @@ function optCondition(query, specs) {
|
|
|
158
153
|
let hasCustom = false;
|
|
159
154
|
let hasText = false;
|
|
160
155
|
const selector = query.replace(/^(?::model\(([^)]+)\)|#([a-z-]+))(.*)$/, (_, $model, _model, $last) => {
|
|
161
|
-
const _selectors =
|
|
156
|
+
const _selectors = contentModelCategoryToTagNames(`#${$model ?? _model}`, specs.def);
|
|
162
157
|
if (_selectors.length === 0) {
|
|
163
|
-
throw new Error(`${$model
|
|
158
|
+
throw new Error(`${$model ?? _model} is empty`);
|
|
164
159
|
}
|
|
165
160
|
const selectors = [];
|
|
166
161
|
for (const selector of _selectors) {
|
|
@@ -174,7 +169,7 @@ function optCondition(query, specs) {
|
|
|
174
169
|
}
|
|
175
170
|
selectors.push(selector);
|
|
176
171
|
}
|
|
177
|
-
return `:is(${selectors.join(',')})${$last
|
|
172
|
+
return `:is(${selectors.join(',')})${$last ?? ''}`;
|
|
178
173
|
});
|
|
179
174
|
const result = {
|
|
180
175
|
selector,
|
|
@@ -1,10 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const complex_branch_1 = require("./complex-branch");
|
|
6
|
-
const debug_1 = require("./debug");
|
|
7
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { deepCopy } from '../helpers.js';
|
|
2
|
+
import { complexBranch } from './complex-branch.js';
|
|
3
|
+
import { cmLog } from './debug.js';
|
|
4
|
+
import { Collection, mergeHints, modelLog } from './utils.js';
|
|
8
5
|
/**
|
|
9
6
|
* Check ordered array
|
|
10
7
|
*
|
|
@@ -15,22 +12,21 @@ const utils_1 = require("./utils");
|
|
|
15
12
|
* @param depth
|
|
16
13
|
* @returns
|
|
17
14
|
*/
|
|
18
|
-
function order(contents,
|
|
15
|
+
export function order(contents,
|
|
19
16
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
20
17
|
nodes, specs, options, depth) {
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
orderLog('Model:\n RegEx: %s\n Schema: %o', (0, utils_1.modelLog)(patterns, ''), patterns);
|
|
18
|
+
const orderLog = cmLog.extend(`order#${depth}`);
|
|
19
|
+
const btLog = cmLog.extend(`backtrack#${depth}`);
|
|
20
|
+
const patterns = deepCopy(contents);
|
|
21
|
+
const collection = new Collection(nodes);
|
|
22
|
+
orderLog('Model:\n RegEx: %s\n Schema: %o', modelLog(patterns, ''), patterns);
|
|
27
23
|
orderLog('Starts: %s', collection);
|
|
28
24
|
let result = undefined;
|
|
29
25
|
let backtrackMode = false;
|
|
30
26
|
let afterBacktrack = false;
|
|
31
27
|
const unmatchedResults = [];
|
|
32
28
|
while (patterns.length > 0 && patterns[0]) {
|
|
33
|
-
result =
|
|
29
|
+
result = complexBranch(patterns[0], collection.unmatched, specs, options, depth);
|
|
34
30
|
collection.addMatched(result.matched);
|
|
35
31
|
if (result.type !== 'UNEXPECTED_EXTRA_NODE' && result.type !== 'MATCHED' && result.type !== 'MATCHED_ZERO') {
|
|
36
32
|
unmatchedResults.push(result);
|
|
@@ -45,7 +41,7 @@ nodes, specs, options, depth) {
|
|
|
45
41
|
if (!barelyMatchedResult) {
|
|
46
42
|
throw new Error('Unreachable code');
|
|
47
43
|
}
|
|
48
|
-
orderLog('Result (%s): %s%s', result.type, collection.toString(true),
|
|
44
|
+
orderLog('Result (%s): %s%s', result.type, collection.toString(true), barelyMatchedResult.hint.missing?.barelyMatchedElements != null
|
|
49
45
|
? `; But ${barelyMatchedResult.hint.missing.barelyMatchedElements} elements hit out of pattern`
|
|
50
46
|
: '');
|
|
51
47
|
return {
|
|
@@ -54,7 +50,7 @@ nodes, specs, options, depth) {
|
|
|
54
50
|
unmatched: collection.unmatched,
|
|
55
51
|
zeroMatch: barelyMatchedResult.zeroMatch,
|
|
56
52
|
query: barelyMatchedResult.query,
|
|
57
|
-
hint:
|
|
53
|
+
hint: mergeHints(barelyMatchedResult.hint, {
|
|
58
54
|
missing: {
|
|
59
55
|
barelyMatchedElements: collection.matched.length,
|
|
60
56
|
need: barelyMatchedResult.query,
|
|
@@ -81,8 +77,8 @@ nodes, specs, options, depth) {
|
|
|
81
77
|
matched: collection.matched,
|
|
82
78
|
unmatched: collection.unmatched,
|
|
83
79
|
zeroMatch: false,
|
|
84
|
-
query:
|
|
85
|
-
hint:
|
|
80
|
+
query: result?.query ?? 'N/A',
|
|
81
|
+
hint: result?.hint ?? {},
|
|
86
82
|
};
|
|
87
83
|
}
|
|
88
84
|
const resultType = collection.matched.length > 0 ? 'MATCHED' : 'MATCHED_ZERO';
|
|
@@ -92,8 +88,7 @@ nodes, specs, options, depth) {
|
|
|
92
88
|
matched: collection.matched,
|
|
93
89
|
unmatched: collection.unmatched,
|
|
94
90
|
zeroMatch: false,
|
|
95
|
-
query:
|
|
96
|
-
hint:
|
|
91
|
+
query: result?.query ?? 'N/A',
|
|
92
|
+
hint: result?.hint ?? {},
|
|
97
93
|
};
|
|
98
94
|
}
|
|
99
|
-
exports.order = order;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { SelectorResult } from './matches-selector';
|
|
2
|
-
import type { ChildNode, Options, Specs } from './types';
|
|
1
|
+
import type { SelectorResult } from './matches-selector.js';
|
|
2
|
+
import type { ChildNode, Options, Specs } from './types.js';
|
|
3
3
|
import type { PermittedContentPattern, Model } from '@markuplint/ml-spec';
|
|
4
4
|
import type { ReadonlyDeep } from 'type-fest';
|
|
5
5
|
export declare function recursiveBranch(model: ReadonlyDeep<Model | PermittedContentPattern[]>, nodes: readonly ChildNode[], specs: Specs, options: Options, depth: number): SelectorResult;
|
|
@@ -1,22 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const order_1 = require("./order");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
function recursiveBranch(model,
|
|
1
|
+
import { matchesSelector } from './matches-selector.js';
|
|
2
|
+
import { order } from './order.js';
|
|
3
|
+
import { Collection, isModel } from './utils.js';
|
|
4
|
+
export function recursiveBranch(model,
|
|
8
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
6
|
nodes, specs, options, depth) {
|
|
10
|
-
if (!
|
|
11
|
-
return
|
|
7
|
+
if (!isModel(model)) {
|
|
8
|
+
return order(model, nodes, specs, options, depth + 1);
|
|
12
9
|
}
|
|
13
10
|
if (typeof model === 'string') {
|
|
14
|
-
return
|
|
11
|
+
return matchesSelector(model, nodes[0], specs, depth);
|
|
15
12
|
}
|
|
16
|
-
const collection = new
|
|
13
|
+
const collection = new Collection(nodes);
|
|
17
14
|
let lastUnmatched = null;
|
|
18
15
|
for (const query of model) {
|
|
19
|
-
const result =
|
|
16
|
+
const result = matchesSelector(query, collection.unmatched[0], specs, depth);
|
|
20
17
|
collection.addMatched(result.matched);
|
|
21
18
|
if (result.type === 'MATCHED' || result.type === 'MATCHED_ZERO') {
|
|
22
19
|
return {
|
|
@@ -42,4 +39,3 @@ nodes, specs, options, depth) {
|
|
|
42
39
|
}
|
|
43
40
|
return lastUnmatched;
|
|
44
41
|
}
|
|
45
|
-
exports.recursiveBranch = recursiveBranch;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChildNode, Options, Result, Specs } from './types';
|
|
1
|
+
import type { ChildNode, Options, Result, Specs } from './types.js';
|
|
2
2
|
export declare const transparentMode: Map<ChildNode, true>;
|
|
3
3
|
export declare function representTransparentNodes(nodes: ChildNode[], specs: Specs, options: Options): {
|
|
4
4
|
nodes: ChildNode[];
|
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
const utils_1 = require("./utils");
|
|
7
|
-
exports.transparentMode = new Map();
|
|
8
|
-
function representTransparentNodes(
|
|
1
|
+
import { getContentModel } from '@markuplint/ml-spec';
|
|
2
|
+
import { order } from './order.js';
|
|
3
|
+
import { Collection, getChildNodesWithoutWhitespaces, isTransparent, matches } from './utils.js';
|
|
4
|
+
export const transparentMode = new Map();
|
|
5
|
+
export function representTransparentNodes(
|
|
9
6
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
10
7
|
nodes, specs, options) {
|
|
11
|
-
var _a;
|
|
12
8
|
const result = [];
|
|
13
9
|
const errors = [];
|
|
14
|
-
const parent =
|
|
10
|
+
const parent = nodes[0]?.parentElement;
|
|
15
11
|
if (parent) {
|
|
16
12
|
const { errors: parentErrors } = representTransparentNodes([parent], specs, options);
|
|
17
13
|
errors.push(...parentErrors);
|
|
@@ -21,37 +17,37 @@ nodes, specs, options) {
|
|
|
21
17
|
result.push(node);
|
|
22
18
|
continue;
|
|
23
19
|
}
|
|
24
|
-
const models =
|
|
20
|
+
const models = getContentModel(node, specs.specs);
|
|
25
21
|
if (models == null || typeof models === 'boolean') {
|
|
26
22
|
result.push(node);
|
|
27
23
|
continue;
|
|
28
24
|
}
|
|
29
|
-
const noTransparentModels = models.filter(m => !
|
|
25
|
+
const noTransparentModels = models.filter(m => !isTransparent(m));
|
|
30
26
|
if (noTransparentModels.length === models.length) {
|
|
31
27
|
result.push(node);
|
|
32
28
|
continue;
|
|
33
29
|
}
|
|
34
|
-
const collection = new
|
|
30
|
+
const collection = new Collection(getChildNodesWithoutWhitespaces(node));
|
|
35
31
|
let unmatched;
|
|
36
32
|
if (noTransparentModels.length > 0) {
|
|
37
|
-
const result =
|
|
33
|
+
const result = order(noTransparentModels, collection.unmatched, specs, options, Infinity);
|
|
38
34
|
unmatched = result.unmatched;
|
|
39
35
|
}
|
|
40
36
|
else {
|
|
41
37
|
unmatched = collection.unmatched;
|
|
42
38
|
}
|
|
43
|
-
const transparent = models.find(m =>
|
|
44
|
-
if (!transparent || !
|
|
39
|
+
const transparent = models.find(m => isTransparent(m));
|
|
40
|
+
if (!transparent || !isTransparent(transparent)) {
|
|
45
41
|
throw new Error('Unreachable code');
|
|
46
42
|
}
|
|
47
43
|
for (const _child of unmatched) {
|
|
48
44
|
const child = _child;
|
|
49
|
-
if (
|
|
45
|
+
if (transparentMode.has(child)) {
|
|
50
46
|
continue;
|
|
51
47
|
}
|
|
52
|
-
|
|
48
|
+
transparentMode.set(child, true);
|
|
53
49
|
if (child.is(child.ELEMENT_NODE)) {
|
|
54
|
-
const transparentCondMatched =
|
|
50
|
+
const transparentCondMatched = matches(transparent.transparent, child, specs);
|
|
55
51
|
if (!transparentCondMatched.matched) {
|
|
56
52
|
errors.push({
|
|
57
53
|
type: 'TRANSPARENT_MODEL_DISALLOWS',
|
|
@@ -75,4 +71,3 @@ nodes, specs, options) {
|
|
|
75
71
|
errors,
|
|
76
72
|
};
|
|
77
73
|
}
|
|
78
|
-
exports.representTransparentNodes = representTransparentNodes;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const order_1 = require("./order");
|
|
5
|
-
const represent_transparent_nodes_1 = require("./represent-transparent-nodes");
|
|
6
|
-
const utils_1 = require("./utils");
|
|
1
|
+
import { order } from './order.js';
|
|
2
|
+
import { representTransparentNodes } from './represent-transparent-nodes.js';
|
|
3
|
+
import { getChildNodesWithoutWhitespaces } from './utils.js';
|
|
7
4
|
/**
|
|
8
5
|
* Check start
|
|
9
6
|
*
|
|
@@ -13,10 +10,9 @@ const utils_1 = require("./utils");
|
|
|
13
10
|
* @param options
|
|
14
11
|
* @returns
|
|
15
12
|
*/
|
|
16
|
-
function start(contents,
|
|
13
|
+
export function start(contents,
|
|
17
14
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
18
15
|
el, specs, options) {
|
|
19
|
-
var _a;
|
|
20
16
|
if (contents === false) {
|
|
21
17
|
if (el.childNodes.length > 0) {
|
|
22
18
|
return [
|
|
@@ -48,26 +44,22 @@ el, specs, options) {
|
|
|
48
44
|
},
|
|
49
45
|
];
|
|
50
46
|
}
|
|
51
|
-
const { nodes, errors } =
|
|
52
|
-
const result =
|
|
47
|
+
const { nodes, errors } = representTransparentNodes(getChildNodesWithoutWhitespaces(el), specs, options);
|
|
48
|
+
const result = order(contents, nodes, specs, options, 0);
|
|
53
49
|
return [
|
|
54
50
|
{
|
|
55
51
|
type: result.type,
|
|
56
52
|
scope: result.type === 'MISSING_NODE_REQUIRED' || result.type === 'MISSING_NODE_ONE_OR_MORE'
|
|
57
53
|
? el
|
|
58
|
-
:
|
|
54
|
+
: result.unmatched[0] ?? el,
|
|
59
55
|
query: result.query,
|
|
60
56
|
hint: result.hint,
|
|
61
57
|
},
|
|
62
|
-
...errors.map(error => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
hint: error.hint,
|
|
69
|
-
});
|
|
70
|
-
}),
|
|
58
|
+
...errors.map(error => ({
|
|
59
|
+
type: error.type,
|
|
60
|
+
scope: error.unmatched[0] ?? el,
|
|
61
|
+
query: error.query,
|
|
62
|
+
hint: error.hint,
|
|
63
|
+
})),
|
|
71
64
|
];
|
|
72
65
|
}
|
|
73
|
-
exports.start = start;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { ChildNode, Result } from './types';
|
|
1
|
+
import type { ChildNode, Result } from './types.js';
|
|
2
2
|
export declare function transparent(nodes: readonly ChildNode[]): Result;
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const debug_1 = require("./debug");
|
|
5
|
-
const transparentLog = debug_1.cmLog.extend('transparent');
|
|
6
|
-
function transparent(
|
|
1
|
+
import { cmLog } from './debug.js';
|
|
2
|
+
const transparentLog = cmLog.extend('transparent');
|
|
3
|
+
export function transparent(
|
|
7
4
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
8
5
|
nodes) {
|
|
9
|
-
|
|
10
|
-
if (nodes.length === 0 || ((_b = (_a = nodes[0]) === null || _a === void 0 ? void 0 : _a.parentElement) === null || _b === void 0 ? void 0 : _b.parentElement)) {
|
|
6
|
+
if (nodes.length === 0 || nodes[0]?.parentElement?.parentElement) {
|
|
11
7
|
transparentLog('Skipped');
|
|
12
8
|
return {
|
|
13
9
|
type: nodes.length === 0 ? 'MATCHED_ZERO' : 'MATCHED',
|
|
@@ -28,4 +24,3 @@ nodes) {
|
|
|
28
24
|
hint: {},
|
|
29
25
|
};
|
|
30
26
|
}
|
|
31
|
-
exports.transparent = transparent;
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types';
|
|
1
|
+
import type { ChildNode, Element, Hints, MissingNodeReason, RepeatSign, Specs } from './types.js';
|
|
2
2
|
import type { PermittedContentPattern, PermittedContentChoice, PermittedContentOneOrMore, PermittedContentOptional, PermittedContentRequire, PermittedContentTransparent, PermittedContentZeroOrMore, Model } from '@markuplint/ml-spec';
|
|
3
3
|
import type { ReadonlyDeep } from 'type-fest';
|
|
4
4
|
export declare function getChildNodesWithoutWhitespaces(el: Element): ChildNode[];
|