xstate 4.7.7 → 4.9.1

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.
package/lib/actions.js CHANGED
@@ -21,12 +21,29 @@ var __rest = (this && this.__rest) || function (s, e) {
21
21
  }
22
22
  return t;
23
23
  };
24
+ var __read = (this && this.__read) || function (o, n) {
25
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
26
+ if (!m) return o;
27
+ var i = m.call(o), r, ar = [], e;
28
+ try {
29
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
30
+ }
31
+ catch (error) { e = { error: error }; }
32
+ finally {
33
+ try {
34
+ if (r && !r.done && (m = i["return"])) m.call(i);
35
+ }
36
+ finally { if (e) throw e.error; }
37
+ }
38
+ return ar;
39
+ };
24
40
  Object.defineProperty(exports, "__esModule", { value: true });
25
41
  var types_1 = require("./types");
26
42
  var actionTypes = require("./actionTypes");
27
43
  exports.actionTypes = actionTypes;
28
44
  var utils_1 = require("./utils");
29
45
  var utils_2 = require("./utils");
46
+ var environment_1 = require("./environment");
30
47
  exports.initEvent = utils_1.toSCXMLEvent({ type: actionTypes.init });
31
48
  function getActionFunction(actionType, actionFunctionMap) {
32
49
  return actionFunctionMap
@@ -84,7 +101,9 @@ exports.toActionObjects = function (action, actionFunctionMap) {
84
101
  return [];
85
102
  }
86
103
  var actions = utils_2.isArray(action) ? action : [action];
87
- return actions.map(function (subAction) { return toActionObject(subAction, actionFunctionMap); });
104
+ return actions.map(function (subAction) {
105
+ return toActionObject(subAction, actionFunctionMap);
106
+ });
88
107
  };
89
108
  function toActivityDefinition(action) {
90
109
  var actionObject = toActionObject(action);
@@ -366,3 +385,64 @@ function escalate(errorData, options) {
366
385
  }, __assign(__assign({}, options), { to: types_1.SpecialTargets.Parent }));
367
386
  }
368
387
  exports.escalate = escalate;
388
+ function choose(conds) {
389
+ return {
390
+ type: types_1.ActionTypes.Choose,
391
+ conds: conds
392
+ };
393
+ }
394
+ exports.choose = choose;
395
+ function resolveActions(machine, currentState, currentContext, _event, actions) {
396
+ var _a = __read(utils_1.partition(actions, function (action) {
397
+ return action.type === actionTypes.assign;
398
+ }), 2), assignActions = _a[0], otherActions = _a[1];
399
+ var updatedContext = assignActions.length
400
+ ? utils_1.updateContext(currentContext, _event, assignActions, currentState)
401
+ : currentContext;
402
+ var resolvedActions = utils_1.flatten(otherActions.map(function (actionObject) {
403
+ var _a;
404
+ switch (actionObject.type) {
405
+ case actionTypes.raise:
406
+ return resolveRaise(actionObject);
407
+ case actionTypes.send:
408
+ var sendAction = resolveSend(actionObject, updatedContext, _event, machine.options.delays); // TODO: fix ActionTypes.Init
409
+ if (!environment_1.IS_PRODUCTION) {
410
+ // warn after resolving as we can create better contextual message here
411
+ utils_1.warn(!utils_1.isString(actionObject.delay) ||
412
+ typeof sendAction.delay === 'number',
413
+ // tslint:disable-next-line:max-line-length
414
+ "No delay reference for delay expression '" + actionObject.delay + "' was found on machine '" + machine.id + "'");
415
+ }
416
+ return sendAction;
417
+ case actionTypes.log:
418
+ return exports.resolveLog(actionObject, updatedContext, _event);
419
+ case actionTypes.choose: {
420
+ var chooseAction = actionObject;
421
+ var matchedActions = (_a = chooseAction.conds.find(function (condition) {
422
+ var guard = utils_1.toGuard(condition.cond, machine.options.guards);
423
+ return (!guard ||
424
+ utils_1.evaluateGuard(machine, guard, updatedContext, _event, currentState));
425
+ })) === null || _a === void 0 ? void 0 : _a.actions;
426
+ if (!matchedActions) {
427
+ return [];
428
+ }
429
+ var resolved = resolveActions(machine, currentState, updatedContext, _event, exports.toActionObjects(utils_1.toArray(matchedActions)));
430
+ updatedContext = resolved[1];
431
+ return resolved[0];
432
+ }
433
+ case actionTypes.pure: {
434
+ var matchedActions = actionObject.get(updatedContext, _event.data);
435
+ if (!matchedActions) {
436
+ return [];
437
+ }
438
+ var resolved = resolveActions(machine, currentState, updatedContext, _event, exports.toActionObjects(utils_1.toArray(matchedActions)));
439
+ updatedContext = resolved[1];
440
+ return resolved[0];
441
+ }
442
+ default:
443
+ return toActionObject(actionObject, machine.options.actions);
444
+ }
445
+ }));
446
+ return [resolvedActions, updatedContext];
447
+ }
448
+ exports.resolveActions = resolveActions;
package/lib/index.d.ts CHANGED
@@ -4,7 +4,7 @@ import { StateNode } from './StateNode';
4
4
  import { State } from './State';
