while-parser.js 667 B

12345678910111213141516171819202122
  1. /** 语句:while 循环(解析在此,执行在 sequence-runner);仅 body,不用 ture */
  2. const { assertStrictKeys } = require('../action-schema.js')
  3. const types = ['while']
  4. function parse (action, parseContext) {
  5. const path = parseContext.actionPath || 'while'
  6. assertStrictKeys(action, ['type', 'condition', 'body'], path)
  7. if (!Array.isArray(action.body)) {
  8. throw new Error(`${path}: while 须包含数组 body`)
  9. }
  10. return {
  11. type: 'while',
  12. condition: action.condition,
  13. body: parseContext.parseActions(action.body, 'body'),
  14. }
  15. }
  16. async function execute() {
  17. return { success: true }
  18. }
  19. module.exports = { types, parse, execute }