Remove comments (but NOT string contents) so comment-only differences don't block alignment. PURE.
(body: string)
| 198 | |
| 199 | /** Remove comments (but NOT string contents) so comment-only differences don't block alignment. PURE. */ |
| 200 | function stripComments(body: string): string { |
| 201 | // Walk once, honoring string/template literals so a "//" inside a string survives. |
| 202 | let out = ''; |
| 203 | let i = 0; |
| 204 | while (i < body.length) { |
| 205 | const ch = body[i]!; |
| 206 | if (ch === '"' || ch === "'" || ch === '`') { |
| 207 | const quote = ch; out += ch; i++; |
| 208 | while (i < body.length && body[i] !== quote) { if (body[i] === '\\') { out += body[i]! + (body[i + 1] ?? ''); i += 2; continue; } out += body[i]!; i++; } |
| 209 | out += body[i] ?? ''; i++; |
| 210 | continue; |
| 211 | } |
| 212 | if (ch === '/' && body[i + 1] === '/') { while (i < body.length && body[i] !== '\n') i++; continue; } |
| 213 | if (ch === '/' && body[i + 1] === '*') { i += 2; while (i < body.length && !(body[i] === '*' && body[i + 1] === '/')) i++; i += 2; continue; } |
| 214 | out += ch; i++; |
| 215 | } |
| 216 | return out; |
| 217 | } |
| 218 | |
| 219 | /** Code tokens WITH literals kept and source offsets (for substitution in the sketch). PURE. */ |
| 220 | function rawTokens(body: string): RawTok[] { |
no outgoing calls
no test coverage detected