From 980a5ac8b54a0cb158bd980d1c8c88ee43de4f8e Mon Sep 17 00:00:00 2001 From: Reda Al Sulais Date: Thu, 10 Aug 2023 22:26:04 +0300 Subject: [PATCH] create `ParserDefinition` type --- packages/mermaid/src/diagram-api/diagramAPI.spec.ts | 7 ++++++- packages/mermaid/src/diagram-api/types.ts | 9 +++++++-- packages/mermaid/src/mermaid.spec.ts | 10 +++++++--- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/mermaid/src/diagram-api/diagramAPI.spec.ts b/packages/mermaid/src/diagram-api/diagramAPI.spec.ts index 49bde1a66..b437745cf 100644 --- a/packages/mermaid/src/diagram-api/diagramAPI.spec.ts +++ b/packages/mermaid/src/diagram-api/diagramAPI.spec.ts @@ -35,7 +35,12 @@ describe('DiagramAPI', () => { 'loki', { db: {}, - parser: {}, + parser: { + parse: (_text) => { + return; + }, + parser: { yy: {} }, + }, renderer: {}, styles: {}, }, diff --git a/packages/mermaid/src/diagram-api/types.ts b/packages/mermaid/src/diagram-api/types.ts index 860e965ac..100b92e87 100644 --- a/packages/mermaid/src/diagram-api/types.ts +++ b/packages/mermaid/src/diagram-api/types.ts @@ -1,5 +1,5 @@ import { Diagram } from '../Diagram.js'; -import { MermaidConfig } from '../config.type.js'; +import type { MermaidConfig } from '../config.type.js'; import type * as d3 from 'd3'; export interface InjectUtils { @@ -27,7 +27,7 @@ export interface DiagramDB { export interface DiagramDefinition { db: DiagramDB; renderer: any; - parser: any; + parser: ParserDefinition; styles?: any; init?: (config: MermaidConfig) => void; injectUtils?: ( @@ -70,6 +70,11 @@ export type DrawDefinition = ( diagramObject: Diagram ) => void; +export interface ParserDefinition { + parse: (text: string) => void; + parser: { yy: DiagramDB }; +} + /** * Type for function parse directive from diagram code. * diff --git a/packages/mermaid/src/mermaid.spec.ts b/packages/mermaid/src/mermaid.spec.ts index e27428545..0b4437d74 100644 --- a/packages/mermaid/src/mermaid.spec.ts +++ b/packages/mermaid/src/mermaid.spec.ts @@ -3,6 +3,7 @@ import { mermaidAPI } from './mermaidAPI.js'; import './diagram-api/diagram-orchestration.js'; import { addDiagrams } from './diagram-api/diagram-orchestration.js'; import { beforeAll, describe, it, expect, vi } from 'vitest'; +import type { DiagramDefinition } from './diagram-api/types.js'; beforeAll(async () => { addDiagrams(); @@ -92,13 +93,16 @@ describe('when using mermaid and ', () => { it('should defer diagram load based on parameter', async () => { let loaded = false; - const dummyDiagram = { + const dummyDiagram: DiagramDefinition = { db: {}, renderer: () => { // do nothing }, - parser: () => { - // do nothing + parser: { + parse: (_text) => { + return; + }, + parser: { yy: {} }, }, styles: () => { // do nothing