/** 语句:for 循环(解析在此,执行在 sequence-runner) */ const { assertStrictKeys } = require('../action-schema.js') const types = ['for'] function parse (action, parseContext) { const path = parseContext.actionPath || 'for' assertStrictKeys(action, ['type', 'variable', 'indexVariable', 'times', 'array', 'body'], path) if (!Array.isArray(action.body)) { throw new Error(`${path}: for 须包含数组 body`) } const hasTimes = action.times != null && action.times !== '' const hasArray = action.array != null && action.array !== '' if (hasTimes === hasArray) { throw new Error(`${path}: for 须二选一:填写 times+variable,或填写 array+indexVariable+variable`) } if (hasTimes && (action.variable === undefined || action.variable === null || action.variable === '')) { throw new Error(`${path}: for 使用 times 时须提供 variable`) } if (hasArray) { if (!action.indexVariable) { throw new Error(`${path}: for 使用 array 时须提供 indexVariable`) } } return { type: 'for', variable: action.variable, indexVariable: action.indexVariable, times: hasTimes ? action.times : null, array: hasArray ? action.array : null, body: parseContext.parseActions(action.body, 'body'), } } async function execute() { return { success: true } } module.exports = { types, parse, execute }