diff --git a/tools/node_modules/eslint-plugin-markdown/lib/processor.js b/tools/node_modules/eslint-plugin-markdown/lib/processor.js index 41f6f7a280e61f..94cf816dc913d9 100644 --- a/tools/node_modules/eslint-plugin-markdown/lib/processor.js +++ b/tools/node_modules/eslint-plugin-markdown/lib/processor.js @@ -3,6 +3,25 @@ * @author Brandon Mills */ +/** + * @typedef {import('eslint/lib/shared/types').LintMessage} Message + * + * @typedef {Object} ASTNode + * @property {string} type + * @property {string} [lang] + * + * @typedef {Object} RangeMap + * @property {number} js + * @property {number} md + * + * @typedef {Object} BlockBase + * @property {string} baseIndentText + * @property {string[]} comments + * @property {RangeMap[]} rangeMap + * + * @typedef {ASTNode & BlockBase} Block + */ + "use strict"; const unified = require("unified"); @@ -16,31 +35,36 @@ const SUPPORTS_AUTOFIX = true; const markdown = unified().use(remarkParse); -let blocks = []; +/** + * @type {Map} + */ +const blocksCache = new Map(); /** * Performs a depth-first traversal of the Markdown AST. * @param {ASTNode} node A Markdown AST node. - * @param {Object} callbacks A map of node types to callbacks. - * @param {Object} [parent] The node's parent AST node. + * @param {{[key: string]: (node: ASTNode) => void}} callbacks A map of node types to callbacks. * @returns {void} */ -function traverse(node, callbacks, parent) { +function traverse(node, callbacks) { if (callbacks[node.type]) { - callbacks[node.type](node, parent); + callbacks[node.type](node); + } else { + callbacks["*"](); } if (typeof node.children !== "undefined") { for (let i = 0; i < node.children.length; i++) { - traverse(node.children[i], callbacks, node); + traverse(node.children[i], callbacks); } } } /** - * Converts leading HTML comments to JS block comments. + * Extracts `eslint-*` or `global` comments from HTML comments if present. * @param {string} html The text content of an HTML AST node. - * @returns {string[]} An array of JS block comments. + * @returns {string} The comment's text without the opening and closing tags or + * an empty string if the text is not an ESLint HTML comment. */ function getComment(html) { const commentStart = "