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

@ -19,15 +19,11 @@ const tokensInclude = new Set(
[ "characterEscapeValue", "codeTextData", "data" ]
);
/**
* @typedef {import("../helpers/micromark.cjs").Token} Token
*/
/**
* Converts a Markdown heading into an HTML fragment according to the rules
* used by GitHub.
*
* @param {Token} headingText Heading text token.
* @param {import("../helpers/micromark.cjs").Token} headingText Heading text token.
* @returns {string} Fragment string for heading.
*/
function convertHeadingToHTMLFragment(headingText) {
@ -56,7 +52,7 @@ function convertHeadingToHTMLFragment(headingText) {
/**
* Unescapes the text of a String-type micromark Token.
*
* @param {Token} token String-type micromark Token.
* @param {import("../helpers/micromark.cjs").Token} token String-type micromark Token.
* @returns {string} Unescaped token text.
*/
function unescapeStringTokenText(token) {
@ -112,6 +108,8 @@ module.exports = {
}
// Process link and definition fragments
// eslint-disable-next-line jsdoc/valid-types
/** @type import("../helpers/micromark.cjs").TokenType[][] */
const parentChilds = [
[ "link", "resourceDestinationString" ],
[ "definition", "definitionDestinationString" ]