also looking at this
chore(deps): update all non-major dependencies
#2997
29 files
+1047
-444
| @@ -5,6 +5,9 @@ | ||
| 5 | 5 | |
| 6 | 6 | import type { SourceFile } from 'typescript' |
| 7 | 7 | import { createSourceFile, ScriptKind, ScriptTarget } from 'typescript' |
| 8 | import { hashContent } from './hash' | |
| 9 | ||
| 10 | export { hashContent } from './hash' | |
| 8 | 11 | |
| 9 | 12 | /** |
| 10 | 13 | * Cache for parsed SourceFile objects to avoid re-parsing |
| @@ -12,11 +15,6 @@ import { createSourceFile, ScriptKind, ScriptTarget } from 'typescript' | ||
| 12 | 15 | */ |
| 13 | 16 | const sourceFileCache = new Map<string, { sourceFile: SourceFile, contentHash: number | bigint, lastAccess: number }>() |
| 14 | 17 | |
| 15 | /** | |
| 16 | * Whether Bun.hash is available (much faster than JS hash) | |
| 17 | */ | |
| 18 | const hasBunHash = typeof globalThis.Bun?.hash === 'function' | |
| 19 | ||
| 20 | 18 | /** |
| 21 | 19 | * Pending async parse operations to prevent duplicate parsing |
| 22 | 20 | */ |
| @@ -50,23 +48,6 @@ export interface AsyncParseConfig { | ||
| 50 | 48 | */ |
| 51 | 49 | const MAX_CACHE_SIZE = 100 |
| 52 | 50 | |
| 53 | /** | |
| 54 | * Fast hash function for content comparison. | |
| 55 | * Uses Bun.hash (native wyhash) when available, falls back to JS implementation. | |
| 56 | */ | |
| 57 | export function hashContent(content: string): number | bigint { | |
| 58 | if (hasBunHash) { | |
| 59 | return Bun.hash(content) | |
| 60 | } | |
| 61 | let hash = 0 | |
| 62 | for (let i = 0; i < content.length; i++) { | |
| 63 | const char = content.charCodeAt(i) | |
| 64 | hash = ((hash << 5) - hash) + char | |
| 65 | hash = hash & hash // Convert to 32-bit integer | |
| 66 | } | |
| 67 | return hash | |
| 68 | } | |
| 69 | ||
| 70 | 51 | /** |
| 71 | 52 | * Evict oldest entry if cache exceeds max size |
| 72 | 53 | * Uses O(n) scan instead of O(n log n) sort since we add one entry at a time |