Skip to content

Commit

Permalink
Fix bug in extracting history
Browse files Browse the repository at this point in the history
  • Loading branch information
farskid committed Jan 11, 2024
1 parent 419c047 commit c14e72f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 116 deletions.
117 changes: 4 additions & 113 deletions new-packages/ts-project/__tests__/state.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ test('should extract states recursively', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -53,7 +52,6 @@ test('should extract states recursively', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -68,7 +66,6 @@ test('should extract states recursively', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -83,7 +80,6 @@ test('should extract states recursively', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -103,7 +99,6 @@ test('should extract states recursively', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -151,7 +146,6 @@ test('Should extract state.initial with string value', async () => {
"history": undefined,
"initial": "foo",
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -166,7 +160,6 @@ test('Should extract state.initial with string value', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -212,7 +205,6 @@ test('Should extract state.initial with undefined value', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -256,7 +248,6 @@ test('Should raise error when state.initial property has invalid value', async (
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -346,7 +337,6 @@ test('Should extract state.type with value "parallel"', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": "parallel",
Expand Down Expand Up @@ -389,7 +379,6 @@ test('Should extract state.type with value "final"', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": "final",
Expand Down Expand Up @@ -433,7 +422,6 @@ test('Should extract state.type with value "history"', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": "history",
Expand Down Expand Up @@ -476,7 +464,6 @@ test('Should extract state.type with value undefined', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -519,7 +506,6 @@ test('Should raise error when state.type has invalid value', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down Expand Up @@ -605,10 +591,9 @@ test('Should extract state.history with value "shallow"', async () => {
"description": undefined,
"entry": [],
"exit": [],
"history": undefined,
"history": "shallow",
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -618,53 +603,7 @@ test('Should extract state.history with value "shallow"', async () => {
},
"states": [],
},
[
{
"node": NodeObject {
"end": 76,
"exclamationToken": undefined,
"flags": 0,
"initializer": NodeObject {
"end": 76,
"flags": 0,
"hasExtendedUnicodeEscape": false,
"kind": 11,
"localSymbol": undefined,
"modifierFlagsCache": 0,
"parent": undefined,
"pos": 66,
"singleQuote": undefined,
"symbol": undefined,
"text": "shallow",
"transformFlags": 0,
},
"jsDoc": undefined,
"kind": 303,
"localSymbol": undefined,
"modifierFlagsCache": 0,
"modifiers": undefined,
"name": IdentifierObject {
"end": 65,
"escapedText": "history",
"flags": 0,
"flowNode": undefined,
"jsDoc": undefined,
"kind": 80,
"modifierFlagsCache": 0,
"parent": undefined,
"pos": 56,
"symbol": undefined,
"transformFlags": 0,
},
"parent": undefined,
"pos": 56,
"questionToken": undefined,
"symbol": undefined,
"transformFlags": 0,
},
"type": "state_property_unhandled",
},
],
[],
],
]
`);
Expand Down Expand Up @@ -694,10 +633,9 @@ test('Should extract state.history with value "deep"', async () => {
"description": undefined,
"entry": [],
"exit": [],
"history": undefined,
"history": "deep",
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand All @@ -707,53 +645,7 @@ test('Should extract state.history with value "deep"', async () => {
},
"states": [],
},
[
{
"node": NodeObject {
"end": 73,
"exclamationToken": undefined,
"flags": 0,
"initializer": NodeObject {
"end": 73,
"flags": 0,
"hasExtendedUnicodeEscape": false,
"kind": 11,
"localSymbol": undefined,
"modifierFlagsCache": 0,
"parent": undefined,
"pos": 66,
"singleQuote": undefined,
"symbol": undefined,
"text": "deep",
"transformFlags": 0,
},
"jsDoc": undefined,
"kind": 303,
"localSymbol": undefined,
"modifierFlagsCache": 0,
"modifiers": undefined,
"name": IdentifierObject {
"end": 65,
"escapedText": "history",
"flags": 0,
"flowNode": undefined,
"jsDoc": undefined,
"kind": 80,
"modifierFlagsCache": 0,
"parent": undefined,
"pos": 56,
"symbol": undefined,
"transformFlags": 0,
},
"parent": undefined,
"pos": 56,
"questionToken": undefined,
"symbol": undefined,
"transformFlags": 0,
},
"type": "state_property_unhandled",
},
],
[],
],
]
`);
Expand Down Expand Up @@ -787,7 +679,6 @@ test('Should extract state.history with value undefined', async () => {
"history": undefined,
"initial": undefined,
"invoke": [],
"key": "",
"metaEntries": [],
"tags": [],
"type": undefined,
Expand Down
4 changes: 1 addition & 3 deletions new-packages/ts-project/src/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,7 @@ export function extractState(
case 'history': {
const isStringWithValidValue =
ts.isStringLiteral(prop.initializer) &&
['history', 'atomic', 'compound', 'parallel', 'final'].includes(
prop.initializer.text,
);
['shallow', 'deep'].includes(prop.initializer.text);

if (isStringWithValidValue) {
result.data[key] = prop.initializer
Expand Down

0 comments on commit c14e72f

Please sign in to comment.