| 28 | } |
| 29 | |
| 30 | function collectErrors(expr: MathJsonExpression): ErrorExpressionObject[] { |
| 31 | const result: ErrorExpressionObject[] = []; |
| 32 | |
| 33 | function visit(x: MathJsonExpression): void { |
| 34 | if (Array.isArray(x)) { |
| 35 | if (x[0] === 'Error') |
| 36 | result.push({ fn: x as ErrorExpressionObject['fn'] }); |
| 37 | for (const child of x.slice(1)) visit(child); |
| 38 | return; |
| 39 | } |
| 40 | |
| 41 | if (x && typeof x === 'object' && 'fn' in x) { |
| 42 | if (x.fn[0] === 'Error') result.push(x as ErrorExpressionObject); |
| 43 | for (const child of x.fn.slice(1)) visit(child); |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | visit(expr); |
| 48 | return result; |
| 49 | } |
| 50 | |
| 51 | function findError( |
| 52 | expr: MathJsonExpression, |