(source)
| 530 | } |
| 531 | |
| 532 | function findIfBlocks(source) { |
| 533 | const blocks = [] |
| 534 | const regex = /\bif\s*\(/g |
| 535 | let match |
| 536 | while ((match = regex.exec(source)) !== null) { |
| 537 | const parenStart = source.indexOf('(', match.index) |
| 538 | const parenEnd = findMatchingDelimiter(source, parenStart, '(', ')') |
| 539 | const braceStart = source.indexOf('{', parenEnd) |
| 540 | if (braceStart === -1) continue |
| 541 | const bodySource = extractBalancedSegment(source, braceStart, '{', '}') |
| 542 | blocks.push({ |
| 543 | gate: source.slice(parenStart + 1, parenEnd).replace(/\s+/g, ' ').trim(), |
| 544 | start: match.index, |
| 545 | end: braceStart + bodySource.length, |
| 546 | body: bodySource.slice(1, -1), |
| 547 | }) |
| 548 | regex.lastIndex = braceStart + bodySource.length |
| 549 | } |
| 550 | return blocks |
| 551 | } |
| 552 | |
| 553 | function stripRanges(source, ranges) { |
| 554 | if (ranges.length === 0) return source |
no test coverage detected