* Compile a node into a JavaScript function. * This basically pre-calculates as much as possible and only leaves open * calculations which depend on a dynamic scope with variables. * @param {Object} math Math.js namespace with functions and constants. * @param {Object} argNam
(math, argNames)
| 56 | * evalNode(scope: Object, args: Object, context: *) |
| 57 | */ |
| 58 | _compile (math, argNames) { |
| 59 | const evalBlocks = map(this.blocks, function (block) { |
| 60 | return { |
| 61 | evaluate: block.node._compile(math, argNames), |
| 62 | visible: block.visible |
| 63 | } |
| 64 | }) |
| 65 | |
| 66 | return function evalBlockNodes (scope, args, context) { |
| 67 | const results = [] |
| 68 | |
| 69 | forEach(evalBlocks, function evalBlockNode (block) { |
| 70 | const result = block.evaluate(scope, args, context) |
| 71 | if (block.visible) { |
| 72 | results.push(result) |
| 73 | } |
| 74 | }) |
| 75 | |
| 76 | return new ResultSet(results) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * Execute a callback for each of the child blocks of this node |