MCPcopy
hub / github.com/lebab/lebab / validateForLoop

Function validateForLoop

src/transform/forEach/validateForLoop.js:14–37  ·  view source on GitHub ↗
(node, {body, indexKind, itemKind})

Source from the content-addressed store, hash-verified

12 * @return {Array} Array of node and warnings message or undefined on success.
13 */
14export default function validateForLoop(node, {body, indexKind, itemKind}) {
15 let statement;
16 if ((statement = returnUsed(body))) {
17 return [statement, 'Return statement used in for-loop body'];
18 }
19 else if ((statement = breakWithLabelUsed(body))) {
20 return [statement, 'Break statement with label used in for-loop body'];
21 }
22 else if ((statement = continueWithLabelUsed(body))) {
23 return [statement, 'Continue statement with label used in for-loop body'];
24 }
25 else if ((statement = breakUsed(body))) {
26 return [statement, 'Break statement used in for-loop body'];
27 }
28 else if ((statement = continueUsed(body))) {
29 return [statement, 'Continue statement used in for-loop body'];
30 }
31 else if (indexKind !== 'let') {
32 return [node, 'Only for-loops with indexes declared as let can be transformed (use let transform first)'];
33 }
34 else if (itemKind !== 'const') {
35 return [node, 'Only for-loops with const array items can be transformed (use let transform first)'];
36 }
37}
38
39const loopStatements = ['ForStatement', 'ForInStatement', 'ForOfStatement', 'DoWhileStatement', 'WhileStatement'];
40

Callers 1

enterFunction · 0.85

Calls 5

returnUsedFunction · 0.85
breakWithLabelUsedFunction · 0.85
continueWithLabelUsedFunction · 0.85
breakUsedFunction · 0.85
continueUsedFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…