mirror of
https://github.com/DavidAnson/markdownlint.git
synced 2025-12-16 14:00:13 +01:00
Refactor Token.parent() to Token.parent, add validation tests for parent, fix parent in htmlFlow scenario, improve type saftey slightly.
This commit is contained in:
parent
06466905a5
commit
2a56f130c1
9 changed files with 73 additions and 372 deletions
|
|
@ -1489,7 +1489,11 @@ test("customRulesParamsAreFrozen", (t) => {
|
|||
t.true(Object.isFrozen(current) || (current === params));
|
||||
for (const name of Object.getOwnPropertyNames(current)) {
|
||||
const value = current[name];
|
||||
if (value && (typeof value === "object")) {
|
||||
if (
|
||||
value &&
|
||||
(typeof value === "object") &&
|
||||
(name !== "parent")
|
||||
) {
|
||||
pending.push(value);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,9 +17,26 @@ const testTokens = new Promise((resolve, reject) => {
|
|||
testContent.then(parse).then(resolve, reject);
|
||||
});
|
||||
|
||||
const cloneToken = (token) => {
|
||||
for (const child of token.children) {
|
||||
const expectedParent = (token.type ? token : null);
|
||||
if (child.parent !== expectedParent) {
|
||||
throw new Error("Unexpected parent.");
|
||||
}
|
||||
}
|
||||
const clone = { ...token };
|
||||
delete clone.parent;
|
||||
clone.children = clone.children.map(cloneToken);
|
||||
return clone;
|
||||
};
|
||||
|
||||
const cloneTokens = (tokens) => (
|
||||
cloneToken({ "children": tokens }).children
|
||||
);
|
||||
|
||||
test("parse", async(t) => {
|
||||
t.plan(1);
|
||||
t.snapshot(await testTokens, "Unexpected tokens");
|
||||
t.snapshot(cloneTokens(await testTokens), "Unexpected tokens");
|
||||
});
|
||||
|
||||
test("getMicromarkEvents/filterByPredicate", async(t) => {
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Binary file not shown.
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue