* Processes `FunctionDeclaration` and `FunctionExpression` instances. * These are the only structures which may contain contracts. * * @param {Object} ast The AST to process. * @param {Object} options The options for the processor. * @return {Array} The processed AST and the numb
(ast, options)
| 104 | * @return {Array} The processed AST and the number of functions that contain contracts. |
| 105 | */ |
| 106 | function processFunctions(ast, options) { |
| 107 | OBLIGATIONS.precondition(ast && typeof ast === 'object'); |
| 108 | var __result; |
| 109 | var total = 0; |
| 110 | estraverse.replace(ast, { |
| 111 | enter: function (node) { |
| 112 | var result; |
| 113 | if (node.type === 'FunctionDeclaration' || node.type === 'FunctionExpression') { |
| 114 | result = collectLabels(node, options); |
| 115 | if (result[1].length) { |
| 116 | total++; |
| 117 | return cleanup(result[0]); |
| 118 | } else { |
| 119 | return result[0]; |
| 120 | } |
| 121 | } |
| 122 | } |
| 123 | }); |
| 124 | __result = [ |
| 125 | ast, |
| 126 | total |
| 127 | ]; |
| 128 | OBLIGATIONS.postcondition(Array.isArray(__result)); |
| 129 | OBLIGATIONS.postcondition(__result[0] && typeof __result[0] === 'object'); |
| 130 | return __result; |
| 131 | } |
| 132 | /** |
| 133 | * Collects all the `LabeledStatement` instances in the tree which |
| 134 | * have labels that match our supported contract types. |
no test coverage detected