@markuplint/ml-core 3.3.1 → 3.4.0
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/ml-dom/node/document.d.ts +4 -4
- package/lib/ml-dom/node/document.js +12 -0
- package/lib/ml-dom/node/dom-token-list.js +5 -5
- package/lib/ml-dom/node/element.d.ts +1 -1
- package/lib/ml-dom/node/named-node-map.js +2 -1
- package/lib/ml-dom/node/node-list.js +17 -2
- package/lib/ml-dom/node/node.d.ts +3 -3
- package/lib/ml-dom/node/node.js +4 -2
- package/lib/ml-dom/node/parent-node.d.ts +2 -2
- package/lib/ml-dom/node/rule-mapper.js +3 -0
- package/lib/ml-dom/node/types.d.ts +1 -1
- package/lib/ml-rule/ml-rule-context.d.ts +1 -1
- package/lib/ml-rule/ml-rule.d.ts +1 -1
- package/lib/ml-rule/types.d.ts +1 -1
- package/lib/test/index.js +1 -1
- package/package.json +9 -9
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import type { MLRule } from '../../ml-rule';
|
|
2
|
-
import type Ruleset from '../../ruleset';
|
|
3
|
-
import type { Walker } from '../helper/walkers';
|
|
4
|
-
import type { MLToken } from '../token/token';
|
|
5
1
|
import type { MLAttr } from './attr';
|
|
6
2
|
import type { MLComment } from './comment';
|
|
7
3
|
import type { MLDocumentType } from './document-type';
|
|
@@ -9,6 +5,10 @@ import type { MLElement } from './element';
|
|
|
9
5
|
import type { MLNode } from './node';
|
|
10
6
|
import type { MLText } from './text';
|
|
11
7
|
import type { DocumentNodeType } from './types';
|
|
8
|
+
import type { MLRule } from '../../ml-rule';
|
|
9
|
+
import type Ruleset from '../../ruleset';
|
|
10
|
+
import type { Walker } from '../helper/walkers';
|
|
11
|
+
import type { MLToken } from '../token/token';
|
|
12
12
|
import type { EndTagType, MLASTDocument } from '@markuplint/ml-ast';
|
|
13
13
|
import type { Pretender, RuleConfigValue } from '@markuplint/ml-config';
|
|
14
14
|
import type { ExtendedSpec, MLMLSpec } from '@markuplint/ml-spec';
|
|
@@ -2064,6 +2064,9 @@ class MLDocument extends parent_node_1.MLParentNode {
|
|
|
2064
2064
|
// global rules to #document
|
|
2065
2065
|
Object.keys(ruleset.rules).forEach(ruleName => {
|
|
2066
2066
|
const rule = ruleset.rules[ruleName];
|
|
2067
|
+
if (rule == null) {
|
|
2068
|
+
return;
|
|
2069
|
+
}
|
|
2067
2070
|
ruleMapper.set(this, ruleName, {
|
|
2068
2071
|
from: 'rules',
|
|
2069
2072
|
specificity: [0, 0, 0],
|
|
@@ -2078,6 +2081,9 @@ class MLDocument extends parent_node_1.MLParentNode {
|
|
|
2078
2081
|
// global rules to each element
|
|
2079
2082
|
Object.keys(ruleset.rules).forEach(ruleName => {
|
|
2080
2083
|
const rule = ruleset.rules[ruleName];
|
|
2084
|
+
if (rule == null) {
|
|
2085
|
+
return;
|
|
2086
|
+
}
|
|
2081
2087
|
ruleMapper.set(node, ruleName, {
|
|
2082
2088
|
from: 'rules',
|
|
2083
2089
|
specificity: [0, 0, 0],
|
|
@@ -2107,6 +2113,9 @@ class MLDocument extends parent_node_1.MLParentNode {
|
|
|
2107
2113
|
const ruleList = Object.keys(nodeRule.rules);
|
|
2108
2114
|
for (const ruleName of ruleList) {
|
|
2109
2115
|
const rule = nodeRule.rules[ruleName];
|
|
2116
|
+
if (rule == null) {
|
|
2117
|
+
continue;
|
|
2118
|
+
}
|
|
2110
2119
|
const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, matches.data || {});
|
|
2111
2120
|
if (convertedRule === undefined) {
|
|
2112
2121
|
continue;
|
|
@@ -2147,6 +2156,9 @@ class MLDocument extends parent_node_1.MLParentNode {
|
|
|
2147
2156
|
const targetDescendants = nodeRule.inheritance ? descendants : children;
|
|
2148
2157
|
Object.keys(nodeRuleRules).forEach(ruleName => {
|
|
2149
2158
|
const rule = nodeRuleRules[ruleName];
|
|
2159
|
+
if (rule == null) {
|
|
2160
|
+
return;
|
|
2161
|
+
}
|
|
2150
2162
|
const convertedRule = (0, ml_config_1.exchangeValueOnRule)(rule, matches.data || {});
|
|
2151
2163
|
if (convertedRule === undefined) {
|
|
2152
2164
|
return;
|
|
@@ -106,8 +106,8 @@ class MLDomTokenList extends Array {
|
|
|
106
106
|
throw new unexpected_call_error_1.default('Not supported "toggle" method');
|
|
107
107
|
}
|
|
108
108
|
_pick(token, _offset = 0) {
|
|
109
|
-
var _a, _b, _c, _d, _e, _f;
|
|
110
|
-
token = token.trim().split(/\s+/g)[0];
|
|
109
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
110
|
+
token = (_a = token.trim().split(/\s+/g)[0]) !== null && _a !== void 0 ? _a : '';
|
|
111
111
|
if (!token) {
|
|
112
112
|
return null;
|
|
113
113
|
}
|
|
@@ -123,9 +123,9 @@ class MLDomTokenList extends Array {
|
|
|
123
123
|
const startCol = (0, parser_utils_1.getCol)(tslib_1.__classPrivateFieldGet(this, _MLDomTokenList_origin, "f"), startOffset);
|
|
124
124
|
return {
|
|
125
125
|
raw: token,
|
|
126
|
-
startOffset: ((
|
|
127
|
-
startLine: ((
|
|
128
|
-
startCol: ((
|
|
126
|
+
startOffset: ((_c = (_b = ownerAttr.valueNode) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : 0) + startOffset,
|
|
127
|
+
startLine: ((_e = (_d = ownerAttr.valueNode) === null || _d === void 0 ? void 0 : _d.startLine) !== null && _e !== void 0 ? _e : 0) + (startLine - 1),
|
|
128
|
+
startCol: ((_g = (_f = ownerAttr.valueNode) === null || _f === void 0 ? void 0 : _f.startCol) !== null && _g !== void 0 ? _g : 0) + (startCol - 1),
|
|
129
129
|
rule: ownerAttr.rule,
|
|
130
130
|
_searchedIndex: startOffset,
|
|
131
131
|
};
|
|
@@ -1657,7 +1657,7 @@ export declare class MLElement<T extends RuleConfigValue, O = null>
|
|
|
1657
1657
|
* @implements DOM API: `Element`
|
|
1658
1658
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-element-getelementsbyclassname
|
|
1659
1659
|
*/
|
|
1660
|
-
getElementsByTagName(qualifiedName: string): ReturnType<typeof Element['prototype']['getElementsByTagName']>;
|
|
1660
|
+
getElementsByTagName(qualifiedName: string): ReturnType<(typeof Element)['prototype']['getElementsByTagName']>;
|
|
1661
1661
|
/**
|
|
1662
1662
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
1663
1663
|
*
|
|
@@ -17,7 +17,8 @@ class MLNamedNodeMap extends Array {
|
|
|
17
17
|
throw new unexpected_call_error_1.default('Not supported "getNamedItemNS" method');
|
|
18
18
|
}
|
|
19
19
|
item(index) {
|
|
20
|
-
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
|
|
21
22
|
}
|
|
22
23
|
/**
|
|
23
24
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -6,7 +6,21 @@ class MLNodeList extends Array {
|
|
|
6
6
|
return super.forEach.bind(this)((v, k) => callbackfn(v, k, thisArg !== null && thisArg !== void 0 ? thisArg : this));
|
|
7
7
|
}
|
|
8
8
|
item(index) {
|
|
9
|
-
|
|
9
|
+
const node = this[index];
|
|
10
|
+
if (!node) {
|
|
11
|
+
/**
|
|
12
|
+
* ⚠ TYPE CONTRADICTION
|
|
13
|
+
*
|
|
14
|
+
* It throws an error because it should return null but the `item` method of `NodeListOf` doesn't return null in the type definition of TypeScript.
|
|
15
|
+
*
|
|
16
|
+
* @see https://www.w3.org/TR/DOM-Level-2-Core/core.html#ID-844377136
|
|
17
|
+
*
|
|
18
|
+
* > item
|
|
19
|
+
* > Returns the index-th item in the collection. If index is greater than or equal to the number of nodes in the list, this returns null.
|
|
20
|
+
*/
|
|
21
|
+
throw new ReferenceError('Invalid index');
|
|
22
|
+
}
|
|
23
|
+
return node;
|
|
10
24
|
}
|
|
11
25
|
}
|
|
12
26
|
function toNodeList(nodes) {
|
|
@@ -16,7 +30,8 @@ function toNodeList(nodes) {
|
|
|
16
30
|
exports.toNodeList = toNodeList;
|
|
17
31
|
class MLHTMLCollection extends Array {
|
|
18
32
|
item(index) {
|
|
19
|
-
|
|
33
|
+
var _a;
|
|
34
|
+
return (_a = this[index]) !== null && _a !== void 0 ? _a : null;
|
|
20
35
|
}
|
|
21
36
|
namedItem(name) {
|
|
22
37
|
return this.find(el => el.getAttribute('name') === name) || null;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type { RuleInfo } from '../..';
|
|
2
1
|
import type { MLBlock } from './block';
|
|
3
2
|
import type { MLChildNode } from './child-node';
|
|
4
3
|
import type { MLDocument } from './document';
|
|
5
4
|
import type { MLDocumentFragment } from './document-fragment';
|
|
6
5
|
import type { MLElement } from './element';
|
|
7
6
|
import type { MarkuplintPreprocessorBlockType, NodeType, NodeTypeOf } from './types';
|
|
7
|
+
import type { RuleInfo } from '../..';
|
|
8
8
|
import type { MLASTAbstractNode } from '@markuplint/ml-ast';
|
|
9
9
|
import type { AnyRule, RuleConfigValue } from '@markuplint/ml-config';
|
|
10
10
|
import { MLToken } from '../token/token';
|
|
@@ -143,7 +143,7 @@ export declare abstract class MLNode<
|
|
|
143
143
|
* @implements DOM API: `Node`
|
|
144
144
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-firstchild%E2%91%A0
|
|
145
145
|
*/
|
|
146
|
-
get firstChild(): MLChildNode<T, O
|
|
146
|
+
get firstChild(): MLChildNode<T, O> | null;
|
|
147
147
|
/**
|
|
148
148
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
149
149
|
*
|
|
@@ -159,7 +159,7 @@ export declare abstract class MLNode<
|
|
|
159
159
|
* @implements DOM API: `Node`
|
|
160
160
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
|
|
161
161
|
*/
|
|
162
|
-
get lastChild(): MLChildNode<T, O
|
|
162
|
+
get lastChild(): MLChildNode<T, O> | null;
|
|
163
163
|
/**
|
|
164
164
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
165
165
|
*/
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -187,7 +187,8 @@ class MLNode extends token_1.MLToken {
|
|
|
187
187
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-firstchild%E2%91%A0
|
|
188
188
|
*/
|
|
189
189
|
get firstChild() {
|
|
190
|
-
|
|
190
|
+
var _a;
|
|
191
|
+
return (_a = this.childNodes[0]) !== null && _a !== void 0 ? _a : null;
|
|
191
192
|
}
|
|
192
193
|
/**
|
|
193
194
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
@@ -207,7 +208,8 @@ class MLNode extends token_1.MLToken {
|
|
|
207
208
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-lastchild%E2%91%A0
|
|
208
209
|
*/
|
|
209
210
|
get lastChild() {
|
|
210
|
-
|
|
211
|
+
var _a;
|
|
212
|
+
return (_a = this.childNodes[this.childNodes.length - 1]) !== null && _a !== void 0 ? _a : null;
|
|
211
213
|
}
|
|
212
214
|
/**
|
|
213
215
|
* @implements `@markuplint/ml-core` API: `MLNode`
|
|
@@ -29,12 +29,12 @@ export declare abstract class MLParentNode<
|
|
|
29
29
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
30
30
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-firstelementchild%E2%91%A0
|
|
31
31
|
*/
|
|
32
|
-
get firstElementChild(): MLElement<T, O
|
|
32
|
+
get firstElementChild(): MLElement<T, O> | null;
|
|
33
33
|
/**
|
|
34
34
|
* @implements DOM API: `Element`, `Document`, `DocumentFragment`
|
|
35
35
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-parentnode-lastelementchild%E2%91%A0
|
|
36
36
|
*/
|
|
37
|
-
get lastElementChild(): MLElement<T, O
|
|
37
|
+
get lastElementChild(): MLElement<T, O> | null;
|
|
38
38
|
/**
|
|
39
39
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
40
40
|
*
|
|
@@ -24,6 +24,9 @@ class RuleMapper {
|
|
|
24
24
|
ruleMapperNodeLog('<%s>', node.nodeName);
|
|
25
25
|
Object.keys(rules).forEach(ruleName => {
|
|
26
26
|
const rule = rules[ruleName];
|
|
27
|
+
if (!rule) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
27
30
|
node.rules[ruleName] = rule.rule;
|
|
28
31
|
ruleMapperNodeRuleLog('[from: %s(%s)] %s: %o', rule.from, rule.specificity, ruleName, rule.rule);
|
|
29
32
|
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { MLToken } from '../token/token';
|
|
2
1
|
import type { MLAttr } from './attr';
|
|
3
2
|
import type { MLBlock } from './block';
|
|
4
3
|
import type { MLComment } from './comment';
|
|
@@ -8,6 +7,7 @@ import type { MLDocumentType } from './document-type';
|
|
|
8
7
|
import type { MLElement } from './element';
|
|
9
8
|
import type { MLNode } from './node';
|
|
10
9
|
import type { MLText } from './text';
|
|
10
|
+
import type { MLToken } from '../token/token';
|
|
11
11
|
import type {
|
|
12
12
|
MLASTAbstractNode,
|
|
13
13
|
MLASTAttr,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { MLDocument } from '../ml-dom/node/document';
|
|
2
1
|
import type { CheckerReport } from './types';
|
|
2
|
+
import type { MLDocument } from '../ml-dom/node/document';
|
|
3
3
|
import type { LocaleSet, Translator } from '@markuplint/i18n';
|
|
4
4
|
import type { Report, RuleConfigValue } from '@markuplint/ml-config';
|
|
5
5
|
export declare class MLRuleContext<T extends RuleConfigValue, O = null> {
|
package/lib/ml-rule/ml-rule.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import type { RuleSeed } from './types';
|
|
1
2
|
import type { Ruleset } from '..';
|
|
2
3
|
import type { MLDocument } from '../ml-dom/node/document';
|
|
3
|
-
import type { RuleSeed } from './types';
|
|
4
4
|
import type { LocaleSet } from '@markuplint/i18n';
|
|
5
5
|
import type { GlobalRuleInfo, RuleConfig, RuleConfigValue, RuleInfo, Severity, Violation } from '@markuplint/ml-config';
|
|
6
6
|
export declare class MLRule<T extends RuleConfigValue, O = null> {
|
package/lib/ml-rule/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Attr, Element } from '../ml-dom';
|
|
2
1
|
import type { MLRuleContext } from './ml-rule-context';
|
|
2
|
+
import type { Attr, Element } from '../ml-dom';
|
|
3
3
|
import type { Translator } from '@markuplint/i18n';
|
|
4
4
|
import type { Report, RuleConfigValue, Severity } from '@markuplint/ml-config';
|
|
5
5
|
export type RuleSeed<T extends RuleConfigValue = boolean, O = null> = {
|
package/lib/test/index.js
CHANGED
|
@@ -27,7 +27,7 @@ exports.createTestTokenList = createTestTokenList;
|
|
|
27
27
|
function createTestElement(sourceCode, options) {
|
|
28
28
|
const document = createTestDocument(sourceCode, options);
|
|
29
29
|
const el = document.nodeList[0];
|
|
30
|
-
if (el.is(el.ELEMENT_NODE)) {
|
|
30
|
+
if (el && el.is(el.ELEMENT_NODE)) {
|
|
31
31
|
return el;
|
|
32
32
|
}
|
|
33
33
|
throw TypeError(`Could not parse it to be an element from: ${sourceCode}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.0",
|
|
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>",
|
|
@@ -24,14 +24,14 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"@markuplint/config-presets": "3.3.0",
|
|
27
|
-
"@markuplint/html-parser": "3.
|
|
28
|
-
"@markuplint/html-spec": "3.
|
|
29
|
-
"@markuplint/i18n": "3.
|
|
27
|
+
"@markuplint/html-parser": "3.4.0",
|
|
28
|
+
"@markuplint/html-spec": "3.4.0",
|
|
29
|
+
"@markuplint/i18n": "3.4.0",
|
|
30
30
|
"@markuplint/ml-ast": "3.0.0",
|
|
31
|
-
"@markuplint/ml-config": "3.
|
|
32
|
-
"@markuplint/ml-spec": "3.
|
|
33
|
-
"@markuplint/parser-utils": "3.
|
|
34
|
-
"@markuplint/selector": "3.
|
|
31
|
+
"@markuplint/ml-config": "3.4.0",
|
|
32
|
+
"@markuplint/ml-spec": "3.4.0",
|
|
33
|
+
"@markuplint/parser-utils": "3.4.0",
|
|
34
|
+
"@markuplint/selector": "3.4.0",
|
|
35
35
|
"debug": "^4.3.4",
|
|
36
36
|
"tslib": "^2.4.1"
|
|
37
37
|
},
|
|
@@ -39,5 +39,5 @@
|
|
|
39
39
|
"@markuplint/html-parser": "3.3.0",
|
|
40
40
|
"@types/debug": "^4.1.7"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "a83e0f5f214a9bbcc0286b9e269074ddca6189e7"
|
|
43
43
|
}
|