Skip to content

Commit 3e32332

Browse files
committedJan 14, 2025·
Added changeset.
1 parent fcb1de9 commit 3e32332

File tree

3 files changed

+24
-19
lines changed

3 files changed

+24
-19
lines changed
 

‎.changeset/witty-crews-smell.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'mermaid': patch
3+
---
4+
5+
`mermaidAPI.getDiagramFromText()` now returns a new different db for each state diagram

‎packages/mermaid/src/diagrams/state/stateDb.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,15 @@ export class StateDb {
3030
#START_TYPE = 'start';
3131
#END_NODE = this.#START_NODE;
3232
#END_TYPE = 'end';
33-
3433
#COLOR_KEYWORD = 'color';
3534
#FILL_KEYWORD = 'fill';
3635
#BG_FILL = 'bgFill';
3736
#STYLECLASS_SEP = ',';
3837

38+
constructor() {
39+
this.clear();
40+
}
41+
3942
/**
4043
* Returns a new list of classes.
4144
* In the future, this can be replaced with a class common to all diagrams.
@@ -54,10 +57,6 @@ export class StateDb {
5457
#rootDoc = [];
5558
#classes = this.#newClassesList(); // style classes defined by a classDef
5659

57-
constructor() {
58-
this.clear();
59-
}
60-
6160
// --------------------------------------
6261

6362
#newDoc = () => {

‎packages/mermaid/src/mermaidAPI.spec.ts

+15-14
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,28 @@ graph TD;A--x|text including URL space|B;`)
838838
it('should not modify db when rendering different diagrams', async () => {
839839
const classDiagram1 = await mermaidAPI.getDiagramFromText(
840840
`stateDiagram
841-
direction LR
842-
[*] --> Still
843-
Still --> [*]
844-
Still --> Moving
845-
Moving --> Still
846-
Moving --> Crash
847-
Crash --> [*]`
841+
direction LR
842+
[*] --> Still
843+
Still --> [*]
844+
Still --> Moving
845+
Moving --> Still
846+
Moving --> Crash
847+
Crash --> [*]`
848848
);
849849
const classDiagram2 = await mermaidAPI.getDiagramFromText(
850850
`stateDiagram
851-
[*] --> Still
852-
Still --> [*]
853-
Still --> Moving
854-
Moving --> Still
855-
Moving --> Crash
856-
Crash --> [*]`
851+
direction TB
852+
[*] --> Still
853+
Still --> [*]
854+
Still --> Moving
855+
Moving --> Still
856+
Moving --> Crash
857+
Crash --> [*]`
857858
);
858859
expect(classDiagram1.db).not.toBe(classDiagram2.db);
859860
assert(classDiagram1.db instanceof StateDb);
860861
assert(classDiagram2.db instanceof StateDb);
861-
expect(classDiagram2.db.getDirection()).not.toEqual(classDiagram2.db.getDirection());
862+
expect(classDiagram1.db.getDirection()).not.toEqual(classDiagram2.db.getDirection());
862863
});
863864
});
864865

0 commit comments

Comments
 (0)
Please sign in to comment.