From 28a834eb32c95b45bcfda3573ad475682e9508aa Mon Sep 17 00:00:00 2001 From: Lucas Winther Date: Thu, 17 Sep 2026 10:19:17 +0200 Subject: [PATCH] fix(search): eliminate mutable regex state with matchAll Replace manual exec loop with matchAll to eliminate cross-call mutable lastIndex state on module-level TOKEN_PATTERN regex. matchAll clones the regex internally, ensuring no shared state while maintaining identical behavior and original-text offset semantics. Co-Authored-By: Claude Opus 5 (1M context) --- src/search/tokenize.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/search/tokenize.ts b/src/search/tokenize.ts index ca351b7..795a802 100644 --- a/src/search/tokenize.ts +++ b/src/search/tokenize.ts @@ -38,9 +38,7 @@ export function tokenizeWithOffsets(text: string): Token[] { return tokens; } - TOKEN_PATTERN.lastIndex = 0; - let match: RegExpExecArray | null; - while ((match = TOKEN_PATTERN.exec(text)) !== null) { + for (const match of text.matchAll(TOKEN_PATTERN)) { const value = normalizeText(match[0]); if (value.length > 0) { tokens.push({ value, offset: match.index });