(text: string)
| 29 | * must conservatively inspect those expressions in the original source. |
| 30 | */ |
| 31 | export function blankStringContents(text: string): string { |
| 32 | const out = text.split(''); |
| 33 | let i = 0; |
| 34 | const n = text.length; |
| 35 | while (i < n) { |
| 36 | const c = text[i]!; |
| 37 | // A quote inside a JS regex is data, not the beginning of a string. |
| 38 | // Expression-start punctuation and keywords distinguish these from division. |
| 39 | if (c === '/' && /(?:^|[=(:,)!&|?;{}\[\]+*%~^<>-]|\b(?:return|throw|case|yield|await|else|do|typeof|void|delete|new|in|of|instanceof))\s*$/.test(text.slice(Math.max(0, i - 32), i))) { |
| 40 | let end = i + 1; |
| 41 | let inClass = false; |
| 42 | for (; end < n && text[end] !== '\n'; end++) { |
| 43 | if (text[end] === '\\') { end++; continue; } |
| 44 | if (text[end] === '[') inClass = true; |
| 45 | if (text[end] === ']') inClass = false; |
| 46 | if (text[end] === '/' && !inClass) break; |
| 47 | } |
| 48 | if (end < n && text[end] === '/') { i = end + 1; continue; } |
| 49 | } |
| 50 | if (c === '"' || c === "'" || c === '`') { |
| 51 | const quote = c; |
| 52 | i++; |
| 53 | while (i < n && text[i] !== quote) { |
| 54 | if (text[i] === '\\' && i + 1 < n) { |
| 55 | out[i] = ' '; |
| 56 | out[i + 1] = ' '; |
| 57 | i += 2; |
| 58 | continue; |
| 59 | } |
| 60 | if (quote !== '`' && text[i] === '\n') break; |
| 61 | if (text[i] !== '\n') out[i] = ' '; |
| 62 | i++; |
| 63 | } |
| 64 | if (i < n && text[i] === quote) i++; |
| 65 | continue; |
| 66 | } |
| 67 | i++; |
| 68 | } |
| 69 | return out.join(''); |
| 70 | } |
| 71 | |
| 72 | export type CommentLang = |
| 73 | | 'python' |
no test coverage detected