state-machine-cat 12.0.5 → 12.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/dist/cli/actions.mjs +34 -31
  2. package/dist/cli/attributes-parser.mjs +914 -976
  3. package/dist/cli/execute-command-line.mjs +98 -48
  4. package/dist/cli/file-name-to-stream.mjs +8 -8
  5. package/dist/cli/normalize.mjs +89 -70
  6. package/dist/cli/validations.mjs +72 -52
  7. package/dist/index-node.mjs +12 -9
  8. package/dist/index.mjs +10 -7
  9. package/dist/options.mjs +53 -53
  10. package/dist/parse/index.mjs +17 -17
  11. package/dist/parse/parser-helpers.mjs +159 -139
  12. package/dist/parse/scxml/index.mjs +152 -129
  13. package/dist/parse/scxml/normalize-machine.mjs +36 -35
  14. package/dist/parse/scxml/utl.mjs +1 -1
  15. package/dist/parse/smcat/smcat-parser.mjs +2794 -2897
  16. package/dist/parse/smcat-ast.schema.mjs +185 -168
  17. package/dist/render/dot/attributebuilder.mjs +40 -37
  18. package/dist/render/dot/counter.mjs +14 -14
  19. package/dist/render/dot/dot.states.template.js +1 -26
  20. package/dist/render/dot/dot.template.js +1 -14
  21. package/dist/render/dot/index.mjs +129 -82
  22. package/dist/render/dot/render-dot-from-ast.mjs +33 -16
  23. package/dist/render/dot/state-transformers.mjs +96 -85
  24. package/dist/render/dot/transition-transformers.mjs +39 -41
  25. package/dist/render/dot/utl.mjs +21 -19
  26. package/dist/render/index-node.mjs +16 -16
  27. package/dist/render/index.mjs +9 -9
  28. package/dist/render/scjson/index.mjs +111 -94
  29. package/dist/render/scjson/make-valid-event-names.mjs +21 -18
  30. package/dist/render/scjson/make-valid-xml-name.mjs +17 -13
  31. package/dist/render/scxml/index.mjs +2 -1
  32. package/dist/render/scxml/render-from-scjson.mjs +5 -2
  33. package/dist/render/scxml/scxml.states.template.js +1 -14
  34. package/dist/render/scxml/scxml.template.js +1 -6
  35. package/dist/render/smcat/index.mjs +54 -39
  36. package/dist/render/smcat/smcat.template.js +1 -13
  37. package/dist/render/vector/dot-to-vector-native.mjs +30 -26
  38. package/dist/render/vector/vector-native-dot-with-fallback.mjs +27 -20
  39. package/dist/render/vector/vector-with-wasm.mjs +13 -6
  40. package/dist/state-machine-model.mjs +67 -52
  41. package/dist/transform/desugar.mjs +115 -66
  42. package/dist/transform/utl.mjs +12 -12
  43. package/dist/version.mjs +1 -1
  44. package/package.json +74 -74
  45. package/types/state-machine-cat.d.mts +209 -209
  46. package/types/state-machine-cat.d.ts +0 -296
@@ -1,112 +1,123 @@
1
1
  import utl from "./utl.mjs";
2
2
  function isType(pString) {
3
- return (pState) => pState.type === pString;
3
+ return (pState) => pState.type === pString;
4
4
  }
5
5
  function isOneOfTypes(pStringArray) {
6
- return (pState) => pStringArray.includes(pState.type);
6
+ return (pState) => pStringArray.includes(pState.type);
7
7
  }
8
8
  function setLabel(pState) {
9
- const lState = structuredClone(pState);
10
- lState.label = pState.label || pState.name;
11
- return lState;
9
+ const lState = structuredClone(pState);
10
+ lState.label = pState.label || pState.name;
11
+ return lState;
12
12
  }
