Priority
P3
Area
Feature enhancement: richer built-in type fidelity
Problem
The built-in RegExp handler serializes with RegExp.prototype.toString(), which preserves source and flags but drops lastIndex. For global or sticky regexes, lastIndex is observable state and can matter when a caller serializes in-progress parser/matcher state.
Current behavior:
const pattern = /item/g;
pattern.lastIndex = 4;
const result = decode<{ pattern: RegExp }>(encode({ pattern }));
result.pattern.lastIndex; // 0
Relevant code:
src/types.ts: the RegExp handler serializes with v.toString() and deserializes by parsing /source/flags.
Expected behavior
Consider preserving lastIndex for regexes where it is meaningful, while keeping backwards compatibility with the existing /source/flags wire format.
Suggested approach
A compatible path is to support both formats during decode:
- Existing legacy string format:
/source/flags
- New structured format:
{ source, flags, lastIndex } encoded as JSON, or another versioned representation
Acceptance criteria
- Add tests for global and sticky regexes with non-zero
lastIndex.
- Existing serialized regex strings still decode correctly.
- README or changelog notes the improved fidelity if the wire format changes.
Priority
P3
Area
Feature enhancement: richer built-in type fidelity
Problem
The built-in
RegExphandler serializes withRegExp.prototype.toString(), which preserves source and flags but dropslastIndex. For global or sticky regexes,lastIndexis observable state and can matter when a caller serializes in-progress parser/matcher state.Current behavior:
Relevant code:
src/types.ts: theRegExphandler serializes withv.toString()and deserializes by parsing/source/flags.Expected behavior
Consider preserving
lastIndexfor regexes where it is meaningful, while keeping backwards compatibility with the existing/source/flagswire format.Suggested approach
A compatible path is to support both formats during decode:
/source/flags{ source, flags, lastIndex }encoded as JSON, or another versioned representationAcceptance criteria
lastIndex.