Refactor to remove micromark helper getSiblingTokens for simpler code and better performance.

This commit is contained in:
David Anson 2024-02-26 21:07:24 -08:00
parent 4436d84b55
commit 996d88a9b4
4 changed files with 88 additions and 140 deletions

View file

@ -295,28 +295,6 @@ function filterByTypes(tokens, types) {
return filterByPredicate(tokens, predicate);
}
/**
* Gets all sibling token groups for a list of Micromark tokens.
*
* @param {Token[]} tokens Micromark tokens.
* @returns {Token[][]} Sibling token groups.
*/
function getSiblingTokens(tokens) {
const result = [];
const queue = [ tokens ];
// eslint-disable-next-line init-declarations
let current;
while ((current = queue.shift())) {
result.push(current);
for (const token of current) {
if (token.children.length > 0) {
queue.push(token.children);
}
}
}
return result;
}
/**
* Gets the heading level of a Micromark heading tokan.
*
@ -441,7 +419,6 @@ module.exports = {
getHeadingLevel,
getHtmlTagInfo,
getMicromarkEvents,
getSiblingTokens,
getTokenParentOfType,
getTokenTextByType,
inHtmlFlow,