13
13
  function nameNote(pState) {
14
- if (pState.note) {
15
- return {
16
- noteName: `note_${pState.name}`,
17
- ...pState,
18
- };
19
- }
20
- return pState;
14
+ if (pState.note) {
15
+ return {
16
+ noteName: `note_${pState.name}`,
17
+ ...pState,
18
+ };
19
+ }
20
+ return pState;
21
21
  }
22
22
  function classifyState(pState) {
23
- const lState = { ...pState };
24
- const lClasses = ["state", pState.type];
25
- if (pState.class) {
26
- lClasses.push(pState.class.trim().replace(/[ ]{2,}/g, " "));
27
- }
28
- lState.class = lClasses.join(" ");
29
- return lState;
23
+ const lState = { ...pState };
24
+ const lClasses = ["state", pState.type];
25
+ if (pState.class) {
26
+ lClasses.push(pState.class.trim().replace(/[ ]{2,}/g, " "));
27
+ }
28
+ lState.class = lClasses.join(" ");
29
+ return lState;
30
30
  }
31
31
  function formatActionType(pString) {
32
- return pString === "activity" ? "" : `${pString}/ `;
32
+ return pString === "activity" ? "" : `${pString}/ `;
33
33
  }
34
34
  function flattenActions(pState) {
35
- if (pState.actions) {
36
- return {
37
- ...pState,
38
- actionStrings: pState.actions.map((pAction) => `${formatActionType(pAction.type)}${pAction.body}`),
39
- };
40
- }
41
- return pState;
35
+ if (pState.actions) {
36
+ return {
37
+ ...pState,
38
+ actionStrings: pState.actions.map(
39
+ (pAction) => `${formatActionType(pAction.type)}${pAction.body}`,
40
+ ),
41
+ };
42
+ }
43
+ return pState;
42
44
  }
43
45
  function flattenNote(pState) {
44
- if (pState.note) {
45
- return {
46
- ...pState,
47
- noteFlattened: pState.note.join(""),
48
- };
49
- }
50
- return pState;
46
+ if (pState.note) {
47
+ return {
48
+ ...pState,
49
+ noteFlattened: pState.note.join(""),
50
+ };
51
+ }
52
+ return pState;
51
53
  }
52
54
  function recolor(pNodeAttributes) {
53
- return (pState) => {
54
- const lNodeColor = (pNodeAttributes || []).find((pAttribute) => pAttribute.name === "color")?.value;
55
- if (lNodeColor &&
56
- !pState.color &&
57
- isOneOfTypes([
58
- "initial",
59
- "fork",
60
- "join",
61
- "junction",
62
- "forkjoin",
63
- "final",
64
- ])(pState)) {
65
- pState.color = lNodeColor;
66
- }
67
- return pState;
68
- };
55
+ return (pState) => {
56
+ const lNodeColor = (pNodeAttributes || []).find(
57
+ (pAttribute) => pAttribute.name === "color",
58
+ )?.value;
59
+ if (
60
+ lNodeColor &&
61
+ !pState.color &&
62
+ isOneOfTypes([
63
+ "initial",
64
+ "fork",
65
+ "join",
66
+ "junction",
67
+ "forkjoin",
68
+ "final",
69
+ ])(pState)
70
+ ) {
71
+ pState.color = lNodeColor;
72
+ }
73
+ return pState;
74
+ };
69
75
  }
70
76
  function escapeStateStrings(pState) {
71
- if (pState.note) {
72
- return {
73
- ...pState,
74
- note: pState.note.map(utl.escapeString),
75
- };
76
- }
77
- return pState;
77
+ if (pState.note) {
78
+ return {
79
+ ...pState,
80
+ note: pState.note.map(utl.escapeString),
81
+ };
82
+ }
83
+ return pState;
78
84
  }
79
85
  function tipForkJoinStates(pDirection) {
80
- return (pState) => {
81
- if (isOneOfTypes(["fork", "join", "forkjoin"])(pState)) {
82
- return {
83
- sizingExtras: utl.isVertical(pDirection) ? "height=0.1" : "width=0.1",
84
- ...pState,
85
- };
86
- }
87
- return pState;
88
- };
86
+ return (pState) => {
87
+ if (isOneOfTypes(["fork", "join", "forkjoin"])(pState)) {
88
+ return {
89
+ sizingExtras: utl.isVertical(pDirection) ? "height=0.1" : "width=0.1",
90
+ ...pState,
91
+ };
92
+ }
93
+ return pState;
94
+ };
89
95
  }
