Skip to content

Commit

Permalink
fix(invoke-usage): allow function calls as valid invoke.src values
Browse files Browse the repository at this point in the history
fix #7
  • Loading branch information
rlaffers committed Aug 16, 2021
1 parent b01ca68 commit ac27f4b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/rules/invoke-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const {
isStringLiteralOrIdentifier,
isFunctionExpression,
isCreateMachineCall,
isCallExpression,
} = require('../utils/predicates')

module.exports = {
Expand All @@ -24,7 +25,7 @@ module.exports = {
'The value of the "invoke" property must be an object with a "src" property.',
invokeObjectLacksSrc: 'The "invoke" object must have a "src" property.',
srcPropertyIsInvalid:
'The value of the "src" property in the "invoke" object must be a machine, function, string or an object.',
'The value of the "src" property in the "invoke" object must be a machine, function, string, object, or a function call.',
},
},

Expand Down Expand Up @@ -59,6 +60,7 @@ module.exports = {
if (
!isStringLiteralOrIdentifier(src.value) &&
!isFunctionExpression(src.value) &&
!isCallExpression(src.value) &&
src.value.type !== 'ObjectExpression' &&
!isCreateMachineCall(src.value)
) {
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/invoke-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ const tests = {
},
})
`,
`
createMachine({
initial: 'active',
states: {
active: {
invoke: {
src: someMachineCreator(),
},
},
},
})
`,
`
createMachine({
initial: 'active',
Expand Down

0 comments on commit ac27f4b

Please sign in to comment.