* 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)
| 2853 | * apply this to function bodies, only to top-level files and import lists). |
| 2854 | */ |
| 2855 | function 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`. |
no outgoing calls
no test coverage detected