| 1234567891011121314151617181920212223242526 |
- /** 语句:if 条件判断(解析在此,执行在 sequence-runner);须同时含 then、else 数组(可无分支写 []) */
- const { assertStrictKeys } = require('../action-schema.js')
- const types = ['if']
- function parse (action, parseContext) {
- const path = parseContext.actionPath || 'if'
- assertStrictKeys(action, ['type', 'condition', 'then', 'else'], path)
- if (!Array.isArray(action.then)) {
- throw new Error(`${path}: if 须包含数组 then`)
- }
- if (!Array.isArray(action.else)) {
- throw new Error(`${path}: if 须包含数组 else(无 else 分支写 [])`)
- }
- return {
- type: 'if',
- condition: action.condition,
- then: parseContext.parseActions(action.then, 'then'),
- else: parseContext.parseActions(action.else, 'else'),
- }
- }
- async function execute() {
- return { success: true }
- }
- module.exports = { types, parse, execute }
|