90
96
  function flagParallelChildren(pState) {
91
- if (pState.type === "parallel" &&
92
- pState.statemachine &&
93
- pState.statemachine.states) {
94
- pState.statemachine.states = pState.statemachine.states.map((pChildState) => isType("regular")(pChildState)
95
- ? { ...pChildState, parentIsParallel: true }
96
- : pChildState);
97
- }
98
- return pState;
97
+ if (
98
+ pState.type === "parallel" &&
99
+ pState.statemachine &&
100
+ pState.statemachine.states
101
+ ) {
102
+ pState.statemachine.states = pState.statemachine.states.map(
103
+ (pChildState) =>
104
+ isType("regular")(pChildState)
105
+ ? { ...pChildState, parentIsParallel: true }
106
+ : pChildState,
107
+ );
108
+ }
109
+ return pState;
99
110
  }
100
111
  export default {
101
- isType,
102
- isOneOfTypes,
103
- setLabel,
104
- classifyState,
105
- nameNote,
106
- flattenActions,
107
- flattenNote,
108
- recolor,
109
- escapeStateStrings,
110
- tipForkJoinStates,
111
- flagParallelChildren,
112
+ isType,
113
+ isOneOfTypes,
114
+ setLabel,
115
+ classifyState,
116
+ nameNote,
117
+ flattenActions,
118
+ flattenNote,
119
+ recolor,
120
+ escapeStateStrings,
121
+ tipForkJoinStates,
122
+ flagParallelChildren,
112
123
  };
@@ -1,49 +1,47 @@
1
1
  import utl from "./utl.mjs";
2
2
  function escapeTransitionStrings(pTransition) {
3
- const lTransition = { ...pTransition };
4
- if (lTransition.note) {
5
- lTransition.note = lTransition.note.map(utl.escapeString);
6
- }
7
- if (lTransition.label) {
8
- lTransition.label = utl.escapeLabelString(lTransition.label);
9
- }
10
- return lTransition;
3
+ const lTransition = { ...pTransition };
4
+ if (lTransition.note) {
5
+ lTransition.note = lTransition.note.map(utl.escapeString);
6
+ }
7
+ if (lTransition.label) {
8
+ lTransition.label = utl.escapeLabelString(lTransition.label);
9
+ }
10
+ return lTransition;
11
11
  }
12
12
  function addPorts(pDirection) {
13
- return (pTransition) => {
14
- let lAdditionalAttributes = {};
15
- if (pTransition.isCompositeSelf) {
16
- if (utl.isVertical(pDirection)) {
17
- lAdditionalAttributes = {
18
- tailportflags: `tailport="e" headport="e"`,
19
- headportflags: `tailport="w"`,
20
- };
21
- }
22
- else if (pTransition.hasParent) {
23
- lAdditionalAttributes = {
24
- tailportflags: `tailport="n" headport="n"`,
25
- headportflags: `tailport="s"`,
26
- };
27
- }
28
- else {
29
- lAdditionalAttributes = {
30
- tailportflags: `tailport="s" headport="s"`,
31
- headportflags: `tailport="n"`,
32
- };
33
- }
34
- }
35
- return { ...pTransition, ...lAdditionalAttributes };
36
- };
13
+ return (pTransition) => {
14
+ let lAdditionalAttributes = {};
15
+ if (pTransition.isCompositeSelf) {
16
+ if (utl.isVertical(pDirection)) {
17
+ lAdditionalAttributes = {
18
+ tailportflags: `tailport="e" headport="e"`,
19
+ headportflags: `tailport="w"`,
20
+ };
21
+ } else if (pTransition.hasParent) {
22
+ lAdditionalAttributes = {
23
+ tailportflags: `tailport="n" headport="n"`,
24
+ headportflags: `tailport="s"`,
25
+ };
26
+ } else {
27
+ lAdditionalAttributes = {
28
+ tailportflags: `tailport="s" headport="s"`,
29
+ headportflags: `tailport="n"`,
30
+ };
31
+ }
32
+ }
33
+ return { ...pTransition, ...lAdditionalAttributes };
34
+ };
37
35
  }
