Skip to content

Commit

Permalink
Include machine options in extracted machine config
Browse files Browse the repository at this point in the history
  • Loading branch information
farskid committed Nov 16, 2023
1 parent 28f278a commit 57722ae
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
23 changes: 15 additions & 8 deletions packages/machine-extractor/src/MachineExtractResult.ts
Original file line number Diff line number Diff line change
Expand Up @@ -725,18 +725,25 @@ export class MachineExtractResult {
Record<string, string>
> = { actions: {}, actors: {}, guards: {}, delays: {} } as const;

const foundKeyToOutKey: Record<string, keyof typeof out> = {
actions: 'actions',
actors: 'actors',
services: 'actors',
guards: 'guards',
delays: 'delays',
};

for (const key in this.machineCallResult.options) {
const _key =
key === 'actors'
? 'services'
: (key as 'actions' | 'services' | 'guards' | 'delays');
const valueNode = this.machineCallResult.options[_key];
const valueNode = this.machineCallResult.options[key as keyof typeof out];
if (valueNode && t.isObjectExpression(valueNode.node)) {
valueNode.node.properties.forEach((prop) => {
if (t.isObjectProperty(prop)) {
out[_key === 'services' ? 'actors' : _key][
getObjectPropertyKey(prop)
] = this._fileContent.slice(prop.value.start!, prop.value.end!);
const propKey = getObjectPropertyKey(prop);
const val = this._fileContent.slice(
prop.value.start!,
prop.value.end!,
);
out[foundKeyToOutKey[key]][propKey] = val;
}
});
}
Expand Down
1 change: 1 addition & 0 deletions packages/machine-extractor/src/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const MachineOptionsObject = objectTypeWithKnownKeys({
unionType<ActionNode | { node: t.Node }>([ChooseAction, AnyNode]),
),
services: objectOf(AnyNode),
actors: objectOf(AnyNode),
guards: objectOf(AnyNode),
delays: objectOf(AnyNode),
devTools: BooleanLiteral,
Expand Down

0 comments on commit 57722ae

Please sign in to comment.