MCPcopy Create free account
hub / github.com/QodeXcli/QodeX / stripComments

Function stripComments

src/codegraph/helper-extract.ts:200–217  ·  view source on GitHub ↗

Remove comments (but NOT string contents) so comment-only differences don't block alignment. PURE.

(body: string)

Source from the content-addressed store, hash-verified

198
199/** Remove comments (but NOT string contents) so comment-only differences don't block alignment. PURE. */
200function 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. */
220function rawTokens(body: string): RawTok[] {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected