A loop's header as written, keyword and braces dropped: `item of items`, `queue.length > 0`.
(loop: SyntaxNode)
| 1045 | |
| 1046 | /** A loop's header as written, keyword and braces dropped: `item of items`, `queue.length > 0`. */ |
| 1047 | function loopHeader(loop: SyntaxNode): string { |
| 1048 | const body = loop.childForFieldName('body') ?? namedChildren(loop).find((c) => BLOCKISH.has(c.type)) ?? null; |
| 1049 | const raw = body && body.startIndex > loop.startIndex ? loop.text.slice(0, body.startIndex - loop.startIndex) : loop.text; |
| 1050 | let text = raw.replace(/\s+/g, ' ').trim(); |
| 1051 | text = text.replace(/^(?:for|foreach|while|do|repeat)\b\s*/i, ''); |
| 1052 | text = text.replace(/[{:]\s*$/, '').trim(); |
| 1053 | const inner = /^\((.*)\)$/s.exec(text); |
| 1054 | if (inner) text = inner[1]!.trim(); |
| 1055 | // `const item of items` reads as `item of items`; the binding word is noise here. |
| 1056 | text = text.replace(/^(?:const|let|var|val|final)\s+/, ''); |
| 1057 | return cut(text, 60); |
| 1058 | } |
| 1059 | |
| 1060 | /** |
| 1061 | * The walk. `line` is 1-based, `column` 0-based (null → first non-blank). |
no test coverage detected