@markuplint/ml-core 4.7.1 → 4.8.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/CHANGELOG.md +11 -0
- package/lib/ml-dom/helper/create-node.js +1 -0
- package/lib/ml-dom/node/block.js +1 -1
- package/lib/ml-dom/node/element.js +2 -2
- package/lib/ml-dom/node/node.d.ts +10 -1
- package/lib/ml-dom/node/node.js +54 -39
- package/package.json +12 -12
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [4.8.0](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.7.2...@markuplint/ml-core@4.8.0) (2024-05-28)
|
|
7
|
+
|
|
8
|
+
### Features
|
|
9
|
+
|
|
10
|
+
- **ml-core:** change `childNodes` to no longer return fragment nodes ([bc41f13](https://github.com/markuplint/markuplint/commit/bc41f13c15ee61616ab9673ed81df52d19786c31))
|
|
11
|
+
- **ml-core:** separate getter `childNodes` and method `getPureChildNodes()` ([a98d22c](https://github.com/markuplint/markuplint/commit/a98d22c5bd291158ceae21c52580136e49bb938b))
|
|
12
|
+
|
|
13
|
+
## [4.7.2](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.7.1...@markuplint/ml-core@4.7.2) (2024-05-12)
|
|
14
|
+
|
|
15
|
+
**Note:** Version bump only for package @markuplint/ml-core
|
|
16
|
+
|
|
6
17
|
## [4.7.1](https://github.com/markuplint/markuplint/compare/@markuplint/ml-core@4.7.1-alpha.0...@markuplint/ml-core@4.7.1) (2024-05-04)
|
|
7
18
|
|
|
8
19
|
**Note:** Version bump only for package @markuplint/ml-core
|
package/lib/ml-dom/node/block.js
CHANGED
|
@@ -4,7 +4,7 @@ export class MLBlock extends MLNode {
|
|
|
4
4
|
constructor(astNode,
|
|
5
5
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
6
6
|
document) {
|
|
7
|
-
super(astNode, document);
|
|
7
|
+
super(astNode, document, astNode.isFragment);
|
|
8
8
|
// TODO:
|
|
9
9
|
this.isTransparent = true;
|
|
10
10
|
this.conditionalType = astNode.conditionalType;
|
|
@@ -28,7 +28,7 @@ export class MLElement extends MLParentNode {
|
|
|
28
28
|
constructor(astNode,
|
|
29
29
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
30
30
|
document) {
|
|
31
|
-
super(astNode, document);
|
|
31
|
+
super(astNode, document, astNode.isFragment);
|
|
32
32
|
_MLElement_attributes.set(this, void 0);
|
|
33
33
|
_MLElement_fixedNodeName.set(this, void 0);
|
|
34
34
|
_MLElement_getChildElementsAndTextNodeWithoutWhitespacesCache.set(this, null);
|
|
@@ -2339,7 +2339,7 @@ export class MLElement extends MLParentNode {
|
|
|
2339
2339
|
* @implements `@markuplint/ml-core` API: `MLElement`
|
|
2340
2340
|
*/
|
|
2341
2341
|
hasMutableChildren(attr = false) {
|
|
2342
|
-
for (const child of this.
|
|
2342
|
+
for (const child of this.getPureChildNodes()) {
|
|
2343
2343
|
if (child.is(child.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
2344
2344
|
if (child.conditionalType) {
|
|
2345
2345
|
continue;
|
|
@@ -107,12 +107,16 @@ export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainD
|
|
|
107
107
|
* @see https://dom.spec.whatwg.org/#interface-node
|
|
108
108
|
*/
|
|
109
109
|
readonly TEXT_NODE = 3;
|
|
110
|
+
/**
|
|
111
|
+
* Returns child nodes when parent node access by `childNodes` property.
|
|
112
|
+
*/
|
|
113
|
+
readonly isFragment: boolean;
|
|
110
114
|
/**
|
|
111
115
|
*
|
|
112
116
|
*/
|
|
113
117
|
readonly rules: Record<string, AnyRule>;
|
|
114
118
|
protected _astToken: A;
|
|
115
|
-
constructor(astNode: A, document: MLDocument<T, O
|
|
119
|
+
constructor(astNode: A, document: MLDocument<T, O>, isFragment?: boolean);
|
|
116
120
|
/**
|
|
117
121
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
118
122
|
*
|
|
@@ -390,6 +394,11 @@ export declare abstract class MLNode<T extends RuleConfigValue, O extends PlainD
|
|
|
390
394
|
* @returns An array of matched child nodes.
|
|
391
395
|
*/
|
|
392
396
|
findSubsequentNodes(selector?: string): MLChildNode<T, O>[];
|
|
397
|
+
/**
|
|
398
|
+
*
|
|
399
|
+
* @implements DOM API: `MLNode`
|
|
400
|
+
*/
|
|
401
|
+
getPureChildNodes(): NodeListOf<MLChildNode<T, O>>;
|
|
393
402
|
/**
|
|
394
403
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
395
404
|
*
|
package/lib/ml-dom/node/node.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
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
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var
|
|
12
|
+
var _MLNode_pureChildNodesCache, _MLNode_ownerDocument, _MLNode_prevToken, _MLNode_conditionalChildNodes;
|
|
13
13
|
import { branchesToPatterns } from '@markuplint/shared';
|
|
14
14
|
import { MLToken } from '../token/token.js';
|
|
15
15
|
import { isChildNode } from './child-node.js';
|
|
@@ -19,7 +19,7 @@ import { UnexpectedCallError } from './unexpected-call-error.js';
|
|
|
19
19
|
export class MLNode extends MLToken {
|
|
20
20
|
constructor(astNode,
|
|
21
21
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
22
|
-
document) {
|
|
22
|
+
document, isFragment) {
|
|
23
23
|
super(astNode);
|
|
24
24
|
/**
|
|
25
25
|
* @implements DOM API: `Node`
|
|
@@ -121,7 +121,7 @@ export class MLNode extends MLToken {
|
|
|
121
121
|
/**
|
|
122
122
|
* Cached `childNodes` property
|
|
123
123
|
*/
|
|
124
|
-
|
|
124
|
+
_MLNode_pureChildNodesCache.set(this, void 0);
|
|
125
125
|
/**
|
|
126
126
|
* Owner `Document`
|
|
127
127
|
*
|
|
@@ -143,6 +143,7 @@ export class MLNode extends MLToken {
|
|
|
143
143
|
this.rules = {};
|
|
144
144
|
this._astToken = astNode;
|
|
145
145
|
__classPrivateFieldSet(this, _MLNode_ownerDocument, document, "f");
|
|
146
|
+
this.isFragment = !!isFragment;
|
|
146
147
|
nodeStore.setNode(astNode, this);
|
|
147
148
|
}
|
|
148
149
|
/**
|
|
@@ -163,41 +164,14 @@ export class MLNode extends MLToken {
|
|
|
163
164
|
* @see https://dom.spec.whatwg.org/#ref-for-dom-node-childnodes%E2%91%A0
|
|
164
165
|
*/
|
|
165
166
|
get childNodes() {
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
const childNodes = [];
|
|
171
|
-
for (const node of this.nodeList) {
|
|
172
|
-
if (isChildNode(node) && (node.parentNode === this || node.parentNode === null)) {
|
|
173
|
-
childNodes.push(node);
|
|
174
|
-
}
|
|
167
|
+
const pureChildNodes = [...this.getPureChildNodes()];
|
|
168
|
+
const childNodes = pureChildNodes.flatMap(node => {
|
|
169
|
+
if (node.isFragment) {
|
|
170
|
+
return [...node.childNodes];
|
|
175
171
|
}
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
if (this.is(this.DOCUMENT_FRAGMENT_NODE) ||
|
|
181
|
-
this.is(this.ELEMENT_NODE) ||
|
|
182
|
-
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
183
|
-
const astChildren =
|
|
184
|
-
// @ts-ignore
|
|
185
|
-
this._astToken?.childNodes?.filter(node => {
|
|
186
|
-
if (node.type === 'endtag' || node.type === 'invalid') {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
return node;
|
|
190
|
-
}) ?? [];
|
|
191
|
-
const childNodes = astChildren
|
|
192
|
-
.map(node => nodeStore.getNode(node))
|
|
193
|
-
.filter(node => isChildNode(node));
|
|
194
|
-
// Cache
|
|
195
|
-
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList(childNodes), "f");
|
|
196
|
-
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
197
|
-
}
|
|
198
|
-
// Cache
|
|
199
|
-
__classPrivateFieldSet(this, _MLNode_childNodes, toNodeList([]), "f");
|
|
200
|
-
return __classPrivateFieldGet(this, _MLNode_childNodes, "f");
|
|
172
|
+
return [node];
|
|
173
|
+
});
|
|
174
|
+
return toNodeList(childNodes);
|
|
201
175
|
}
|
|
202
176
|
/**
|
|
203
177
|
* The first node that may be `Element`, `Text`, and `CommentNode`.
|
|
@@ -690,6 +664,47 @@ export class MLNode extends MLToken {
|
|
|
690
664
|
}
|
|
691
665
|
return matched;
|
|
692
666
|
}
|
|
667
|
+
/**
|
|
668
|
+
*
|
|
669
|
+
* @implements DOM API: `MLNode`
|
|
670
|
+
*/
|
|
671
|
+
getPureChildNodes() {
|
|
672
|
+
if (__classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f") != null) {
|
|
673
|
+
return __classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f");
|
|
674
|
+
}
|
|
675
|
+
if (this.is(this.DOCUMENT_NODE)) {
|
|
676
|
+
const childNodes = [];
|
|
677
|
+
for (const node of this.nodeList) {
|
|
678
|
+
if (isChildNode(node) && (node.parentNode === this || node.parentNode === null)) {
|
|
679
|
+
childNodes.push(node);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
// Cache
|
|
683
|
+
__classPrivateFieldSet(this, _MLNode_pureChildNodesCache, toNodeList(childNodes), "f");
|
|
684
|
+
return __classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f");
|
|
685
|
+
}
|
|
686
|
+
if (this.is(this.DOCUMENT_FRAGMENT_NODE) ||
|
|
687
|
+
this.is(this.ELEMENT_NODE) ||
|
|
688
|
+
this.is(this.MARKUPLINT_PREPROCESSOR_BLOCK)) {
|
|
689
|
+
const astChildren =
|
|
690
|
+
// @ts-ignore
|
|
691
|
+
this._astToken?.childNodes?.filter(node => {
|
|
692
|
+
if (node.type === 'endtag' || node.type === 'invalid') {
|
|
693
|
+
return null;
|
|
694
|
+
}
|
|
695
|
+
return node;
|
|
696
|
+
}) ?? [];
|
|
697
|
+
const childNodes = astChildren
|
|
698
|
+
.map(node => nodeStore.getNode(node))
|
|
699
|
+
.filter(node => isChildNode(node));
|
|
700
|
+
// Cache
|
|
701
|
+
__classPrivateFieldSet(this, _MLNode_pureChildNodesCache, toNodeList(childNodes), "f");
|
|
702
|
+
return __classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f");
|
|
703
|
+
}
|
|
704
|
+
// Cache
|
|
705
|
+
__classPrivateFieldSet(this, _MLNode_pureChildNodesCache, toNodeList([]), "f");
|
|
706
|
+
return __classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f");
|
|
707
|
+
}
|
|
693
708
|
/**
|
|
694
709
|
* **IT THROWS AN ERROR WHEN CALLING THIS.**
|
|
695
710
|
*
|
|
@@ -844,7 +859,7 @@ export class MLNode extends MLToken {
|
|
|
844
859
|
resetChildren(
|
|
845
860
|
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
846
861
|
childNodes) {
|
|
847
|
-
__classPrivateFieldSet(this,
|
|
862
|
+
__classPrivateFieldSet(this, _MLNode_pureChildNodesCache, childNodes ?? __classPrivateFieldGet(this, _MLNode_pureChildNodesCache, "f"), "f");
|
|
848
863
|
}
|
|
849
864
|
}
|
|
850
|
-
|
|
865
|
+
_MLNode_pureChildNodesCache = new WeakMap(), _MLNode_ownerDocument = new WeakMap(), _MLNode_prevToken = new WeakMap(), _MLNode_conditionalChildNodes = new WeakMap();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markuplint/ml-core",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.8.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>",
|
|
@@ -28,20 +28,20 @@
|
|
|
28
28
|
"./lib/configs.js": "./lib/configs.browser.js"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@markuplint/config-presets": "4.5.
|
|
32
|
-
"@markuplint/html-parser": "4.6.
|
|
33
|
-
"@markuplint/html-spec": "4.
|
|
31
|
+
"@markuplint/config-presets": "4.5.2",
|
|
32
|
+
"@markuplint/html-parser": "4.6.3",
|
|
33
|
+
"@markuplint/html-spec": "4.8.0",
|
|
34
34
|
"@markuplint/i18n": "4.5.0",
|
|
35
|
-
"@markuplint/ml-ast": "4.
|
|
36
|
-
"@markuplint/ml-config": "4.
|
|
37
|
-
"@markuplint/ml-spec": "4.
|
|
38
|
-
"@markuplint/parser-utils": "4.6.
|
|
39
|
-
"@markuplint/selector": "4.6.
|
|
40
|
-
"@markuplint/shared": "4.
|
|
35
|
+
"@markuplint/ml-ast": "4.4.0",
|
|
36
|
+
"@markuplint/ml-config": "4.7.0",
|
|
37
|
+
"@markuplint/ml-spec": "4.6.1",
|
|
38
|
+
"@markuplint/parser-utils": "4.6.3",
|
|
39
|
+
"@markuplint/selector": "4.6.3",
|
|
40
|
+
"@markuplint/shared": "4.4.1",
|
|
41
41
|
"@types/debug": "4.1.12",
|
|
42
42
|
"debug": "4.3.4",
|
|
43
43
|
"is-plain-object": "5.0.0",
|
|
44
|
-
"type-fest": "4.18.
|
|
44
|
+
"type-fest": "4.18.3"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "bf70c41b1d2497e85b73c9ecd5551eb522e6bdfc"
|
|
47
47
|
}
|