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,6 @@
"use strict";
const { addErrorContext } = require("../helpers");
const { filterByTypes } = require("../helpers/micromark-helpers.cjs");
const { filterByTypesCached } = require("./cache");
const dollarCommandRe = /^(\s*)(\$\s+)/;
@ -17,10 +16,7 @@ module.exports = {
"parser": "micromark",
"function": function MD014(params, onError) {
for (const codeBlock of filterByTypesCached([ "codeFenced", "codeIndented" ])) {
const codeFlowValues = filterByTypes(
codeBlock.children,
[ "codeFlowValue" ]
);
const codeFlowValues = codeBlock.children.filter((child) => child.type === "codeFlowValue");
const dollarMatches = codeFlowValues
.map((codeFlowValue) => ({
"result": codeFlowValue.text.match(dollarCommandRe),