mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-01 11:24:16 +01:00
fix: Support multiple stereotypes on class diagrams (#6680)
- Modified JISON grammar to support consecutive annotations like <<interface>><<injected>> - Updated addAnnotation method to create classes if they don't exist - Added comprehensive tests for multiple annotation scenarios - Maintains backward compatibility with existing single annotation syntax Fixes #6680
This commit is contained in:
@@ -237,6 +237,7 @@ export class ClassDB implements DiagramDB {
|
||||
* @public
|
||||
*/
|
||||
public addAnnotation(className: string, annotation: string) {
|
||||
this.addClass(className);
|
||||
const validatedClassName = this.splitClassNameAndType(className).className;
|
||||
this.classes.get(validatedClassName)!.annotations.push(annotation);
|
||||
}
|
||||
|
||||
@@ -922,6 +922,28 @@ foo()
|
||||
expect(actual.methods.length).toBe(1);
|
||||
expect(actual.annotations[0]).toBe('interface');
|
||||
});
|
||||
|
||||
it('should handle multiple consecutive annotations on a single class', function () {
|
||||
const str = 'classDiagram\n' + '<<interface>><<injected>> Class1';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const actual = parser.yy.getClass('Class1');
|
||||
expect(actual.annotations.length).toBe(2);
|
||||
expect(actual.annotations).toContain('interface');
|
||||
expect(actual.annotations).toContain('injected');
|
||||
});
|
||||
|
||||
it('should handle multiple separate annotations on a single class', function () {
|
||||
const str = 'classDiagram\n' + '<<interface>> Class1\n' + '<<injected>> Class1';
|
||||
|
||||
parser.parse(str);
|
||||
|
||||
const actual = parser.yy.getClass('Class1');
|
||||
expect(actual.annotations.length).toBe(2);
|
||||
expect(actual.annotations).toContain('interface');
|
||||
expect(actual.annotations).toContain('injected');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -310,7 +310,12 @@ emptyBody
|
||||
;
|
||||
|
||||
annotationStatement
|
||||
: ANNOTATION_START alphaNumToken ANNOTATION_END className { yy.addAnnotation($4,$2); }
|
||||
: annotationList className { for(const annotation of $1) { yy.addAnnotation($2, annotation); } }
|
||||
;
|
||||
|
||||
annotationList
|
||||
: ANNOTATION_START alphaNumToken ANNOTATION_END { $$ = [$2]; }
|
||||
| annotationList ANNOTATION_START alphaNumToken ANNOTATION_END { $1.push($3); $$ = $1; }
|
||||
;
|
||||
|
||||
members
|
||||
|
||||
Reference in New Issue
Block a user