Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Parse description field in StateNode #18

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/description.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { createMachine } from "xstate";

export const descriptionMachine = createMachine({
initial: "wow",
description: "hello!",
states: {
wow: {
description: "WOWZA!",
},
},
});
2 changes: 2 additions & 0 deletions src/stateNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export type StateNodeReturn = {
states?: GetParserResult<AnyParser<ObjectOfReturn<StateNodeReturn>>>;
node: t.Node;
meta?: GetParserResult<typeof StateMeta>;
description?: GetParserResult<typeof StringLiteral>;
tsTypes?: GetParserResult<typeof TsTypes>;
context?: GetParserResult<typeof Context>;
data?: GetParserResult<typeof AnyNode>;
Expand Down Expand Up @@ -81,6 +82,7 @@ const StateNodeObject: AnyParser<StateNodeReturn> = objectTypeWithKnownKeys(
context: Context,
data: AnyNode,
preserveActionOrder: BooleanLiteral,
description: StringLiteral,
}),
);

Expand Down
4 changes: 4 additions & 0 deletions src/toMachineConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ const parseStateNode = (
};
}

if (astResult.description) {
config.description = astResult.description.value;
}

if (astResult.onDone) {
// @ts-ignore
config.onDone = getTransitions(astResult.onDone);
Expand Down