* Collects all the `LabeledStatement` instances in the tree which * have labels that match our supported contract types. * * Nodes that follow a label are then added to a new temporary `BlockStatement` * which forms the body of the label. * * * @param {Object} ast The AST to process. *
(ast, options)
| 142 | * @return {Array} The processed AST and an array containing any collected, supported labels. |
| 143 | */ |
| 144 | function collectLabels(ast, options) { |
| 145 | OBLIGATIONS.precondition(ast && typeof ast === 'object'); |
| 146 | OBLIGATIONS.precondition(ast.type === 'FunctionDeclaration' || ast.type === 'FunctionExpression'); |
| 147 | OBLIGATIONS.precondition(options && typeof options === 'object'); |
| 148 | var __result; |
| 149 | var state = { |
| 150 | ast: ast, |
| 151 | inLabel: false, |
| 152 | parent: null, |
| 153 | labels: [] |
| 154 | }; |
| 155 | estraverse.replace(ast, { |
| 156 | enter: enterCollect.bind(null, options, state), |
| 157 | leave: leaveCollect.bind(null, options, state) |
| 158 | }); |
| 159 | __result = [ |
| 160 | ast, |
| 161 | state.labels |
| 162 | ]; |
| 163 | OBLIGATIONS.postcondition(Array.isArray(__result)); |
| 164 | return __result; |
| 165 | } |
| 166 | /** |
| 167 | * Invoked when `estraverse` enters a node during the collection phase. |
| 168 | * |