(content: string)
| 108 | * Parse a file's lines into LineRecord objects with indentation information. |
| 109 | */ |
| 110 | export function parseLines(content: string): LineRecord[] { |
| 111 | const lines = content.split("\n") |
| 112 | return lines.map((line, index) => { |
| 113 | const trimmed = line.trimStart() |
| 114 | const leadingWhitespace = line.length - trimmed.length |
| 115 | |
| 116 | // Calculate indent in spaces (tabs = TAB_WIDTH spaces each) |
| 117 | let indentSpaces = 0 |
| 118 | for (let i = 0; i < leadingWhitespace; i++) { |
| 119 | if (line[i] === "\t") { |
| 120 | indentSpaces += TAB_WIDTH |
| 121 | } else { |
| 122 | indentSpaces += 1 |
| 123 | } |
| 124 | } |
| 125 | // Convert to indent level (number of INDENT_SIZE units) |
| 126 | const indentLevel = Math.floor(indentSpaces / INDENT_SIZE) |
| 127 | |
| 128 | const isBlank = trimmed.length === 0 |
| 129 | const isBlockStart = !isBlank && BLOCK_START_PATTERNS.some((pattern) => pattern.test(line)) |
| 130 | |
| 131 | return { |
| 132 | lineNumber: index + 1, |
| 133 | content: line, |
| 134 | indentLevel, |
| 135 | isBlank, |
| 136 | isBlockStart, |
| 137 | } |
| 138 | }) |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Compute effective indents where blank lines inherit the previous non-blank line's indent. |
no outgoing calls
no test coverage detected