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

Function stripJsComments

src/resolution/import-resolver.ts:2855–2894  ·  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

2853 * apply this to function bodies, only to top-level files and import lists).
2854 */
2855function stripJsComments(content: string): string {
2856 let out = '';
2857 let i = 0;
2858 let str: '"' | "'" | '`' | null = null;
2859 while (i < content.length) {
2860 const ch = content[i]!;
2861 if (str !== null) {
2862 out += ch;
2863 if (ch === '\\' && i + 1 < content.length) {
2864 out += content[i + 1]!;
2865 i += 2;
2866 continue;
2867 }
2868 if (ch === str) str = null;
2869 i++;
2870 continue;
2871 }
2872 if (ch === '"' || ch === "'" || ch === '`') {
2873 str = ch;
2874 out += ch;
2875 i++;
2876 continue;
2877 }
2878 if (ch === '/' && content[i + 1] === '/') {
2879 while (i < content.length && content[i] !== '\n') i++;
2880 continue;
2881 }
2882 if (ch === '/' && content[i + 1] === '*') {
2883 i += 2;
2884 while (i < content.length && !(content[i] === '*' && content[i + 1] === '/')) i++;
2885 i += 2;
2886 // A space, not nothing: `A/**/as B` must stay two words.
2887 out += ' ';
2888 continue;
2889 }
2890 out += ch;
2891 i++;
2892 }
2893 return out;
2894}
2895
2896/**
2897 * 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