diff --git a/packages/mermaid/src/diagrams/class/classDb.ts b/packages/mermaid/src/diagrams/class/classDb.ts index 312dda7a6..d61573ded 100644 --- a/packages/mermaid/src/diagrams/class/classDb.ts +++ b/packages/mermaid/src/diagrams/class/classDb.ts @@ -446,11 +446,13 @@ const getNamespaces = function (): NamespaceMap { * @public */ export const addClassesToNamespace = function (id: string, classNames: string[]) { - if (namespaces[id] !== undefined) { - classNames.map((className) => { - classes[className].parent = id; - namespaces[id].classes[className] = classes[className]; - }); + if (namespaces[id] === undefined) { + return; + } + for (const name of classNames) { + const { className } = splitClassNameAndType(name); + classes[className].parent = id; + namespaces[id].classes[className] = classes[className]; } }; diff --git a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts index 532c8aaa7..fb719658e 100644 --- a/packages/mermaid/src/diagrams/class/classDiagram.spec.ts +++ b/packages/mermaid/src/diagrams/class/classDiagram.spec.ts @@ -1043,6 +1043,19 @@ foo() `; parser.parse(str); }); + + it('should handle namespace with generic types', () => { + parser.parse(`classDiagram + +namespace space { + class Square~Shape~{ + int id + List~int~ position + setPoints(List~int~ points) + getPoints() List~int~ + } +}`); + }); }); });