Address new TypeScript warnings in core files, improve type definitions.
Some checks are pending
Checkers / linkcheck (push) Waiting to run
Checkers / spellcheck (push) Waiting to run
CI / build (20, macos-latest) (push) Waiting to run
CI / build (20, ubuntu-latest) (push) Waiting to run
CI / build (20, windows-latest) (push) Waiting to run
CI / build (22, macos-latest) (push) Waiting to run
CI / build (22, ubuntu-latest) (push) Waiting to run
CI / build (22, windows-latest) (push) Waiting to run
CI / build (24, macos-latest) (push) Waiting to run
CI / build (24, ubuntu-latest) (push) Waiting to run
CI / build (24, windows-latest) (push) Waiting to run
CI / pnpm (push) Waiting to run
CodeQL / Analyze (push) Waiting to run
TestRepos / build (latest, ubuntu-latest) (push) Waiting to run
UpdateTestRepos / update (push) Waiting to run

This commit is contained in:
David Anson 2025-10-11 16:36:47 -07:00
parent bd02390014
commit 7beb9fc9d0
32 changed files with 354 additions and 170 deletions

View file

@ -17,6 +17,7 @@ const { flatTokensSymbol, htmlFlowSymbol, newLineRe } = require("./shared.cjs");
* @returns {boolean} True iff the token is within an htmlFlow type.
*/
function inHtmlFlow(token) {
// @ts-ignore
return Boolean(token[htmlFlowSymbol]);
}
@ -126,8 +127,11 @@ function filterByPredicate(tokens, allowed, transformChildren) {
* @returns {Token[]} Filtered tokens.
*/
function filterByTypes(tokens, types, htmlFlow) {
const predicate = (token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
const flatTokens = tokens[flatTokensSymbol];
const predicate = (/** @type {Token} */ token) => types.includes(token.type) && (htmlFlow || !inHtmlFlow(token));
/** @type {Token[]} */
const flatTokens =
// @ts-ignore
tokens[flatTokensSymbol];
if (flatTokens) {
return flatTokens.filter(predicate);
}
@ -163,7 +167,7 @@ function getBlockQuotePrefixText(tokens, lineNumber, count = 1) {
function getDescendantsByType(parent, typePath) {
let tokens = Array.isArray(parent) ? parent : [ parent ];
for (const type of typePath) {
const predicate = (token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
const predicate = (/** @type {Token} */ token) => Array.isArray(type) ? type.includes(token.type) : (type === token.type);
tokens = tokens.flatMap((t) => t.children.filter(predicate));
}
return tokens;