`src` with the ranges (start and end pairs, in order) turned to spaces, line breaks kept.
(src: string, blanks: number[])
| 108 | |
| 109 | /** `src` with the ranges (start and end pairs, in order) turned to spaces, line breaks kept. */ |
| 110 | function blankRanges(src: string, blanks: number[]): string { |
| 111 | if (blanks.length === 0) return src; |
| 112 | const parts: string[] = []; |
| 113 | let from = 0; |
| 114 | for (let b = 0; b < blanks.length; b += 2) { |
| 115 | const start = blanks[b]!; |
| 116 | const end = blanks[b + 1]!; |
| 117 | if (start < from) continue; |
| 118 | parts.push(src.slice(from, start)); |
| 119 | const text = src.slice(start, end); |
| 120 | parts.push(/[\r\n]/.test(text) ? text.replace(/[^\r\n]/g, ' ') : ' '.repeat(end - start)); |
| 121 | from = end; |
| 122 | } |
| 123 | parts.push(src.slice(from)); |
| 124 | return parts.join(''); |
| 125 | } |
| 126 | |
| 127 | export function jsxCode(src: string): string | null { |
| 128 | return new JsxLexer(src).read(); |