* Strip JS line + block comments from `content` while preserving * string literals (so `"//"` inside a string stays intact). Used by * extractReExports so commented-out export-from statements * don't generate phantom re-export edges. * * Scanner is deliberately small: it only tracks the
(content: string)
| 1118 | * apply this to function bodies, only to top-level files). |
| 1119 | */ |
| 1120 | function stripJsComments(content: string): string { |
| 1121 | let out = ''; |
| 1122 | let i = 0; |
| 1123 | let str: '"' | "'" | '`' | null = null; |
| 1124 | while (i < content.length) { |
| 1125 | const ch = content[i]!; |
| 1126 | if (str !== null) { |
| 1127 | out += ch; |
| 1128 | if (ch === '\\' && i + 1 < content.length) { |
| 1129 | out += content[i + 1]!; |
| 1130 | i += 2; |
| 1131 | continue; |
| 1132 | } |
| 1133 | if (ch === str) str = null; |
| 1134 | i++; |
| 1135 | continue; |
| 1136 | } |
| 1137 | if (ch === '"' || ch === "'" || ch === '`') { |
| 1138 | str = ch; |
| 1139 | out += ch; |
| 1140 | i++; |
| 1141 | continue; |
| 1142 | } |
| 1143 | if (ch === '/' && content[i + 1] === '/') { |
| 1144 | while (i < content.length && content[i] !== '\n') i++; |
| 1145 | continue; |
| 1146 | } |
| 1147 | if (ch === '/' && content[i + 1] === '*') { |
| 1148 | i += 2; |
| 1149 | while (i < content.length && !(content[i] === '*' && content[i + 1] === '/')) i++; |
| 1150 | i += 2; |
| 1151 | continue; |
| 1152 | } |
| 1153 | out += ch; |
| 1154 | i++; |
| 1155 | } |
| 1156 | return out; |
| 1157 | } |
| 1158 | |
| 1159 | /** |
| 1160 | * Extract JS/TS re-export declarations from `content`. |