MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / stripJsComments

Function stripJsComments

src/resolution/import-resolver.ts:2609–2648  ·  view source on GitHub ↗

* Strip JS line + block comments from `content` while preserving * string literals (so `"//"` inside a string stays intact). A block * comment becomes one space, so the tokens either side stay apart. Used by * extractReExports over a whole file, so commented-out export-from * statements

(content: string)

Source from the content-addressed store, hash-verified

2607 * apply this to function bodies, only to top-level files and import lists).
2608 */
2609function stripJsComments(content: string): string {
2610 let out = '';
2611 let i = 0;
2612 let str: '"' | "'" | '`' | null = null;
2613 while (i < content.length) {
2614 const ch = content[i]!;
2615 if (str !== null) {
2616 out += ch;
2617 if (ch === '\\' && i + 1 < content.length) {
2618 out += content[i + 1]!;
2619 i += 2;
2620 continue;
2621 }
2622 if (ch === str) str = null;
2623 i++;
2624 continue;
2625 }
2626 if (ch === '"' || ch === "'" || ch === '`') {
2627 str = ch;
2628 out += ch;
2629 i++;
2630 continue;
2631 }
2632 if (ch === '/' && content[i + 1] === '/') {
2633 while (i < content.length && content[i] !== '\n') i++;
2634 continue;
2635 }
2636 if (ch === '/' && content[i + 1] === '*') {
2637 i += 2;
2638 while (i < content.length && !(content[i] === '*' && content[i + 1] === '/')) i++;
2639 i += 2;
2640 // A space, not nothing: `A/**/as B` must stay two words.
2641 out += ' ';
2642 continue;
2643 }
2644 out += ch;
2645 i++;
2646 }
2647 return out;
2648}
2649
2650/**
2651 * Extract JS/TS re-export declarations from `content`.

Callers 2

cleanSpecifierListFunction · 0.85
extractReExportsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected