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) <[email protected]>
This commit is contained in:
Lucas Winther
2026-09-17 10:19:17 +02:00
co-authored by Claude Opus 5
parent 5b0f73ae0e
commit 28a834eb32
+1 -3
View File
@@ -38,9 +38,7 @@ export function tokenizeWithOffsets(text: string): Token[] {
return tokens; return tokens;
} }
TOKEN_PATTERN.lastIndex = 0; for (const match of text.matchAll(TOKEN_PATTERN)) {
let match: RegExpExecArray | null;
while ((match = TOKEN_PATTERN.exec(text)) !== null) {
const value = normalizeText(match[0]); const value = normalizeText(match[0]);
if (value.length > 0) { if (value.length > 0) {
tokens.push({ value, offset: match.index }); tokens.push({ value, offset: match.index });