diff --git a/new-packages/ts-project/__tests__/actions.test.ts b/new-packages/ts-project/__tests__/actions.test.ts index 5a82ff6c..b7b4df10 100644 --- a/new-packages/ts-project/__tests__/actions.test.ts +++ b/new-packages/ts-project/__tests__/actions.test.ts @@ -57,6 +57,7 @@ test('should extract a string entry action (direct)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -130,6 +131,7 @@ test('should extract a string exit action (direct)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -203,6 +205,7 @@ test('should extract a string action (in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -292,6 +295,7 @@ test('should extract multiple string actions', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -367,6 +371,7 @@ test('should extract a simple parameterized action (direct)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -444,6 +449,7 @@ test('should extract a simple parameterized action (in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -517,6 +523,7 @@ test('should extract an inline action (function)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -592,6 +599,7 @@ test('should extract an inline action (builtin)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -646,6 +654,7 @@ test('should error when extracting undefined action (direct)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -704,6 +713,7 @@ test('should error when extracting undefined action (in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -803,6 +813,7 @@ test('should extract a transition action', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -877,6 +888,7 @@ test('should not register multiple entry actions with duplicated entry property' "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -914,78 +926,79 @@ test('should not register multiple transition actions with duplicated actions pr const project = await createTestProject(tmpPath); expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": { - "block-0": { - "blockType": "action", - "parentId": "edge-0", - "properties": { - "params": {}, - "type": "callAnders", - }, - "sourceId": "callAnders", - "uniqueId": "block-0", + [ + { + "blocks": { + "block-0": { + "blockType": "action", + "parentId": "edge-0", + "properties": { + "params": {}, + "type": "callAnders", + }, + "sourceId": "callAnders", + "uniqueId": "block-0", + }, }, - }, - "data": { - "context": {}, - }, - "edges": { - "edge-0": { - "data": { - "actions": [ - "block-0", - ], - "description": undefined, - "eventTypeData": { - "eventType": "EVENT", - "type": "named", - }, - "guard": undefined, - "internal": true, - "metaEntries": [], - }, - "source": "state-0", - "targets": [], - "type": "edge", - "uniqueId": "edge-0", + "data": { + "context": {}, }, - }, - "implementations": { - "actions": { - "callAnders": { - "id": "callAnders", - "name": "callAnders", - "type": "action", + "edges": { + "edge-0": { + "data": { + "actions": [ + "block-0", + ], + "description": undefined, + "eventTypeData": { + "eventType": "EVENT", + "type": "named", + }, + "guard": undefined, + "internal": true, + "metaEntries": [], + }, + "source": "state-0", + "targets": [], + "type": "edge", + "uniqueId": "edge-0", }, }, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", + "implementations": { + "actions": { + "callAnders": { + "id": "callAnders", + "name": "callAnders", + "type": "action", + }, + }, + "actors": {}, + "guards": {}, }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); diff --git a/new-packages/ts-project/__tests__/actors.test.ts b/new-packages/ts-project/__tests__/actors.test.ts index 2c3e1886..c5910610 100644 --- a/new-packages/ts-project/__tests__/actors.test.ts +++ b/new-packages/ts-project/__tests__/actors.test.ts @@ -59,6 +59,7 @@ test('should extract an actor with string src (direct)', async () => { "invoke": [ "block-0", ], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -157,6 +158,7 @@ test('should extract multiple actors with different string sources (direct)', as "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -175,6 +177,7 @@ test('should extract multiple actors with different string sources (direct)', as "invoke": [ "block-0", ], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -193,6 +196,7 @@ test('should extract multiple actors with different string sources (direct)', as "invoke": [ "block-1", ], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -286,6 +290,7 @@ test('should extract multiple actors with the same string source (direct)', asyn "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -304,6 +309,7 @@ test('should extract multiple actors with the same string source (direct)', asyn "invoke": [ "block-0", ], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -322,6 +328,7 @@ test('should extract multiple actors with the same string source (direct)', asyn "invoke": [ "block-1", ], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -420,6 +427,7 @@ test('should extract multiple actors with string source (array)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -439,6 +447,7 @@ test('should extract multiple actors with string source (array)', async () => { "block-0", "block-1", ], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -537,6 +546,7 @@ test('should extract actor with inline source (direct)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -555,6 +565,7 @@ test('should extract actor with inline source (direct)', async () => { "invoke": [ "block-0", ], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -573,6 +584,7 @@ test('should extract actor with inline source (direct)', async () => { "invoke": [ "block-1", ], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -610,63 +622,65 @@ test('should raise error if actor is missing src property', async () => { const project = await createTestProject(tmpPath); expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": "foo", - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", - }, - }, - "root": "state-0", - }, [ { - "type": "state_property_unhandled", + "blocks": {}, + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": "foo", + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, + }, + "root": "state-0", }, + [ + { + "type": "state_property_unhandled", + }, + ], ], - ], - ] - `); + ] + `); }); test('should extract actor id if it is present with a string value', async () => { @@ -692,76 +706,78 @@ test('should extract actor id if it is present with a string value', async () => const project = await createTestProject(tmpPath); expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": { - "block-0": { - "blockType": "actor", - "parentId": "state-1", - "properties": { - "id": "user-provided-id", - "src": "actor1", - }, - "sourceId": "actor1", - "uniqueId": "block-0", + [ + { + "blocks": { + "block-0": { + "blockType": "actor", + "parentId": "state-1", + "properties": { + "id": "user-provided-id", + "src": "actor1", + }, + "sourceId": "actor1", + "uniqueId": "block-0", + }, }, - }, - "data": { - "context": {}, - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": { - "actor1": { - "id": "actor1", - "name": "actor1", - "type": "actor", + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": { + "actor1": { + "id": "actor1", + "name": "actor1", + "type": "actor", + }, }, + "guards": {}, }, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": "foo", - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [ - "block-0", - ], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": "foo", + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [ + "block-0", + ], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); diff --git a/new-packages/ts-project/__tests__/createMachine.test.ts b/new-packages/ts-project/__tests__/createMachine.test.ts index e28f258b..b21cc96a 100644 --- a/new-packages/ts-project/__tests__/createMachine.test.ts +++ b/new-packages/ts-project/__tests__/createMachine.test.ts @@ -37,6 +37,7 @@ test('should extract a machine with empty config', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -90,6 +91,7 @@ test('should extract a machine created with no config at all', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -149,6 +151,7 @@ test('should extract multiple machines in a single file', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "machine1", "metaEntries": [], "tags": [], "type": "normal", @@ -183,6 +186,7 @@ test('should extract multiple machines in a single file', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "machine2", "metaEntries": [], "tags": [], "type": "normal", @@ -240,6 +244,7 @@ test('should extract a machine created with `setup`', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -256,6 +261,7 @@ test('should extract a machine created with `setup`', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", diff --git a/new-packages/ts-project/__tests__/guards.test.ts b/new-packages/ts-project/__tests__/guards.test.ts index e8516f6d..4671bb6f 100644 --- a/new-packages/ts-project/__tests__/guards.test.ts +++ b/new-packages/ts-project/__tests__/guards.test.ts @@ -86,6 +86,7 @@ test('should extract guard from transition (string)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -102,6 +103,7 @@ test('should extract guard from transition (string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -118,6 +120,7 @@ test('should extract guard from transition (string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -220,6 +223,7 @@ test('should extract guard (inline)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -236,6 +240,7 @@ test('should extract guard (inline)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -252,6 +257,7 @@ test('should extract guard (inline)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -356,6 +362,7 @@ test('should extract parameterized guards', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -372,6 +379,7 @@ test('should extract parameterized guards', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -388,6 +396,7 @@ test('should extract parameterized guards', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -490,6 +499,7 @@ test('should extract higher order guards as inline', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -506,6 +516,7 @@ test('should extract higher order guards as inline', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -522,6 +533,7 @@ test('should extract higher order guards as inline', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -707,6 +719,7 @@ test('should extract multiple guards', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -723,6 +736,7 @@ test('should extract multiple guards', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -739,6 +753,7 @@ test('should extract multiple guards', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -755,6 +770,7 @@ test('should extract multiple guards', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -857,6 +873,7 @@ test('should support XState v4 guard', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -873,6 +890,7 @@ test('should support XState v4 guard', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -889,6 +907,7 @@ test('should support XState v4 guard', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -992,6 +1011,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1008,6 +1028,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1024,6 +1045,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -1131,6 +1153,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1147,6 +1170,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1163,6 +1187,7 @@ test('should raise error if both guard and cond are provided, pick guard over co "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -1252,6 +1277,7 @@ test('should raise error for parameterized guard is missing type property', asyn "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1268,6 +1294,7 @@ test('should raise error for parameterized guard is missing type property', asyn "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1284,6 +1311,7 @@ test('should raise error for parameterized guard is missing type property', asyn "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -1375,6 +1403,7 @@ test('should raise error for parameterized guard with invalid type property', as "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1391,6 +1420,7 @@ test('should raise error for parameterized guard with invalid type property', as "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1407,6 +1437,7 @@ test('should raise error for parameterized guard with invalid type property', as "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", diff --git a/new-packages/ts-project/__tests__/state.test.ts b/new-packages/ts-project/__tests__/state.test.ts index f78b0f46..ebdda726 100644 --- a/new-packages/ts-project/__tests__/state.test.ts +++ b/new-packages/ts-project/__tests__/state.test.ts @@ -40,6 +40,7 @@ test('should extract a simple state', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -56,6 +57,7 @@ test('should extract a simple state', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -121,6 +123,7 @@ test('should extract states recursively', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -137,6 +140,7 @@ test('should extract states recursively', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -153,6 +157,7 @@ test('should extract states recursively', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -169,6 +174,7 @@ test('should extract states recursively', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -185,6 +191,7 @@ test('should extract states recursively', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "state4", "metaEntries": [], "tags": [], "type": "normal", @@ -202,6 +209,137 @@ test('should extract states recursively', async () => { `); }); +test("should use the root's id as its key", async () => { + const tmpPath = await testdir({ + 'tsconfig.json': JSON.stringify({}), + 'index.ts': ts` + import { createMachine } from "xstate"; + + createMachine({ + id: 'my-machine', + }); + `, + }); + + const project = await createTestProject(tmpPath); + expect(replaceUniqueIds(project.extractMachines('index.ts'))) + .toMatchInlineSnapshot(` + [ + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "my-machine", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + }, + "root": "state-0", + }, + [], + ], + ] + `); +}); + +test("should not use the non-root's id as its key", async () => { + const tmpPath = await testdir({ + 'tsconfig.json': JSON.stringify({}), + 'index.ts': ts` + import { createMachine } from "xstate"; + + createMachine({ + states: { + foo: { + id: 'my-state', + }, + }, + }); + `, + }); + + const project = await createTestProject(tmpPath); + expect(replaceUniqueIds(project.extractMachines('index.ts'))) + .toMatchInlineSnapshot(` + [ + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, + }, + "root": "state-0", + }, + [], + ], + ] + `); +}); + test('should extract state.initial with string value', async () => { const tmpPath = await testdir({ 'tsconfig.json': JSON.stringify({}), @@ -243,6 +381,7 @@ test('should extract state.initial with string value', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -259,6 +398,7 @@ test('should extract state.initial with string value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -317,6 +457,7 @@ test('should extract state.initial with template literal value', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -333,6 +474,7 @@ test('should extract state.initial with template literal value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -389,6 +531,7 @@ test('should extract state.initial with undefined value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -445,6 +588,7 @@ test('should raise error when state.initial property has invalid value', async ( "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -505,6 +649,7 @@ test('should extract state.type with value "parallel"', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "parallel", @@ -561,6 +706,7 @@ test('should extract state.type with value "final"', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "final", @@ -617,6 +763,7 @@ test('should extract state.type with value "history"', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "history", @@ -673,6 +820,7 @@ test('should extract state.type with value undefined', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -729,6 +877,7 @@ test('should raise error when state.type has invalid value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -789,6 +938,7 @@ test('should extract state.history with value "shallow"', async () => { "history": "shallow", "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -845,6 +995,7 @@ test('should extract state.history with value "deep"', async () => { "history": "deep", "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -901,6 +1052,7 @@ test('should extract state.history with value true as deep', async () => { "history": "deep", "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -957,6 +1109,7 @@ test('should extract state.history with value false as shallow', async () => { "history": "shallow", "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1013,6 +1166,7 @@ test('should extract state.history with value undefined', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1073,6 +1227,7 @@ test('should extract state.description with string value', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1089,6 +1244,7 @@ test('should extract state.description with string value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1151,6 +1307,7 @@ test('should extract state.description with template literal value', async () => "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1169,6 +1326,7 @@ test('should extract state.description with template literal value', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1229,6 +1387,7 @@ test('should extract state.description with undefined value with no errors', asy "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1245,6 +1404,7 @@ test('should extract state.description with undefined value with no errors', asy "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1305,6 +1465,7 @@ test('should raise error when state.description has invalid value', async () => "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1321,6 +1482,7 @@ test('should raise error when state.description has invalid value', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1394,6 +1556,7 @@ test("should extract state.meta when it's a javascript object", async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1410,6 +1573,7 @@ test("should extract state.meta when it's a javascript object", async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [ [ "str", @@ -1503,6 +1667,7 @@ test("should extract state.meta when it's a javascript object containing nested "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1519,6 +1684,7 @@ test("should extract state.meta when it's a javascript object containing nested "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [ [ "arr", @@ -1605,6 +1771,7 @@ test("should extract state.meta when it's a javascript object and contains multi "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1621,6 +1788,7 @@ test("should extract state.meta when it's a javascript object and contains multi "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [ [ "obj", @@ -1692,6 +1860,7 @@ test('should not raise error for state.meta with undefined value', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1708,6 +1877,7 @@ test('should not raise error for state.meta with undefined value', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1769,6 +1939,7 @@ test('should raise error when state.meta contains any value other than a plain j "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1785,6 +1956,7 @@ test('should raise error when state.meta contains any value other than a plain j "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1824,45 +1996,46 @@ test('should extract state.context on the root state', async () => { expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": { - "foo": "bar", + [ + { + "blocks": {}, + "data": { + "context": { + "foo": "bar", + }, }, - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); test('should raise error when state.context is provided on any state other than the root state', async () => { @@ -1887,63 +2060,65 @@ test('should raise error when state.context is provided on any state other than expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", }, + "root": "state-0", }, - "root": "state-0", - }, - [ - { - "type": "state_property_invalid", - }, + [ + { + "type": "state_property_invalid", + }, + ], ], - ], - ] - `); + ] + `); }); test('should raise error when state.context has any value other than plain JS object', async () => { @@ -1968,63 +2143,65 @@ test('should raise error when state.context has any value other than plain JS ob expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", }, + "root": "state-0", }, - "root": "state-0", - }, - [ - { - "type": "state_property_invalid", - }, + [ + { + "type": "state_property_invalid", + }, + ], ], - ], - ] - `); + ] + `); }); test('should extract state.context with function value (lazy context)', async () => { @@ -2047,45 +2224,46 @@ test('should extract state.context with function value (lazy context)', async () expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": "{{() => { - return { - foo: 'bar' - } - }}}", - }, - "edges": {}, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", + [ + { + "blocks": {}, + "data": { + "context": "{{() => { + return { + foo: 'bar' + } + }}}", + }, + "edges": {}, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); diff --git a/new-packages/ts-project/__tests__/transitions.test.ts b/new-packages/ts-project/__tests__/transitions.test.ts index 0a371182..80e5b8cd 100644 --- a/new-packages/ts-project/__tests__/transitions.test.ts +++ b/new-packages/ts-project/__tests__/transitions.test.ts @@ -65,6 +65,7 @@ test('should extract transition to a sibling (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -81,6 +82,7 @@ test('should extract transition to a sibling (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -97,6 +99,7 @@ test('should extract transition to a sibling (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -178,6 +181,7 @@ test('should extract transition to a sibling (string in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -194,6 +198,7 @@ test('should extract transition to a sibling (string in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -210,6 +215,7 @@ test('should extract transition to a sibling (string in array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -291,6 +297,7 @@ test('should extract transition to a sibling (direct object with target)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -307,6 +314,7 @@ test('should extract transition to a sibling (direct object with target)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -323,6 +331,7 @@ test('should extract transition to a sibling (direct object with target)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -404,6 +413,7 @@ test('should extract transition to a sibling (object with target in array)', asy "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -420,6 +430,7 @@ test('should extract transition to a sibling (object with target in array)', asy "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -436,6 +447,7 @@ test('should extract transition to a sibling (object with target in array)', asy "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -519,6 +531,7 @@ test('should extract transition to a child', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -535,6 +548,7 @@ test('should extract transition to a child', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -551,6 +565,7 @@ test('should extract transition to a child', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -634,6 +649,7 @@ test('should extract transition to an ID', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -650,6 +666,7 @@ test('should extract transition to an ID', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -666,6 +683,7 @@ test('should extract transition to an ID', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -767,6 +785,7 @@ test('should extract multiple transitions (array of strings)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -783,6 +802,7 @@ test('should extract multiple transitions (array of strings)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -799,6 +819,7 @@ test('should extract multiple transitions (array of strings)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -815,6 +836,7 @@ test('should extract multiple transitions (array of strings)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -916,6 +938,7 @@ test('should extract multiple transitions (array of objects)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -932,6 +955,7 @@ test('should extract multiple transitions (array of objects)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -948,6 +972,7 @@ test('should extract multiple transitions (array of objects)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -964,6 +989,7 @@ test('should extract multiple transitions (array of objects)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -1065,6 +1091,7 @@ test('should extract multiple transitions (mixed array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1081,6 +1108,7 @@ test('should extract multiple transitions (mixed array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -1097,6 +1125,7 @@ test('should extract multiple transitions (mixed array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -1113,6 +1142,7 @@ test('should extract multiple transitions (mixed array)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -1209,6 +1239,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "parallel", @@ -1225,6 +1256,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": "a1", "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1241,6 +1273,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "a1", "metaEntries": [], "tags": [], "type": "normal", @@ -1257,6 +1290,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "a2", "metaEntries": [], "tags": [], "type": "normal", @@ -1273,6 +1307,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": "b1", "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -1289,6 +1324,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "b1", "metaEntries": [], "tags": [], "type": "normal", @@ -1305,6 +1341,7 @@ test('should extract transition with multiple targets (array of strings)', async "history": undefined, "initial": undefined, "invoke": [], + "key": "b2", "metaEntries": [], "tags": [], "type": "normal", @@ -1383,6 +1420,7 @@ test('should extract forbidden transition (undefined)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1399,6 +1437,7 @@ test('should extract forbidden transition (undefined)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1477,6 +1516,7 @@ test('should extract forbidden transition (null)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1493,6 +1533,7 @@ test('should extract forbidden transition (null)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1582,6 +1623,7 @@ test('should extract deep sibling transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1598,6 +1640,7 @@ test('should extract deep sibling transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1614,6 +1657,7 @@ test('should extract deep sibling transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -1630,6 +1674,7 @@ test('should extract deep sibling transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "deep", "metaEntries": [], "tags": [], "type": "normal", @@ -1646,6 +1691,7 @@ test('should extract deep sibling transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "child", "metaEntries": [], "tags": [], "type": "normal", @@ -1733,6 +1779,7 @@ test('should extract deep descendant transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1749,6 +1796,7 @@ test('should extract deep descendant transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1765,6 +1813,7 @@ test('should extract deep descendant transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "deep", "metaEntries": [], "tags": [], "type": "normal", @@ -1781,6 +1830,7 @@ test('should extract deep descendant transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "child", "metaEntries": [], "tags": [], "type": "normal", @@ -1871,6 +1921,7 @@ test('should extract transition to a deep child of an ID target', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -1887,6 +1938,7 @@ test('should extract transition to a deep child of an ID target', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -1903,6 +1955,7 @@ test('should extract transition to a deep child of an ID target', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -1919,6 +1972,7 @@ test('should extract transition to a deep child of an ID target', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "deep", "metaEntries": [], "tags": [], "type": "normal", @@ -1935,6 +1989,7 @@ test('should extract transition to a deep child of an ID target', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "child", "metaEntries": [], "tags": [], "type": "normal", @@ -2015,6 +2070,7 @@ test('should extract a wildcard transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2031,6 +2087,7 @@ test('should extract a wildcard transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2047,6 +2104,7 @@ test('should extract a wildcard transition', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -2128,6 +2186,7 @@ test('should extract transition description (single-line)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2144,6 +2203,7 @@ test('should extract transition description (single-line)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2222,6 +2282,7 @@ test('should extract an always transition (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2238,6 +2299,7 @@ test('should extract an always transition (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2254,6 +2316,7 @@ test('should extract an always transition (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -2354,6 +2417,7 @@ test('should extract invoke.onDone transition (with invoke.id)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2372,6 +2436,7 @@ test('should extract invoke.onDone transition (with invoke.id)', async () => { "invoke": [ "block-0", ], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2388,6 +2453,7 @@ test('should extract invoke.onDone transition (with invoke.id)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "relief", "metaEntries": [], "tags": [], "type": "normal", @@ -2487,6 +2553,7 @@ test('should extract invoke.onDone transition (without invoke.id)', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2505,6 +2572,7 @@ test('should extract invoke.onDone transition (without invoke.id)', async () => "invoke": [ "block-0", ], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2521,6 +2589,7 @@ test('should extract invoke.onDone transition (without invoke.id)', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "shipIt", "metaEntries": [], "tags": [], "type": "normal", @@ -2641,6 +2710,7 @@ test('should extract invoke.onDone action', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2659,6 +2729,7 @@ test('should extract invoke.onDone action', async () => { "invoke": [ "block-1", ], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2675,6 +2746,7 @@ test('should extract invoke.onDone action', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "shipIt", "metaEntries": [], "tags": [], "type": "normal", @@ -2775,6 +2847,7 @@ test('should extract invoke.onError transition (with invoke.id)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2793,6 +2866,7 @@ test('should extract invoke.onError transition (with invoke.id)', async () => { "invoke": [ "block-0", ], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2809,6 +2883,7 @@ test('should extract invoke.onError transition (with invoke.id)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "panic", "metaEntries": [], "tags": [], "type": "normal", @@ -2908,6 +2983,7 @@ test('should extract invoke.onError transition (without invoke.id)', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -2926,6 +3002,7 @@ test('should extract invoke.onError transition (without invoke.id)', async () => "invoke": [ "block-0", ], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -2942,6 +3019,7 @@ test('should extract invoke.onError transition (without invoke.id)', async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "revert", "metaEntries": [], "tags": [], "type": "normal", @@ -3029,6 +3107,7 @@ test('should extract transition description (multi-line)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -3045,6 +3124,7 @@ test('should extract transition description (multi-line)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -3124,6 +3204,7 @@ test('should extract state.onDone transition (direct string)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -3140,6 +3221,7 @@ test('should extract state.onDone transition (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -3156,6 +3238,7 @@ test('should extract state.onDone transition (direct string)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -3281,6 +3364,7 @@ test("should extract transition.meta when it's a javascript object", async () => "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -3297,6 +3381,7 @@ test("should extract transition.meta when it's a javascript object", async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -3313,6 +3398,7 @@ test("should extract transition.meta when it's a javascript object", async () => "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -3358,113 +3444,116 @@ test("should extract transition.meta when it's a javascript object containing ne expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": { - "edge-0": { - "data": { - "actions": [], - "description": undefined, - "eventTypeData": { - "eventType": "EV", - "type": "named", - }, - "guard": undefined, - "internal": true, - "metaEntries": [ - [ - "arr", + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": { + "edge-0": { + "data": { + "actions": [], + "description": undefined, + "eventTypeData": { + "eventType": "EV", + "type": "named", + }, + "guard": undefined, + "internal": true, + "metaEntries": [ [ - "str", - 123, - true, + "arr", [ - 1, - 2, - 3, + "str", + 123, + true, + [ + 1, + 2, + 3, + ], + { + "foo": "bar", + }, + null, ], - { - "foo": "bar", - }, - null, ], ], + }, + "source": "state-1", + "targets": [ + "state-2", ], + "type": "edge", + "uniqueId": "edge-0", }, - "source": "state-1", - "targets": [ - "state-2", - ], - "type": "edge", - "uniqueId": "edge-0", }, - }, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": "foo", - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", - }, - "state-2": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-2", + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": "foo", + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, + "state-2": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "bar", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-2", + }, }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); test("should extract transition.meta when it's a javascript object and contains multi level object value", async () => { @@ -3501,106 +3590,109 @@ test("should extract transition.meta when it's a javascript object and contains expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": { - "edge-0": { - "data": { - "actions": [], - "description": undefined, - "eventTypeData": { - "eventType": "EV", - "type": "named", - }, - "guard": undefined, - "internal": true, - "metaEntries": [ - [ - "obj", - { - "x": { - "y": { - "z": "some string", + [ + { + "blocks": {}, + "data": { + "context": {}, + }, + "edges": { + "edge-0": { + "data": { + "actions": [], + "description": undefined, + "eventTypeData": { + "eventType": "EV", + "type": "named", + }, + "guard": undefined, + "internal": true, + "metaEntries": [ + [ + "obj", + { + "x": { + "y": { + "z": "some string", + }, }, }, - }, + ], ], + }, + "source": "state-1", + "targets": [ + "state-2", ], + "type": "edge", + "uniqueId": "edge-0", }, - "source": "state-1", - "targets": [ - "state-2", - ], - "type": "edge", - "uniqueId": "edge-0", }, - }, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": "foo", - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", - }, - "state-2": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-2", + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": "foo", + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, + "state-2": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "bar", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-2", + }, }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); test('should not raise error for transition.meta with undefined value', async () => { @@ -3629,95 +3721,98 @@ test('should not raise error for transition.meta with undefined value', async () expect(replaceUniqueIds(project.extractMachines('index.ts'))) .toMatchInlineSnapshot(` - [ [ - { - "blocks": {}, - "data": { - "context": {}, - }, - "edges": { - "edge-0": { - "data": { - "actions": [], - "description": undefined, - "eventTypeData": { - "eventType": "EV", - "type": "named", - }, - "guard": undefined, - "internal": true, - "metaEntries": [], - }, - "source": "state-1", - "targets": [ - "state-2", - ], - "type": "edge", - "uniqueId": "edge-0", + [ + { + "blocks": {}, + "data": { + "context": {}, }, - }, - "implementations": { - "actions": {}, - "actors": {}, - "guards": {}, - }, - "nodes": { - "state-0": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": "foo", - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": undefined, - "type": "node", - "uniqueId": "state-0", - }, - "state-1": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-1", - }, - "state-2": { - "data": { - "description": undefined, - "entry": [], - "exit": [], - "history": undefined, - "initial": undefined, - "invoke": [], - "metaEntries": [], - "tags": [], - "type": "normal", - }, - "parentId": "state-0", - "type": "node", - "uniqueId": "state-2", + "edges": { + "edge-0": { + "data": { + "actions": [], + "description": undefined, + "eventTypeData": { + "eventType": "EV", + "type": "named", + }, + "guard": undefined, + "internal": true, + "metaEntries": [], + }, + "source": "state-1", + "targets": [ + "state-2", + ], + "type": "edge", + "uniqueId": "edge-0", + }, + }, + "implementations": { + "actions": {}, + "actors": {}, + "guards": {}, + }, + "nodes": { + "state-0": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": "foo", + "invoke": [], + "key": "(machine)", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": undefined, + "type": "node", + "uniqueId": "state-0", + }, + "state-1": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "foo", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-1", + }, + "state-2": { + "data": { + "description": undefined, + "entry": [], + "exit": [], + "history": undefined, + "initial": undefined, + "invoke": [], + "key": "bar", + "metaEntries": [], + "tags": [], + "type": "normal", + }, + "parentId": "state-0", + "type": "node", + "uniqueId": "state-2", + }, }, + "root": "state-0", }, - "root": "state-0", - }, - [], - ], - ] - `); + [], + ], + ] + `); }); // TODO: this needs to change as technically any value is accepted by XState. Studio only supports plain js objects right now @@ -3789,6 +3884,7 @@ test('should raise error when transition.meta contains any value other than a pl "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -3805,6 +3901,7 @@ test('should raise error when transition.meta contains any value other than a pl "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -3821,6 +3918,7 @@ test('should raise error when transition.meta contains any value other than a pl "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -3907,6 +4005,7 @@ test('should extract after transition (number delay)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -3923,6 +4022,7 @@ test('should extract after transition (number delay)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -3939,6 +4039,7 @@ test('should extract after transition (number delay)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4021,6 +4122,7 @@ test('should extract delayed transition (identifier delay)', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4037,6 +4139,7 @@ test('should extract delayed transition (identifier delay)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4053,6 +4156,7 @@ test('should extract delayed transition (identifier delay)', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4135,6 +4239,7 @@ test('should extract after transition (string with whitespace delay)', async () "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4151,6 +4256,7 @@ test('should extract after transition (string with whitespace delay)', async () "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4167,6 +4273,7 @@ test('should extract after transition (string with whitespace delay)', async () "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4287,6 +4394,7 @@ test('should extract multiple delayed transitions', async () => { "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4303,6 +4411,7 @@ test('should extract multiple delayed transitions', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4319,6 +4428,7 @@ test('should extract multiple delayed transitions', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4335,6 +4445,7 @@ test('should extract multiple delayed transitions', async () => { "history": undefined, "initial": undefined, "invoke": [], + "key": "baz", "metaEntries": [], "tags": [], "type": "normal", @@ -4417,6 +4528,7 @@ test('should extract a sibling transition as internal by default (direct string) "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4433,6 +4545,7 @@ test('should extract a sibling transition as internal by default (direct string) "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4449,6 +4562,7 @@ test('should extract a sibling transition as internal by default (direct string) "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4533,6 +4647,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4549,6 +4664,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4565,6 +4681,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4647,6 +4764,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4663,6 +4781,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4679,6 +4798,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4765,6 +4885,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4781,6 +4902,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4797,6 +4919,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4879,6 +5002,7 @@ test('should extract an explicit reentering transition as not internal', async ( "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -4895,6 +5019,7 @@ test('should extract an explicit reentering transition as not internal', async ( "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -4911,6 +5036,7 @@ test('should extract an explicit reentering transition as not internal', async ( "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -4993,6 +5119,7 @@ test('should extract an explicit non-reentering transition as internal', async ( "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5009,6 +5136,7 @@ test('should extract an explicit non-reentering transition as internal', async ( "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5025,6 +5153,7 @@ test('should extract an explicit non-reentering transition as internal', async ( "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5107,6 +5236,7 @@ test('should extract a sibling transition as not internal by default (direct str "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5123,6 +5253,7 @@ test('should extract a sibling transition as not internal by default (direct str "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5139,6 +5270,7 @@ test('should extract a sibling transition as not internal by default (direct str "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5223,6 +5355,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5239,6 +5372,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5255,6 +5389,7 @@ test('should extract a descendant transition as internal by default (direct stri "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5337,6 +5472,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5353,6 +5489,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5369,6 +5506,7 @@ test('should extract a sibling transition as internal by default (direct object "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5455,6 +5593,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5471,6 +5610,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5487,6 +5627,7 @@ test('should extract a descendant transition as internal by default (direct obje "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5569,6 +5710,7 @@ test('should extract an explicit internal transition as internal (v4)', async () "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5585,6 +5727,7 @@ test('should extract an explicit internal transition as internal (v4)', async () "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5601,6 +5744,7 @@ test('should extract an explicit internal transition as internal (v4)', async () "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5683,6 +5827,7 @@ test('should extract an explicit non-internal transition as not internal (v4)', "history": undefined, "initial": "foo", "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "normal", @@ -5699,6 +5844,7 @@ test('should extract an explicit non-internal transition as not internal (v4)', "history": undefined, "initial": undefined, "invoke": [], + "key": "foo", "metaEntries": [], "tags": [], "type": "normal", @@ -5715,6 +5861,7 @@ test('should extract an explicit non-internal transition as not internal (v4)', "history": undefined, "initial": undefined, "invoke": [], + "key": "bar", "metaEntries": [], "tags": [], "type": "normal", @@ -5813,6 +5960,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "parallel", @@ -5829,6 +5977,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": "a1", "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -5845,6 +5994,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": undefined, "invoke": [], + "key": "a1", "metaEntries": [], "tags": [], "type": "normal", @@ -5861,6 +6011,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": undefined, "invoke": [], + "key": "a2", "metaEntries": [], "tags": [], "type": "normal", @@ -5877,6 +6028,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": "b1", "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -5893,6 +6045,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": undefined, "invoke": [], + "key": "b1", "metaEntries": [], "tags": [], "type": "normal", @@ -5909,6 +6062,7 @@ test('should extract transition with multiple targets as internal when any of it "history": undefined, "initial": undefined, "invoke": [], + "key": "b2", "metaEntries": [], "tags": [], "type": "normal", @@ -6009,6 +6163,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": undefined, "invoke": [], + "key": "(machine)", "metaEntries": [], "tags": [], "type": "parallel", @@ -6025,6 +6180,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": "a1", "invoke": [], + "key": "a", "metaEntries": [], "tags": [], "type": "normal", @@ -6041,6 +6197,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": undefined, "invoke": [], + "key": "a1", "metaEntries": [], "tags": [], "type": "normal", @@ -6057,6 +6214,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": undefined, "invoke": [], + "key": "a2", "metaEntries": [], "tags": [], "type": "normal", @@ -6073,6 +6231,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": "b1", "invoke": [], + "key": "b", "metaEntries": [], "tags": [], "type": "normal", @@ -6089,6 +6248,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": undefined, "invoke": [], + "key": "b1", "metaEntries": [], "tags": [], "type": "normal", @@ -6105,6 +6265,7 @@ test('should extract transition with multiple targets as not internal when none "history": undefined, "initial": undefined, "invoke": [], + "key": "b2", "metaEntries": [], "tags": [], "type": "normal", diff --git a/new-packages/ts-project/src/index.ts b/new-packages/ts-project/src/index.ts index 67b826df..686647a4 100644 --- a/new-packages/ts-project/src/index.ts +++ b/new-packages/ts-project/src/index.ts @@ -110,7 +110,10 @@ function extractMachineConfig( createMachineCall: CallExpression, ): readonly [ExtractorDigraphDef | undefined, ExtractionError[]] { const rootState = createMachineCall.arguments[0]; - const rootNode = extractState(ctx, ts, rootState, undefined); + const rootNode = extractState(ctx, ts, rootState, { + parentId: undefined, + key: '(machine)', // acts as a default that might be overriden by `rootState.id` + }); if (!rootNode) { return [undefined, ctx.errors]; diff --git a/new-packages/ts-project/src/state.ts b/new-packages/ts-project/src/state.ts index 92465a62..5851acdc 100644 --- a/new-packages/ts-project/src/state.ts +++ b/new-packages/ts-project/src/state.ts @@ -473,13 +473,14 @@ export function extractState( ctx: ExtractionContext, ts: typeof import('typescript'), state: Expression | undefined, - parentId: string | undefined, + { parentId, key }: { parentId: string | undefined; key: string }, ): TreeNode | undefined { const node: Node = { type: 'node', uniqueId: uniqueId(), parentId, data: { + key, initial: undefined, type: 'normal', history: undefined, @@ -515,11 +516,15 @@ export function extractState( return treeNode; } - forEachStaticProperty(ctx, ts, state, (prop, key) => { - switch (key) { + forEachStaticProperty(ctx, ts, state, (prop, propKey) => { + switch (propKey) { case 'id': { if (ts.isStringLiteralLike(prop.initializer)) { ctx.idMap[prop.initializer.text] = node.uniqueId; + + if (!node.parentId) { + node.data.key = prop.initializer.text; + } return; } return; @@ -610,12 +615,10 @@ export function extractState( if (ts.isPropertyAssignment(state)) { const childKey = getPropertyKey(ctx, ts, state); if (childKey) { - const childTreeNode = extractState( - ctx, - ts, - state.initializer, - node.uniqueId, - ); + const childTreeNode = extractState(ctx, ts, state.initializer, { + parentId: node.uniqueId, + key: childKey, + }); if (!childTreeNode) { continue; } @@ -724,7 +727,7 @@ export function extractState( return; } - registerActionBlocks(ctx, blocks, node.data[key]); + registerActionBlocks(ctx, blocks, node.data[propKey]); return; } case 'invoke': { @@ -813,7 +816,7 @@ export function extractState( } for (const block of blocks) { - node.data[key].push(block.uniqueId); + node.data[propKey].push(block.uniqueId); ctx.digraph.blocks[block.uniqueId] = block; ctx.digraph.implementations.actors[block.sourceId] ??= { type: 'actor', diff --git a/new-packages/ts-project/src/types.ts b/new-packages/ts-project/src/types.ts index 0dc7fdb3..b5a5cc8e 100644 --- a/new-packages/ts-project/src/types.ts +++ b/new-packages/ts-project/src/types.ts @@ -119,7 +119,7 @@ export type Node = { uniqueId: string; parentId: string | undefined; data: { - // key: string; + key: string; type: 'normal' | 'parallel' | 'final' | 'history'; history: 'shallow' | 'deep' | undefined; metaEntries: ExtractorMetaEntry[];