(segments: Iterable<string>)
| 427 | const parts = str.split(/(\r?\n)/); |
| 428 | let stream = ''; |
| 429 | let sep = ''; |
| 430 | // Offset of the start of the current line in the original string. Advanced |
| 431 | // by the line length plus the actual separator length. Used only to report |
| 432 | // the original-input span of discarded comments (code `comment-discarded`). |
| 433 | let lineOffset = 0; |
| 434 | for (let i = 0; i < parts.length; i += 2) { |
| 435 | const line = parts[i]; |
| 436 | const separator = parts[i + 1] ?? ''; |
| 437 | stream += sep; |
| 438 | sep = ' '; |
| 439 | // Remove everything after a % (comment marker) |
| 440 | // (but \% should be preserved...) |
| 441 | const m = line.match(/((?:\\%)|[^%])*/); |
| 442 | if (m !== null) { |
| 443 | stream += m[0]; |
| 444 | // An unescaped `%` was found iff the match is shorter than the line: the |
| 445 | // discarded run is `%` through end-of-line, in original-input coordinates. |
| 446 | if (comments !== undefined && m[0].length < line.length) { |
| 447 | const start = lineOffset + m[0].length; |
| 448 | const end = lineOffset + line.length; |
| 449 | comments.push({ |
no test coverage detected