(compiled: string)
| 177 | } |
| 178 | |
| 179 | function splitExportBlocks(compiled: string): string[] { |
| 180 | const normalizedCompiled = compiled |
| 181 | .trim() |
| 182 | .replace(/;(export\s+(?:interface|type)\s+)/g, ";\n$1") |
| 183 | .replace(/}(export\s+(?:interface|type)\s+)/g, "}\n$1"); |
| 184 | const lines = normalizedCompiled.split(/\r?\n/); |
| 185 | const blocks: string[] = []; |
| 186 | let pending: string[] = []; |
| 187 | |
| 188 | for (let index = 0; index < lines.length;) { |
| 189 | const line = lines[index]; |
| 190 | if (!/^export\s+(?:interface|type)\s+\w+/.test(line)) { |
| 191 | pending.push(line); |
| 192 | index++; |
| 193 | continue; |
| 194 | } |
| 195 | |
| 196 | const blockLines = [...pending, line]; |
| 197 | pending = []; |
| 198 | let braceDepth = countBraces(line); |
| 199 | index++; |
| 200 | |
| 201 | if (braceDepth === 0 && line.trim().endsWith(";")) { |
| 202 | blocks.push(blockLines.join("\n").trim()); |
| 203 | continue; |
| 204 | } |
| 205 | |
| 206 | while (index < lines.length) { |
| 207 | const nextLine = lines[index]; |
| 208 | blockLines.push(nextLine); |
| 209 | braceDepth += countBraces(nextLine); |
| 210 | index++; |
| 211 | |
| 212 | const trimmed = nextLine.trim(); |
| 213 | if (braceDepth === 0 && (trimmed === "}" || trimmed.endsWith(";"))) { |
| 214 | break; |
| 215 | } |
| 216 | } |
| 217 | |
| 218 | blocks.push(blockLines.join("\n").trim()); |
| 219 | } |
| 220 | |
| 221 | return blocks; |
| 222 | } |
| 223 | |
| 224 | function countBraces(line: string): number { |
| 225 | let depth = 0; |
no test coverage detected
searching dependent graphs…