Refactor various code to do shallow/constrained search instead of deep search for better performance, make cache key for filterByTypesCached unique.

This commit is contained in:
David Anson 2024-10-09 22:42:36 -07:00
parent 2fa7730a6b
commit d22c1f19ef
12 changed files with 171 additions and 220 deletions

View file

@ -3,7 +3,7 @@
"use strict";
const { addError, getHtmlAttributeRe, nextLinesRe } = require("../helpers");
const { filterByTypes, getHtmlTagInfo } = require("../helpers/micromark-helpers.cjs");
const { getHtmlTagInfo, getDescendantsByType } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const altRe = getHtmlAttributeRe("alt");
@ -19,7 +19,7 @@ module.exports = {
// Process Markdown images
const images = filterByTypesCached([ "image" ]);
for (const image of images) {
const labelTexts = filterByTypes(image.children, [ "labelText" ]);
const labelTexts = getDescendantsByType(image, [ "label", "labelText" ]);
if (labelTexts.some((labelText) => labelText.text.length === 0)) {
const range = (image.startLine === image.endLine) ?
[ image.startColumn, image.endColumn - image.startColumn ] :