5
5
  import { Machine, createMachine } from './Machine';
6
6
  import { Actor } from './Actor';
7
- import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate } from './actions';
7
+ import { raise, send, sendParent, sendUpdate, log, start, stop, assign, after, done, respond, doneInvoke, forwardTo, escalate, choose, pure } from './actions';
8
8
  import { interpret, Interpreter, spawn } from './interpreter';
9
9
  import { matchState } from './match';
10
10
  declare const actions: {
@@ -22,6 +22,8 @@ declare const actions: {
22
22
  respond: typeof respond;
23
23
  forwardTo: typeof forwardTo;
24
24
  escalate: typeof escalate;
25
+ choose: typeof choose;
26
+ pure: typeof pure;
25
27
  };
26
28
  export { Actor, Machine, StateNode, State, matchesState, mapState, actions, assign, send, sendParent, sendUpdate, forwardTo, interpret, Interpreter, matchState, spawn, doneInvoke, createMachine };
27
29
  export * from './types';
package/lib/index.js CHANGED
@@ -41,7 +41,9 @@ var actions = {
41
41
  done: actions_1.done,
42
42
  respond: actions_1.respond,
43
43
  forwardTo: actions_1.forwardTo,
44
- escalate: actions_1.escalate
44
+ escalate: actions_1.escalate,
45
+ choose: actions_1.choose,
46
+ pure: actions_1.pure
45
47
  };
46
48
  exports.actions = actions;
47
49
  __export(require("./types"));
@@ -64,7 +64,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
64
64
  */
65
65
  constructor(machine: StateMachine<TContext, TStateSchema, TEvent, TTypestate>, options?: Partial<InterpreterOptions>);
66
66
  get initialState(): State<TContext, TEvent>;
67
- get state(): State<TContext, TEvent>;
67
+ get state(): State<TContext, TEvent, any, TTypestate>;
68
68
  static interpret: typeof interpret;
69
69
  /**
70
70
  * Executes the actions of the given state, with that state's `context` and `event`.
@@ -110,12 +110,12 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
110
110
  /**
111
111
  * Alias for Interpreter.prototype.start
112
112
  */
113
- init: (initialState?: string | import("./types").StateValueMap | State<TContext, TEvent, any, any> | undefined) => Interpreter<TContext, TStateSchema, TEvent, any>;
113
+ init: (initialState?: string | import("./types").StateValueMap | State<TContext, TEvent, any, any> | undefined) => Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
114
114
  /**
115
115
  * Starts the interpreter from the given state, or the initial state.
116
116
  * @param initialState The state to start the statechart from
117
117
  */
118
- start(initialState?: State<TContext, TEvent> | StateValue): Interpreter<TContext, TStateSchema, TEvent>;
118
+ start(initialState?: State<TContext, TEvent> | StateValue): Interpreter<TContext, TStateSchema, TEvent, TTypestate>;
119
119
  /**
120
120
  * Stops the interpreter and unsubscribe all listeners.
121
121
  *
@@ -152,6 +152,7 @@ export declare class Interpreter<TContext, TStateSchema extends StateSchema = an
152
152
  private defer;
153
153
  private cancel;
154
154
  private exec;
155
+ private removeChild;
155
156
  private stopChild;
156
157
  spawn(entity: Spawnable, name: string, options?: SpawnOptions): Actor;
157
158
  spawnMachine<TChildContext, TChildStateSchema, TChildEvent extends EventObject>(machine: StateMachine<TChildContext, TChildStateSchema, TChildEvent>, options?: {
@@ -763,14 +763,17 @@ var Interpreter = /** @class */ (function () {
763
763
  }
764
764
  return undefined;
765
765
  };
766
+ Interpreter.prototype.removeChild = function (childId) {
767
+ this.children.delete(childId);
768
+ this.forwardTo.delete(childId);
769
+ delete this.state.children[childId];
770
+ };
766
771
  Interpreter.prototype.stopChild = function (childId) {
767
772
  var child = this.children.get(childId);
768
773
  if (!child) {
769
774
  return;
770
775
  }
771
- this.children.delete(childId);
772
- this.forwardTo.delete(childId);
773
- delete this.state.children[childId];
776
+ this.removeChild(childId);
774
777
  if (utils_1.isFunction(child.stop)) {
775
778
  child.stop();
776
779
  }
@@ -808,16 +811,17 @@ var Interpreter = /** @class */ (function () {
808
811
  });
809
812
  });
