MCPcopy Create free account
hub / github.com/codemix/contractual / collectLabels

Function collectLabels

lib/processor.js:144–165  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

142 * @return {Array} The processed AST and an array containing any collected, supported labels.
143 */
144function 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 *

Callers 1

processFunctionsFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected