* Whether a routine nested in another is declared `forward` above a line * (`procedure Late; forward;`), which puts it in scope there ahead of its * body (#2550): a header of its name, as indented as its own, that ends in * `forward;`, between the line and the header indented less above it, the
(routine: Node, line: number, context: ResolutionContext)
| 392 | * routine both are nested in. |
| 393 | */ |
| 394 | function declaredForward(routine: Node, line: number, context: ResolutionContext): boolean { |
| 395 | const lines = fileLines(routine.filePath, context); |
| 396 | const name = routine.name.toLowerCase(); |
| 397 | for (let i = Math.min(line, lines.length) - 1; i >= 0; i--) { |
| 398 | const m = /^(\s*)(?:class\s+)?(?:procedure|function|constructor|destructor)\s+([A-Za-z_]\w*)/i.exec(lines[i]!); |
| 399 | if (!m) continue; |
| 400 | if (m[1]!.length < routine.startColumn) return false; |
| 401 | if (m[1]!.length !== routine.startColumn || m[2]!.toLowerCase() !== name) continue; |
| 402 | // Its parameters may go on over a few lines. |
| 403 | let text = lines[i]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' '); |
| 404 | for (let j = i + 1; j < lines.length && j <= i + 4 && (text.split('(').length > text.split(')').length); j++) { |
| 405 | text += ' ' + lines[j]!.replace(/\/\/.*$|\{[^}]*\}|\(\*.*?\*\)/g, ' '); |
| 406 | } |
| 407 | if (/\bforward\s*;/i.test(text)) return true; |
| 408 | } |
| 409 | return false; |
| 410 | } |
| 411 | |
| 412 | /** |
| 413 | * Whether a node is a routine nested in another (see nestedRoutineInScope): |
no test coverage detected