Improve type safety by strongly-typing the micromark token type property everywhere.

This commit is contained in:
David Anson 2024-02-29 23:05:27 -08:00
parent 828ae3541a
commit 28e1b23955
7 changed files with 106 additions and 50 deletions

View file

@ -6,12 +6,12 @@ const { addErrorDetailIf } = require("../helpers");
const { filterByTypes, getTokenParentOfType, inHtmlFlow } =
require("../helpers/micromark.cjs");
/**
* @typedef {import("../helpers/micromark.cjs").Token} Token
*/
// eslint-disable-next-line jsdoc/valid-types
/** @type import("micromark-util-types").TokenType[] */
const unorderedListTypes =
[ "blockQuotePrefix", "listItemPrefix", "listUnordered" ];
// eslint-disable-next-line jsdoc/valid-types
/** @type import("micromark-util-types").TokenType[] */
const unorderedParentTypes =
[ "blockQuote", "listOrdered", "listUnordered" ];
@ -39,7 +39,7 @@ module.exports = {
lastBlockQuotePrefix = token;
} else if (type === "listUnordered") {
let nesting = 0;
/** @type {Token | null} */
/** @type {import("../helpers/micromark.cjs").Token | null} */
let current = token;
while (
(current = getTokenParentOfType(current, unorderedParentTypes))