38
36
  function classifyTransition(pTransition) {
39
- const lClasses = ["transition"];
40
- if (pTransition.type) {
41
- lClasses.push(pTransition.type);
42
- }
43
- if (pTransition.class) {
44
- lClasses.push(pTransition.class.trim().replace(/[ ]{2,}/g, " "));
45
- }
46
- pTransition.class = lClasses.join(" ");
47
- return pTransition;
37
+ const lClasses = ["transition"];
38
+ if (pTransition.type) {
39
+ lClasses.push(pTransition.type);
40
+ }
41
+ if (pTransition.class) {
42
+ lClasses.push(pTransition.class.trim().replace(/[ ]{2,}/g, " "));
43
+ }
44
+ pTransition.class = lClasses.join(" ");
45
+ return pTransition;
48
46
  }
49
47
  export default { escapeTransitionStrings, addPorts, classifyTransition };
@@ -1,29 +1,31 @@
1
1
  function escapeString(pString) {
2
- return pString
3
- .replace(/\\/g, "\\\\")
4
- .replace(/\n\s*/g, "\\l")
5
- .replace(/"/g, '\\"')
6
- .concat("\\l");
2
+ return pString
3
+ .replace(/\\/g, "\\\\")
4
+ .replace(/\n\s*/g, "\\l")
5
+ .replace(/"/g, '\\"')
6
+ .concat("\\l");
7
7
  }
8
8
  function escapeLabelString(pString) {
9
- return pString
10
- .replace(/\\/g, "\\\\")
11
- .replace(/\n\s*/g, " \\l")
12
- .replace(/"/g, '\\"')
13
- .concat(" \\l");
9
+ return pString
10
+ .replace(/\\/g, "\\\\")
11
+ .replace(/\n\s*/g, " \\l")
12
+ .replace(/"/g, '\\"')
13
+ .concat(" \\l");
14
14
  }
15
15
  function isVertical(pDirection) {
16
- const lDirection = pDirection || "top-down";
17
- return lDirection === "top-down" || lDirection === "bottom-top";
16
+ const lDirection = pDirection || "top-down";
17
+ return lDirection === "top-down" || lDirection === "bottom-top";
18
18
  }
19
19
  function isCompositeSelf(pStateMachineModel, pTransition) {
20
- return (pTransition.from === pTransition.to &&
21
- pStateMachineModel.findStateByName(pTransition.from).statemachine &&
22
- !(pTransition.type === "internal"));
20
+ return (
21
+ pTransition.from === pTransition.to &&
22
+ pStateMachineModel.findStateByName(pTransition.from).statemachine &&
23
+ !(pTransition.type === "internal")
24
+ );
23
25
  }
24
26
  export default {
25
- escapeString,
26
- escapeLabelString,
27
- isVertical,
28
- isCompositeSelf,
27
+ escapeString,
28
+ escapeLabelString,
29
+ isVertical,
30
+ isCompositeSelf,
29
31
  };
@@ -6,20 +6,20 @@ import scjson from "./scjson/index.mjs";
6
6
  import scxml from "./scxml/index.mjs";
7
7
  const smcat = smcatRendererAsImported;
8
8
  export default function getRenderFunction(pOutputType) {
9
- const lOutputType2RenderFunctionMap = new Map([
10
- ["smcat", smcat],
11
- ["dot", renderDot],
12
- ["svg", vector],
13
- ["eps", vector],
14
- ["ps", vector],
15
- ["ps2", vector],
16
- ["oldsvg", oldVector],
17
- ["oldps2", oldVector],
18
- ["oldeps", oldVector],
19
- ["pdf", vector],
20
- ["png", vector],
21
- ["scjson", scjson],
22
- ["scxml", scxml],
23
- ]);
24
- return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
9
+ const lOutputType2RenderFunctionMap = new Map([
10
+ ["smcat", smcat],
11
+ ["dot", renderDot],
12
+ ["svg", vector],
13
+ ["eps", vector],
14
+ ["ps", vector],
15
+ ["ps2", vector],
16
+ ["oldsvg", oldVector],
17
+ ["oldps2", oldVector],
18
+ ["oldeps", oldVector],
19
+ ["pdf", vector],
20
+ ["png", vector],
21
+ ["scjson", scjson],
22
+ ["scxml", scxml],
23
+ ]);
24
+ return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
25
25
  }
@@ -5,13 +5,13 @@ import scjson from "./scjson/index.mjs";
5
5
  import scxml from "./scxml/index.mjs";
6
6
  const smcat = smcatRendererAsImported;
7
7
  export default function getRenderFunction(pOutputType) {
8
- const lOutputType2RenderFunctionMap = new Map([
9
- ["smcat", smcat],
10
- ["dot", renderDot],
11
- ["svg", svg],
12
- ["oldsvg", svg],
13
- ["scjson", scjson],
14
- ["scxml", scxml],
15
- ]);
16
- return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
8
+ const lOutputType2RenderFunctionMap = new Map([
9
+ ["smcat", smcat],
10
+ ["dot", renderDot],
11
+ ["svg", svg],
12
+ ["oldsvg", svg],
13
+ ["scjson", scjson],
14
+ ["scxml", scxml],
15
+ ]);
16
+ return lOutputType2RenderFunctionMap.get(pOutputType) ?? ((pX) => pX);
17
17
  }
@@ -2,120 +2,137 @@ import StateMachineModel from "../../state-machine-model.mjs";
2
2
  import makeValidXMLName from "./make-valid-xml-name.mjs";
3
3
  import makeValidEventNames from "./make-valid-event-names.mjs";
4
4
  const STATE_TYPE2SCXML_STATE_KIND = {
5
- regular: "state",
6
- initial: "initial",
7
- final: "final",
8
- terminate: "final",
9
- parallel: "parallel",
10
- history: "history",
11
- deephistory: "history",
5
+ regular: "state",
6
+ initial: "initial",
7
+ final: "final",
8
+ terminate: "final",
9
+ parallel: "parallel",
10
+ history: "history",
11
+ deephistory: "history",
12
12
  };
13
13
  function stateType2SCXMLStateKind(pStateType) {
14
- return STATE_TYPE2SCXML_STATE_KIND[pStateType] || "state";
14
+ return STATE_TYPE2SCXML_STATE_KIND[pStateType] || "state";
15
15
  }
16
16
  function transformTransition(pTransition) {
17
- const lReturnValue = {
18
- target: makeValidXMLName(pTransition.to),
19
- };
20
- if (pTransition.event) {
21
- lReturnValue.event = makeValidEventNames(pTransition.event);
22
- }
23
- if (pTransition.cond) {
24
- lReturnValue.cond = pTransition.cond;
25
- }
26
- if (pTransition.action) {
27
- lReturnValue.action = pTransition.action;
28
- }
29
- if (pTransition.type) {
30
- lReturnValue.type = pTransition.type;
31
- }
32
- return lReturnValue;
17
+ const lReturnValue = {
18
+ target: makeValidXMLName(pTransition.to),
19
+ };
20
+ if (pTransition.event) {
21
+ lReturnValue.event = makeValidEventNames(pTransition.event);
22
+ }
23
+ if (pTransition.cond) {
24
+ lReturnValue.cond = pTransition.cond;
25
+ }
26
+ if (pTransition.action) {
27
+ lReturnValue.action = pTransition.action;
28
+ }
29
+ if (pTransition.type) {
30
+ lReturnValue.type = pTransition.type;
31
+ }
32
+ return lReturnValue;
33
33
  }
34
34
  function extractTriggers(pTriggers, pTriggerType) {
35
- return pTriggers
36
- .filter((pTrigger) => pTrigger.type === pTriggerType)
37
- .map((pTrigger) => pTrigger.body);
35
+ return pTriggers
36
+ .filter((pTrigger) => pTrigger.type === pTriggerType)
37
+ .map((pTrigger) => pTrigger.body);
38
38
  }
39
39
  function pullOutActionType(pReturnValue, pTriggersType, pActions, pActionType) {
40
- const lTriggerArray = extractTriggers(pActions, pActionType);
41
- if (lTriggerArray.length > 0) {
42
- pReturnValue[pTriggersType] = (pReturnValue[pTriggersType] || []).concat(lTriggerArray);
43
- }
40
+ const lTriggerArray = extractTriggers(pActions, pActionType);
41
+ if (lTriggerArray.length > 0) {
42
+ pReturnValue[pTriggersType] = (pReturnValue[pTriggersType] || []).concat(
43
+ lTriggerArray,
44
+ );
45
+ }
44
46
  }
45
47
  function transformTriggers(pReturnValue, pState) {
46
- if (pState.actions) {
47
- pullOutActionType(pReturnValue, "onentries", pState.actions, "entry");
48
- pullOutActionType(pReturnValue, "onentries", pState.actions, "activity");
49
- pullOutActionType(pReturnValue, "onexits", pState.actions, "exit");
50
- }
48
+ if (pState.actions) {
49
+ pullOutActionType(pReturnValue, "onentries", pState.actions, "entry");
50
+ pullOutActionType(pReturnValue, "onentries", pState.actions, "activity");
51
+ pullOutActionType(pReturnValue, "onexits", pState.actions, "exit");
52
+ }
51
53
  }
52
54
  function transformTransitions(pReturnValue, pState, pTransitions) {
53
- const lTransitions = pTransitions
54
- .filter((pTransition) => pTransition.from === pState.name)
55
- .map(transformTransition);
56
- if (lTransitions.length > 0) {
57
- pReturnValue.transitions = lTransitions;
58
- }
55
+ const lTransitions = pTransitions
56
+ .filter((pTransition) => pTransition.from === pState.name)
57
+ .map(transformTransition);
58
+ if (lTransitions.length > 0) {
59
+ pReturnValue.transitions = lTransitions;
60
+ }
59
61
  }
60
62
  function transformCompositeState(pReturnValue, pState, pTransitions) {
61
- if (pState.statemachine) {
62
- const lRenderedState = render(pState.statemachine, undefined, pTransitions);
63
- pReturnValue.states = (pReturnValue.states || []).concat(lRenderedState.states);
64
- if (lRenderedState.initial) {
65
- pReturnValue.initial = lRenderedState.initial;
66
- }
67
- }
63
+ if (pState.statemachine) {
64
+ const lRenderedState = render(pState.statemachine, undefined, pTransitions);
65
+ pReturnValue.states = (pReturnValue.states || []).concat(
66
+ lRenderedState.states,
67
+ );
68
+ if (lRenderedState.initial) {
69
+ pReturnValue.initial = lRenderedState.initial;
70
+ }
71
+ }
68
72
  }
69
73
  function transformState(pTransitions) {
70
- pTransitions = pTransitions || [];
71
- return (pState) => {
72
- const lReturnValue = {
73
- kind: stateType2SCXMLStateKind(pState.type),
74
- id: makeValidXMLName(pState.name),
75
- };
76
- if (pState.type === "deephistory") {
77
- lReturnValue.type = "deep";
78
- }
79
- transformTriggers(lReturnValue, pState);
80
- transformTransitions(lReturnValue, pState, pTransitions);
81
- transformCompositeState(lReturnValue, pState, pTransitions);
82
- return lReturnValue;
83
- };
74
+ pTransitions = pTransitions || [];
75
+ return (pState) => {
76
+ const lReturnValue = {
77
+ kind: stateType2SCXMLStateKind(pState.type),
78
+ id: makeValidXMLName(pState.name),
79
+ };
80
+ if (pState.type === "deephistory") {
81
+ lReturnValue.type = "deep";
82
+ }
83
+ transformTriggers(lReturnValue, pState);
84
+ transformTransitions(lReturnValue, pState, pTransitions);
85
+ transformCompositeState(lReturnValue, pState, pTransitions);
86
+ return lReturnValue;
87
+ };
84
88
  }
85
89
  function findInitialPseudoStateName(pStateMachine) {
86
- const lInitial = pStateMachine.states.filter((pState) => pState.type === "initial");
87
- if (lInitial.length > 0) {
88
- return lInitial[0].name;
89
- }
90
- return undefined;
90
+ const lInitial = pStateMachine.states.filter(
91
+ (pState) => pState.type === "initial",
92
+ );
93
+ if (lInitial.length > 0) {
94
+ return lInitial[0].name;
95
+ }
96
+ return undefined;
91
97
  }
92
98
  function findInitialStateName(pStateMachine, pInitialPseudoStateName) {
93
- let lReturnValue = pInitialPseudoStateName;
94
- if (pInitialPseudoStateName && pStateMachine.transitions) {
95
- const lInitialTransitions = pStateMachine.transitions.filter((pTransition) => pTransition.from === pInitialPseudoStateName);
96
- if (lInitialTransitions.length > 0 && !lInitialTransitions[0].action) {
97
- lReturnValue = lInitialTransitions[0].to;
98
- }
99
- }
100
- return lReturnValue;
99
+ let lReturnValue = pInitialPseudoStateName;
100
+ if (pInitialPseudoStateName && pStateMachine.transitions) {
101
+ const lInitialTransitions = pStateMachine.transitions.filter(
102
+ (pTransition) => pTransition.from === pInitialPseudoStateName,
103
+ );
104
+ if (lInitialTransitions.length > 0 && !lInitialTransitions[0].action) {
105
+ lReturnValue = lInitialTransitions[0].to;
106
+ }
107
+ }
108
+ return lReturnValue;
101
109
  }
102
110
  export default function render(pStateMachine, _pOptions, pTransitions) {
103
- const lInitialPseudoStateName = findInitialPseudoStateName(pStateMachine);
104
- const lInitialStateName = findInitialStateName(pStateMachine, lInitialPseudoStateName);
105
- const lReturnValue = {
106
- states: pStateMachine.states
107
- .filter((pState) => {
108
- if (lInitialStateName &&
109
- lInitialStateName !== lInitialPseudoStateName) {
110
- return pState.type !== "initial";
111
- }
112
- return true;
113
- })
114
- .map(transformState(pTransitions ||
115
- new StateMachineModel(pStateMachine).flattenedTransitions)),
116
- };
117
- if (lInitialStateName) {
118
- lReturnValue.initial = makeValidXMLName(lInitialStateName);
119
- }
120
- return lReturnValue;
111
+ const lInitialPseudoStateName = findInitialPseudoStateName(pStateMachine);
112
+ const lInitialStateName = findInitialStateName(
113
+ pStateMachine,
114
+ lInitialPseudoStateName,
115
+ );
116
+ const lReturnValue = {
117
+ states: pStateMachine.states
118
+ .filter((pState) => {
119
+ if (
120
+ lInitialStateName &&
121
+ lInitialStateName !== lInitialPseudoStateName
122
+ ) {
123
+ return pState.type !== "initial";
124
+ }
125
+ return true;
126
+ })
127
+ .map(
128
+ transformState(
129
+ pTransitions ||
130
+ new StateMachineModel(pStateMachine).flattenedTransitions,
131
+ ),
132
+ ),
133
+ };
134
+ if (lInitialStateName) {
135
+ lReturnValue.initial = makeValidXMLName(lInitialStateName);
136
+ }
137
+ return lReturnValue;
121
138
  }