chore: Minor cleanups

This commit is contained in:
Sidharth Vinod
2023-08-08 00:31:17 +05:30
parent 4471001ef2
commit 776b219c03
2 changed files with 4 additions and 9 deletions

View File

@@ -6,9 +6,7 @@ import { extractFrontMatter } from './diagram-api/frontmatter.js';
import { UnknownDiagramError } from './errors.js'; import { UnknownDiagramError } from './errors.js';
import { cleanupComments } from './diagram-api/comments.js'; import { cleanupComments } from './diagram-api/comments.js';
import type { DetailedError } from './utils.js'; import type { DetailedError } from './utils.js';
import type { MermaidConfig } from './config.type.js';
import type { DiagramDefinition } from './diagram-api/types.js'; import type { DiagramDefinition } from './diagram-api/types.js';
import { D } from 'vitest/dist/types-198fd1d9.js';
export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void; export type ParseErrorFunction = (err: string | DetailedError | unknown, hash?: any) => void;
@@ -62,10 +60,7 @@ export class Diagram {
throw this.detectError; throw this.detectError;
} }
this.db.clear?.(); this.db.clear?.();
if (this.init) { this.init?.(configApi.getConfig());
const config = configApi.getConfig();
this.init(config);
}
this.parser.parse(this.text); this.parser.parse(this.text);
} }

View File

@@ -69,11 +69,11 @@ export const getDiagram = (name: string): DiagramDefinition => {
if (name in diagrams) { if (name in diagrams) {
return diagrams[name]; return diagrams[name];
} }
throw new Error(`Diagram ${name} not found.`); throw new DiagramNotFoundError(name);
}; };
export class DiagramNotFoundError extends Error { export class DiagramNotFoundError extends Error {
constructor(message: string) { constructor(name: string) {
super(`Diagram ${message} not found.`); super(`Diagram ${name} not found.`);
} }
} }