@@ -111,10 +111,11 @@ module.exports.cloneIfArray = cloneIfArray;
111111/**
112112 * Clones the input if it is a URL.
113113 *
114- * @param {Object } url Object of unknown type.
114+ * @param {Object | undefined } url Object of unknown type.
115115 * @returns {Object } Clone of obj iff obj is a URL.
116116 */
117117function cloneIfUrl ( url ) {
118+ // @ts -ignore
118119 return isUrl ( url ) ? new URL ( url ) : url ;
119120}
120121module . exports . cloneIfUrl = cloneIfUrl ;
@@ -139,7 +140,7 @@ module.exports.getHtmlAttributeRe = function getHtmlAttributeRe(name) {
139140function isBlankLine ( line ) {
140141 const startComment = "<!--" ;
141142 const endComment = "-->" ;
142- const removeComments = ( s ) => {
143+ const removeComments = ( /** @type { string } */ s ) => {
143144 while ( true ) {
144145 const start = s . indexOf ( startComment ) ;
145146 const end = s . indexOf ( endComment ) ;
@@ -177,8 +178,8 @@ const startsWithPipeRe = /^ *\|/;
177178const notCrLfRe = / [ ^ \r \n ] / g;
178179const notSpaceCrLfRe = / [ ^ \r \n ] / g;
179180const trailingSpaceRe = / + [ \r \n ] / g;
180- const replaceTrailingSpace = ( s ) => s . replace ( notCrLfRe , safeCommentCharacter ) ;
181- module . exports . clearHtmlCommentText = function clearHtmlCommentText ( text ) {
181+ const replaceTrailingSpace = ( /** @type { string } */ s ) => s . replace ( notCrLfRe , safeCommentCharacter ) ;
182+ module . exports . clearHtmlCommentText = function clearHtmlCommentText ( /** @type { string } */ text ) {
182183 let i = 0 ;
183184 while ( ( i = text . indexOf ( htmlCommentBegin , i ) ) !== - 1 ) {
184185 const j = text . indexOf ( htmlCommentEnd , i + 2 ) ;
@@ -220,7 +221,7 @@ module.exports.clearHtmlCommentText = function clearHtmlCommentText(text) {
220221} ;
221222
222223// Escapes a string for use in a RegExp
223- module . exports . escapeForRegExp = function escapeForRegExp ( str ) {
224+ module . exports . escapeForRegExp = function escapeForRegExp ( /** @type { string } */ str ) {
224225 return str . replace ( / [ - / \\ ^ $ * + ? . ( ) | [ \] { } ] / g, "\\$&" ) ;
225226} ;
226227
@@ -355,7 +356,7 @@ module.exports.hasOverlap = function hasOverlap(rangeA, rangeB) {
355356
356357// Determines if the front matter includes a title
357358module . exports . frontMatterHasTitle =
358- function frontMatterHasTitle ( frontMatterLines , frontMatterTitlePattern ) {
359+ function frontMatterHasTitle ( /** @type { readonly string[] } */ frontMatterLines , /** @type { string } */ frontMatterTitlePattern ) {
359360 const ignoreFrontMatter =
360361 ( frontMatterTitlePattern !== undefined ) && ! frontMatterTitlePattern ;
361362 const frontMatterTitleRe =
@@ -367,18 +368,31 @@ module.exports.frontMatterHasTitle =
367368 frontMatterLines . some ( ( line ) => frontMatterTitleRe . test ( line ) ) ;
368369 } ;
369370
371+ /**
372+ * Result object for getReferenceLinkImageData.
373+ *
374+ * @typedef {Object } GetReferenceLinkImageDataResult
375+ * @property {Map<string, number[][]> } references References.
376+ * @property {Map<string, number[][]> } shortcuts Shortcuts.
377+ * @property {Map<string, [number, string]> } definitions Definitions.
378+ * @property {[string, number][] } duplicateDefinitions Duplicate definitions.
379+ * @property {number[] } definitionLineIndices Definition line indices.
380+ */
381+
370382/**
371383 * Returns an object with information about reference links and images.
372384 *
373385 * @param {MicromarkToken[] } tokens Micromark tokens.
374- * @returns {Object } Reference link/image data.
386+ * @returns {GetReferenceLinkImageDataResult } Reference link/image data.
375387 */
376388function getReferenceLinkImageData ( tokens ) {
377- const normalizeReference = ( s ) => s . toLowerCase ( ) . trim ( ) . replace ( / \s + / g, " " ) ;
378- const getText = ( t ) => t ?. children . filter ( ( c ) => c . type !== "blockQuotePrefix" ) . map ( ( c ) => c . text ) . join ( "" ) ;
389+ const normalizeReference = ( /** @type {string } */ s ) => s . toLowerCase ( ) . trim ( ) . replace ( / \s + / g, " " ) ;
390+ const getText = ( /** @type {MicromarkToken } */ t ) => t ?. children . filter ( ( c ) => c . type !== "blockQuotePrefix" ) . map ( ( c ) => c . text ) . join ( "" ) ;
391+ /** @type {Map<string, number[][]> } */
379392 const references = new Map ( ) ;
393+ /** @type {Map<string, number[][]> } */
380394 const shortcuts = new Map ( ) ;
381- const addReferenceToDictionary = ( token , label , isShortcut ) => {
395+ const addReferenceToDictionary = ( /** @type { MicromarkToken } */ token , /** @type { string } */ label , /** @type { boolean } */ isShortcut ) => {
382396 const referenceDatum = [
383397 token . startLine - 1 ,
384398 token . startColumn - 1 ,
@@ -390,8 +404,11 @@ function getReferenceLinkImageData(tokens) {
390404 referenceData . push ( referenceDatum ) ;
391405 dictionary . set ( reference , referenceData ) ;
392406 } ;
407+ /** @type {Map<string, [number, string]> } */
393408 const definitions = new Map ( ) ;
409+ /** @type {number[] } */
394410 const definitionLineIndices = [ ] ;
411+ /** @type {[string, number][] } */
395412 const duplicateDefinitions = [ ] ;
396413 const filteredTokens =
397414 micromark . filterByTypes (
@@ -433,7 +450,7 @@ function getReferenceLinkImageData(tokens) {
433450 micromark . getDescendantsByType ( parent , [ "definitionDestination" , "definitionDestinationRaw" , "definitionDestinationString" ] ) [ 0 ] ?. text ;
434451 definitions . set (
435452 reference ,
436- [ token . startLine - 1 , destinationString ]
453+ [ token . startLine - 1 , destinationString || "" ]
437454 ) ;
438455 }
439456 }
@@ -490,7 +507,7 @@ module.exports.getReferenceLinkImageData = getReferenceLinkImageData;
490507 * Gets the most common line ending, falling back to the platform default.
491508 *
492509 * @param {string } input Markdown content to analyze.
493- * @param {Object } [os] Node.js "os" module.
510+ * @param {{EOL: string} } [os] Node.js "os" module.
494511 * @returns {string } Preferred line ending.
495512 */
496513function getPreferredLineEnding ( input , os ) {
@@ -530,7 +547,7 @@ module.exports.getPreferredLineEnding = getPreferredLineEnding;
530547 * Expands a path with a tilde to an absolute path.
531548 *
532549 * @param {string } file Path that may begin with a tilde.
533- * @param {Object } os Node.js "os" module.
550+ * @param {{homedir: () => string} } os Node.js "os" module.
534551 * @returns {string } Absolute path (or original path).
535552 */
536553function expandTildePath ( file , os ) {
@@ -591,6 +608,7 @@ function convertLintErrorsVersion2To1(errors) {
591608 * @returns {LintErrors } Lint errors (v0).
592609 */
593610function convertLintErrorsVersion2To0 ( errors ) {
611+ /** @type {Object.<string, number[]> } */
594612 const dictionary = { } ;
595613 for ( const error of errors ) {
596614 const ruleName = error . ruleNames [ 0 ] ;
@@ -606,10 +624,11 @@ function convertLintErrorsVersion2To0(errors) {
606624 * Copies and transforms lint results from resultVersion 3 to ?.
607625 *
608626 * @param {LintResults } results Lint results (v3).
609- * @param {(LintErrors) => LintErrors } transform Lint errors (v?).
627+ * @param {(errors: LintErrors) => LintErrors } transform Lint errors (v?).
610628 * @returns {LintResults } Lint results (v?).
611629 */
612630function copyAndTransformResults ( results , transform ) {
631+ /** @type {Object.<string, LintErrors> } */
613632 const newResults = { } ;
614633 Object . defineProperty ( newResults , "toString" , { "value" : results . toString } ) ;
615634 for ( const key of Object . keys ( results ) ) {
0 commit comments