810
813
  }
811
- childService
812
- .onDone(function (doneEvent) {
813
- _this.send(utils_1.toSCXMLEvent(doneEvent, { origin: childService.id }));
814
- })
815
- .start();
816
814
  var actor = childService;
817
815
  this.children.set(childService.id, actor);
818
816
  if (resolvedOptions.autoForward) {
819
817
  this.forwardTo.add(childService.id);
820
818
  }
819
+ childService
820
+ .onDone(function (doneEvent) {
821
+ _this.removeChild(childService.id);
822
+ _this.send(utils_1.toSCXMLEvent(doneEvent, { origin: childService.id }));
823
+ })
824
+ .start();
821
825
  return actor;
822
826
  };
823
827
  Interpreter.prototype.spawnPromise = function (promise, id) {
@@ -825,10 +829,12 @@ var Interpreter = /** @class */ (function () {
825
829
  var canceled = false;
826
830
  promise.then(function (response) {
827
831
  if (!canceled) {
832
+ _this.removeChild(id);
828
833
  _this.send(utils_1.toSCXMLEvent(actions_1.doneInvoke(id, response), { origin: id }));
829
834
  }
830
835
  }, function (errorData) {
831
836
  if (!canceled) {
837
+ _this.removeChild(id);
832
838
  var errorEvent = actions_1.error(id, errorData);
833
839
  try {
834
840
  // Send "error.platform.id" to this (parent).
@@ -938,8 +944,10 @@ var Interpreter = /** @class */ (function () {
938
944
  var subscription = source.subscribe(function (value) {
939
945
  _this.send(utils_1.toSCXMLEvent(value, { origin: id }));
940
946
  }, function (err) {
947
+ _this.removeChild(id);
941
948
  _this.send(utils_1.toSCXMLEvent(actions_1.error(id, err), { origin: id }));
942
949
  }, function () {
950
+ _this.removeChild(id);
943
951
  _this.send(utils_1.toSCXMLEvent(actions_1.doneInvoke(id), { origin: id }));
944
952
  });
945
953
  var actor = {
package/lib/json.d.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { StateNode, ActionObject, Guard, InvokeDefinition } from './';
2
+ interface JSONFunction {
3
+ $function: string;
4
+ }
5
+ export declare function stringifyFunction(fn: Function): JSONFunction;
6
+ interface TransitionConfig {
7
+ target: string[];
8
+ source: string;
9
+ actions: Array<ActionObject<any, any>>;
10
+ cond: Guard<any, any> | undefined;
11
+ eventType: string;
12
+ }
13
+ interface StateNodeConfig {
14
+ type: StateNode['type'];
15
+ id: string;
16
+ key: string;
17
+ initial?: string;
18
+ entry: Array<ActionObject<any, any>>;
19
+ exit: Array<ActionObject<any, any>>;
20
+ on: {
21
+ [key: string]: TransitionConfig[];
22
+ };
23
+ invoke: Array<InvokeDefinition<any, any>>;
24
+ states: Record<string, StateNodeConfig>;
25
+ }
26
+ export declare function machineToJSON(stateNode: StateNode): StateNodeConfig;
27
+ export declare function stringify(machine: StateNode): string;
28
+ export declare function parse(machineString: string): StateNodeConfig;
29
+ export declare function jsonify<T extends Record<string, any>>(value: T): T;
30
+ export {};
31
+ //# sourceMappingURL=json.d.ts.map
package/lib/json.js ADDED
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var utils_1 = require("./utils");
4
+ // tslint:disable-next-line:ban-types
5
+ function stringifyFunction(fn) {
6
+ return {
7
+ $function: fn.toString()
8
+ };
9
+ }
10
+ exports.stringifyFunction = stringifyFunction;
11
+ function getStateNodeId(stateNode) {
12
+ return "#" + stateNode.id;
13
+ }
14
+ // derive config from machine
15
+ function machineToJSON(stateNode) {
16
+ var config = {
17
+ type: stateNode.type,
18
+ initial: stateNode.initial === undefined ? undefined : String(stateNode.initial),
19
+ id: stateNode.id,
20
+ key: stateNode.key,
21
+ entry: stateNode.onEntry,
22
+ exit: stateNode.onExit,
23
+ on: utils_1.mapValues(stateNode.on, function (transition) {
24
+ return transition.map(function (t) {
25
+ return {
26
+ target: t.target ? t.target.map(getStateNodeId) : [],
27
+ source: getStateNodeId(t.source),
28
+ actions: t.actions,
29
+ cond: t.cond,
30
+ eventType: t.eventType
31
+ };
32
+ });
33
+ }),
34
+ invoke: stateNode.invoke,
35
+ states: {}
36
+ };
37
+ Object.values(stateNode.states).forEach(function (sn) {
38
+ config.states[sn.key] = machineToJSON(sn);
39
+ });
40
+ return config;
41
+ }
42
+ exports.machineToJSON = machineToJSON;
43
+ function stringify(machine) {
44
+ return JSON.stringify(machineToJSON(machine), function (_, value) {
45
+ if (utils_1.isFunction(value)) {
46
+ return { $function: value.toString() };
47
+ }
48
+ return value;
49
+ });
50
+ }
51
+ exports.stringify = stringify;
52
+ function parse(machineString) {
53
+ var config = JSON.parse(machineString, function (_, value) {
54
+ if (typeof value === 'object' && '$function' in value) {
55
+ return new Function(value.value);
56
+ }
57
+ return value;
58
+ });
59
+ return config;
60
+ }
61
+ exports.parse = parse;
62
+ function jsonify(value) {
63
+ Object.defineProperty(value, 'toJSON', {
64
+ value: function () {
65
+ return utils_1.mapValues(value, function (subValue) {
66
+ if (utils_1.isFunction(subValue)) {
67
+ return stringifyFunction(subValue);
68
+ }
69
+ else if (typeof subValue === 'object' && !Array.isArray(subValue)) {
70
+ // mostly for assignments
71
+ return utils_1.mapValues(subValue, function (subSubValue) {
72
+ if (utils_1.isFunction(subSubValue)) {
73
+ return stringifyFunction(subSubValue);
74
+ }
75
+ return subSubValue;
76
+ });
77
+ }
78
+ return subValue;
79
+ });
80
+ }
81
+ });
82
+ return value;
83
+ }
84
+ exports.jsonify = jsonify;
package/lib/scxml.js CHANGED
@@ -30,6 +30,17 @@ var __spread = (this && this.__spread) || function () {
30
30
  for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
31
31
  return ar;
32
32
  };
33
+ var __values = (this && this.__values) || function(o) {
34
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
35
+ if (m) return m.call(o);
36
+ if (o && typeof o.length === "number") return {
37
+ next: function () {
38
+ if (o && i >= o.length) o = void 0;
39
+ return { value: o && o[i++], done: !o };
40
+ }
41
+ };
42
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
43
+ };
33
44
  Object.defineProperty(exports, "__esModule", { value: true });
34
45
  var xml_js_1 = require("xml-js");
35
46
  var index_1 = require("./index");
@@ -103,60 +114,128 @@ var evaluateExecutableContent = function (context, _ev, meta, body) {
103
114
  var fn = new (Function.bind.apply(Function, __spread([void 0], args, [fnBody])))();
104
115
  return fn(context, meta._event);
105
116
  };
106
- function mapActions(elements) {
107
- return elements.map(function (element) {
108
- switch (element.name) {
109
- case 'raise':
110
- return actions.raise(element.attributes
111
- .event);
112
- case 'assign':
113
- return actions.assign(function (context, e, meta) {
114
- var fnBody = "\n return {'" + element.attributes.location + "': " + element.attributes.expr + "};\n ";
115
- return evaluateExecutableContent(context, e, meta, fnBody);
116
- });
117
- case 'send':
118
- var _a = element.attributes, event_1 = _a.event, eventexpr_1 = _a.eventexpr, target = _a.target;
119
- var convertedEvent = void 0;
120
- var convertedDelay = void 0;
121
- var params_1 = element.elements &&
122
- element.elements.reduce(function (acc, child) {
123
- if (child.name === 'content') {
124
- throw new Error('Conversion of <content/> inside <send/> not implemented.');
125
- }
126
- return "" + acc + child.attributes.name + ":" + child.attributes.expr + ",\n";
127
- }, '');
128
- if (event_1 && !params_1) {
129
- convertedEvent = event_1;
130
- }
131
- else {
132
- convertedEvent = function (context, _ev, meta) {
133
- var fnBody = "\n return { type: " + (event_1 ? "\"" + event_1 + "\"" : eventexpr_1) + ", " + (params_1 ? params_1 : '') + " }\n ";
134
- return evaluateExecutableContent(context, _ev, meta, fnBody);
135
- };
136
- }
137
- if ('delay' in element.attributes) {
138
- convertedDelay = delayToMs(element.attributes.delay);
117
+ function createCond(cond) {
118
+ return function (context, _event, meta) {
119
+ return evaluateExecutableContent(context, _event, meta, "return " + cond + ";");
120
+ };
121
+ }
122
+ function mapAction(element) {
123
+ var e_1, _a;
124
+ switch (element.name) {
125
+ case 'raise': {
126
+ return actions.raise(element.attributes.event);
127
+ }
128
+ case 'assign': {
129
+ return actions.assign(function (context, e, meta) {
130
+ var fnBody = "\n return {'" + element.attributes.location + "': " + element.attributes.expr + "};\n ";
131
+ return evaluateExecutableContent(context, e, meta, fnBody);
132
+ });
133
+ }
134
+ case 'send': {
135
+ var _b = element.attributes, event_1 = _b.event, eventexpr_1 = _b.eventexpr, target = _b.target;
136
+ var convertedEvent = void 0;
137
+ var convertedDelay = void 0;
138
+ var params_1 = element.elements &&
139
+ element.elements.reduce(function (acc, child) {
140
+ if (child.name === 'content') {
141
+ throw new Error('Conversion of <content/> inside <send/> not implemented.');
142
+ }
143
+ return "" + acc + child.attributes.name + ":" + child.attributes.expr + ",\n";
144
+ }, '');
145
+ if (event_1 && !params_1) {
146
+ convertedEvent = event_1;
147
+ }
148
+ else {
149
+ convertedEvent = function (context, _ev, meta) {
150
+ var fnBody = "\n return { type: " + (event_1 ? "\"" + event_1 + "\"" : eventexpr_1) + ", " + (params_1 ? params_1 : '') + " }\n ";
151
+ return evaluateExecutableContent(context, _ev, meta, fnBody);
152
+ };
153
+ }
154
+ if ('delay' in element.attributes) {
155
+ convertedDelay = delayToMs(element.attributes.delay);
156
+ }
157
+ else if (element.attributes.delayexpr) {
158
+ convertedDelay = function (context, _ev, meta) {
159
+ var fnBody = "\n return (" + delayToMs + ")(" + element.attributes.delayexpr + ");\n ";
160
+ return evaluateExecutableContent(context, _ev, meta, fnBody);
161
+ };
162
+ }
163
+ return actions.send(convertedEvent, {
164
+ delay: convertedDelay,
165
+ to: target
166
+ });
167
+ }
168
+ case 'log': {
169
+ var label = element.attributes.label;
170
+ return actions.log(function (context, e, meta) {
171
+ var fnBody = "\n return " + element.attributes.expr + ";\n ";
172
+ return evaluateExecutableContent(context, e, meta, fnBody);
173
+ }, label !== undefined ? String(label) : undefined);
174
+ }
175
+ case 'if': {
176
+ var conds = [];
177
+ var current = {
178
+ cond: createCond(element.attributes.cond),
179
+ actions: []
180
+ };
181
+ try {
182
+ for (var _c = __values(element.elements), _d = _c.next(); !_d.done; _d = _c.next()) {
183
+ var el = _d.value;
184
+ if (el.type === 'comment') {
185
+ continue;
186
+ }
187
+ switch (el.name) {
188
+ case 'elseif':
189
+ conds.push(current);
190
+ current = {
191
+ cond: createCond(el.attributes.cond),
192
+ actions: []
193
+ };
194
+ break;
195
+ case 'else':
196
+ conds.push(current);
197
+ current = { actions: [] };
198
+ break;
199
+ default:
200
+ current.actions.push(mapAction(el));
201
+ break;
202
+ }
139
203
  }
140
- else if (element.attributes.delayexpr) {
141
- convertedDelay = function (context, _ev, meta) {
142
- var fnBody = "\n return (" + delayToMs + ")(" + element.attributes.delayexpr + ");\n ";
143
- return evaluateExecutableContent(context, _ev, meta, fnBody);
144
- };
204
+ }
205
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
206
+ finally {
207
+ try {
208
+ if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
145
209
  }
146
- return actions.send(convertedEvent, {
147
- delay: convertedDelay,
148
- to: target
149
- });
150
- case 'log':
151
- var label = element.attributes.label;
152
- return actions.log(function (context, e, meta) {
153
- var fnBody = "\n return " + element.attributes.expr + ";\n ";
154
- return evaluateExecutableContent(context, e, meta, fnBody);
155
- }, label !== undefined ? String(label) : undefined);
156
- default:
157
- return { type: 'not-implemented' };
210
+ finally { if (e_1) throw e_1.error; }
211
+ }
212
+ conds.push(current);
213
+ return actions.choose(conds);
158
214
  }
159
- });
215
+ default:
216
+ throw new Error("Conversion of \"" + element.name + "\" elements is not implemented yet.");
217
+ }
218
+ }
219
+ function mapActions(elements) {
220
+ var e_2, _a;
221
+ var mapped = [];
222
+ try {
223
+ for (var elements_1 = __values(elements), elements_1_1 = elements_1.next(); !elements_1_1.done; elements_1_1 = elements_1.next()) {
224
+ var element = elements_1_1.value;
225
+ if (element.type === 'comment') {
226
+ continue;
227
+ }
228
+ mapped.push(mapAction(element));
229
+ }
230
+ }
231
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
232
+ finally {
233
+ try {
234
+ if (elements_1_1 && !elements_1_1.done && (_a = elements_1.return)) _a.call(elements_1);
235
+ }
236
+ finally { if (e_2) throw e_2.error; }
237
+ }
238
+ return mapped;
160
239
  }
161
240
  function toConfig(nodeJson, id, options) {
162
241
  var parallel = nodeJson.name === 'parallel';
@@ -212,10 +291,7 @@ function toConfig(nodeJson, id, options) {
212
291
  var internal = getAttribute(value, 'type') === 'internal';
213
292
  return __assign(__assign(__assign({ event: event, target: getTargets(targets) }, (value.elements ? executableContent(value.elements) : undefined)), (value.attributes && value.attributes.cond
214
293
  ? {
215
- cond: function (context, _event, meta) {
216
- var fnBody = "\n return " + value.attributes.cond + ";\n ";
217
- return evaluateExecutableContent(context, _event, meta, fnBody);
218
- }
294
+ cond: createCond(value.attributes.cond)
219
295
  }
220
296
  : undefined)), { internal: internal });
221
297
  });
@@ -226,8 +302,7 @@ function toConfig(nodeJson, id, options) {
226
302
  ? mapActions(onExitElement.elements)
227
303
  : undefined;
228
304
  var invoke = invokeElements.map(function (element) {
229
- if (!['scxml', 'http://www.w3.org/TR/scxml/'].includes(element.attributes
230
- .type)) {
305
+ if (!['scxml', 'http://www.w3.org/TR/scxml/'].includes(element.attributes.type)) {
231
306
  throw new Error('Currently only converting invoke elements of type SCXML is supported.');
232
307
  }
233
308
  var content = element.elements.find(function (el) { return el.name === 'content'; });