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

Commit

Permalink
Parse description field in StateNode
Browse files Browse the repository at this point in the history
  • Loading branch information
with-heart committed Feb 25, 2022
1 parent 957947d commit 47a1af0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
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

0 comments on commit 47a1af0

Please sign in to comment.