(n, ctx)
| 191 | } |
| 192 | |
| 193 | static ConvertForStatement (n, ctx) { |
| 194 | const found = findOne(ctx.plan, x => fuzzyMatch(n, x[1]), 'Can\'t find the for statement') |
| 195 | convert(n.init, { ...ctx, nospace: true }) |
| 196 | const body = convert(n.body, { ...ctx, nospace: true, context: 'statement' }) |
| 197 | |
| 198 | // Only handles most basic cases for now, like standard for (let i = 0; i < 3; i++) |
| 199 | const start = n.init?.declarations?.[0]?.init?.value ?? 0 |
| 200 | const end = n.test?.right?.value ?? 1 |
| 201 | const times = end - start |
| 202 | // For Junior, we have simplified dropdown block if the range is in 1-7 |
| 203 | const type = times >= 1 && times <= 7 && _.find(ctx.plan, p => p[0].type === 'controls_repeat_dropdown') ? 'controls_repeat_dropdown' : found[0].type |
| 204 | let o |
| 205 | if (type === 'controls_repeat_dropdown') { |
| 206 | // Change input to field |
| 207 | o = { type, inputs: {}, fields: { TIMES: '' + times } } |
| 208 | } else { |
| 209 | // TODO: figure out how to always include controls_repeat_ext so that we can handle if the number is outside our target range |
| 210 | o = { type, inputs: { TIMES: { block: convert(n.test.right, ctx) } } } |
| 211 | } |
| 212 | |
| 213 | if (body) o.inputs.DO = { block: body[0] } |
| 214 | return o |
| 215 | } |
| 216 | |
| 217 | static ConvertForOfStatement (n, ctx) { |
| 218 | ctx.scope[n.left.name] = { type: 'var' } |
nothing calls this directly
no test coverage detected