diff --git a/packages/mermaid/src/diagrams/class/classDb.ts b/packages/mermaid/src/diagrams/class/classDb.ts index c77bacc55..71afa5993 100644 --- a/packages/mermaid/src/diagrams/class/classDb.ts +++ b/packages/mermaid/src/diagrams/class/classDb.ts @@ -15,6 +15,7 @@ import { setDiagramTitle, getDiagramTitle, } from '../../commonDb.js'; +import { ClassMember } from './classTypes.js'; import type { ClassRelation, ClassNode, @@ -22,7 +23,6 @@ import type { ClassMap, NamespaceMap, NamespaceNode, - ClassMember, } from './classTypes.js'; const MERMAID_DOM_ID_PREFIX = 'classId-'; diff --git a/packages/mermaid/src/diagrams/common/common.ts b/packages/mermaid/src/diagrams/common/common.ts index 3814c8b58..bb9c6b649 100644 --- a/packages/mermaid/src/diagrams/common/common.ts +++ b/packages/mermaid/src/diagrams/common/common.ts @@ -181,46 +181,31 @@ export const getMin = function (...values: number[]): number { export const parseGenericTypes = function (input: string): string { const inputSets = input.split(/(,)/); const output = []; - let finalResult = ''; - let skipNextSet = false; for (let i = 0; i < inputSets.length; i++) { - const previousIndex = i - 1; - const nextIndex = i + 1; let thisSet = inputSets[i]; - // based on logic below - if we have already combined this set with the previous, we want to skip it - if (skipNextSet) { - continue; - } - // if the original input included a value such as "~K, V~"", these will be split into // an array of ["~K",","," V~"]. // This means that on each call of processSet, there will only be 1 ~ present // To account for this, if we encounter a ",", we are checking the previous and next sets in the array // to see if they contain matching ~'s // in which case we are assuming that they should be rejoined and sent to be processed - // we are also removing - if (thisSet === ',' && previousIndex > -1 && nextIndex <= inputSets.length) { + if (thisSet === ',' && i > 0 && i + 1 < inputSets.length) { const previousSet = inputSets[i - 1]; const nextSet = inputSets[i + 1]; + if (shouldCombineSets(previousSet, nextSet)) { thisSet = previousSet + ',' + nextSet; - skipNextSet = true; - // remove previous set + i++; // Move the index forward to skip the next iteration since we're combining sets output.pop(); } - } else { - skipNextSet = false; } output.push(processSet(thisSet)); } - finalResult = output.join(''); - // one last scan to see if any sets were missed - finalResult = processSet(finalResult); - return finalResult; + return output.join(''); }; const shouldCombineSets = (previousSet: string, nextSet: string): boolean => { @@ -234,7 +219,6 @@ const processSet = (input: string): string => { const chars = [...input]; const tildeCount = chars.reduce((count, char) => (char === '~' ? count + 1 : count), 0); - // ignoring any if (tildeCount <= 1) { return input; }