also looking at this
chore(deps): update all non-major dependencies
#2997
29 files
+1047
-444
| @@ -0,0 +1,48 @@ | ||
| 1 | /** | |
| 2 | * Triple-slash directive extraction — NO TypeScript dependency. | |
| 3 | * Pure string processing for maximum startup speed. | |
| 4 | */ | |
| 5 | ||
| 6 | /** | |
| 7 | * Extract triple-slash directives from source code. | |
| 8 | * These are special comments like /// <reference types="..." /> | |
| 9 | */ | |
| 10 | export function extractTripleSlashDirectives(sourceCode: string): string[] { | |
| 11 | const directives: string[] = [] | |
| 12 | let lineStart = 0 | |
| 13 | ||
| 14 | // Scan line-by-line without splitting the entire source (stops early for large files) | |
| 15 | for (let i = 0; i <= sourceCode.length; i++) { | |
| 16 | if (i === sourceCode.length || sourceCode[i] === '\n') { | |
| 17 | // Extract and trim the current line | |
| 18 | let start = lineStart | |
| 19 | let end = i | |
| 20 | while (start < end && (sourceCode[start] === ' ' || sourceCode[start] === '\t' || sourceCode[start] === '\r')) start++ | |
| 21 | while (end > start && (sourceCode[end - 1] === ' ' || sourceCode[end - 1] === '\t' || sourceCode[end - 1] === '\r')) end-- | |
| 22 | const trimmed = sourceCode.slice(start, end) | |
| 23 | lineStart = i + 1 | |
| 24 | ||
| 25 | // Triple-slash directives must be at the very beginning of the file | |
| 26 | // (only whitespace and other triple-slash directives can precede them) | |
| 27 | if (trimmed.startsWith('///')) { | |
| 28 | if (trimmed.match(/^\/\/\/\s*<reference\s+(path|types|lib|no-default-lib)\s*=\s*["'][^"']+["']\s*\/>/)) { | |
| 29 | directives.push(trimmed) | |
| 30 | } | |
| 31 | else if (trimmed.match(/^\/\/\/\s*<amd-module\s+name\s*=\s*["'][^"']+["']\s*\/>/)) { | |
| 32 | directives.push(trimmed) | |
| 33 | } | |
| 34 | else if (trimmed.match(/^\/\/\/\s*<amd-dependency\s+path\s*=\s*["'][^"']+["']/)) { | |
| 35 | directives.push(trimmed) | |
| 36 | } | |
| 37 | } | |
| 38 | else if (trimmed === '' || trimmed.startsWith('//')) { | |
| 39 | continue | |
| 40 | } | |
| 41 | else { | |
| 42 | break | |
| 43 | } | |
| 44 | } | |
| 45 | } | |
| 46 | ||
| 47 | return directives | |
| 48 | } | |