From 4c311ea4b1a34db0a3d15eaa52e04242c7ba70b6 Mon Sep 17 00:00:00 2001 From: Sidharth Vinod Date: Wed, 19 Oct 2022 19:03:29 +0530 Subject: [PATCH] fix: TS errors --- packages/mermaid/src/mermaid.ts | 41 ++++++++++++++++++--------------- packages/mermaid/src/utils.ts | 2 ++ 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/mermaid/src/mermaid.ts b/packages/mermaid/src/mermaid.ts index b7eaf8c36..58aaa9025 100644 --- a/packages/mermaid/src/mermaid.ts +++ b/packages/mermaid/src/mermaid.ts @@ -7,7 +7,7 @@ import { log } from './logger'; import utils from './utils'; import { mermaidAPI } from './mermaidAPI'; import { addDetector } from './diagram-api/detectType'; -import { isDetailedError } from './utils'; +import { isDetailedError, DetailedError } from './utils'; import { registerDiagram } from './diagram-api/diagramAPI'; /** @@ -103,7 +103,7 @@ const initThrowsErrors = function ( const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed); let txt: string; - const errors = []; + const errors: DetailedError[] = []; // element is the current div with mermaid class for (const element of Array.from(nodesToProcess)) { @@ -144,8 +144,12 @@ const initThrowsErrors = function ( ); } catch (error) { log.warn('Catching Error (bootstrap)', error); - // @ts-ignore: TODO Fix ts errors - const mermaidError = { error, str: error.str, hash: error.hash, message: error.str }; + const mermaidError: DetailedError = { + error, + str: error.str, + hash: error.hash, + message: error.str, + }; if (typeof mermaid.parseError === 'function') { mermaid.parseError(mermaidError); } @@ -240,7 +244,7 @@ const initThrowsErrorsAsync = async function ( const idGenerator = new utils.initIdGenerator(conf.deterministicIds, conf.deterministicIDSeed); let txt: string; - const errors = []; + const errors: DetailedError[] = []; // element is the current div with mermaid class for (const element of Array.from(nodesToProcess)) { @@ -281,8 +285,12 @@ const initThrowsErrorsAsync = async function ( ); } catch (error) { log.warn('Catching Error (bootstrap)', error); - // @ts-ignore: TODO Fix ts errors - const mermaidError = { error, str: error.str, hash: error.hash, message: error.str }; + const mermaidError: DetailedError = { + error, + str: error.str, + hash: error.hash, + message: error.str, + }; if (typeof mermaid.parseError === 'function') { mermaid.parseError(mermaidError); } @@ -355,22 +363,21 @@ const parse = (txt: string) => { return mermaidAPI.parse(txt, mermaid.parseError); }; -// @ts-ignore: TODO Fix ts errors -const executionQueue = []; +const executionQueue: (() => Promise)[] = []; let executionQueueRunning = false; const executeQueue = async () => { if (executionQueueRunning) { return; } executionQueueRunning = true; - // @ts-ignore: TODO Fix ts errors while (executionQueue.length > 0) { - // @ts-ignore: TODO Fix ts errors const f = executionQueue.shift(); - try { - await f(); - } catch (e) { - log.error('Error executing queue', e); + if (f) { + try { + await f(); + } catch (e) { + log.error('Error executing queue', e); + } } } executionQueueRunning = false; @@ -497,10 +504,8 @@ const mermaid: { mermaidAPI, parse, parseAsync, - // parseAsync: mermaidAPI.parseAsync, render: mermaidAPI.render, renderAsync, - // renderAsync: mermaidAPI.renderAsync, init, initThrowsErrors, initialize, @@ -508,8 +513,6 @@ const mermaid: { parseError: undefined, contentLoaded, setParseErrorHandler, - // test1, - // executeQueue, }; export default mermaid; diff --git a/packages/mermaid/src/utils.ts b/packages/mermaid/src/utils.ts index 395e6fe2a..e9d790df3 100644 --- a/packages/mermaid/src/utils.ts +++ b/packages/mermaid/src/utils.ts @@ -825,6 +825,8 @@ export const sanitizeCss = (str) => { export interface DetailedError { str: string; hash: any; + error?: Error; + message?: string; } /** @param error */