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:
co-authored by
Claude Opus 5
parent
5b0f73ae0e
commit
28a834eb32
@@ -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 });
|
||||||
|
|||||||
Reference in New Issue
Block a user