regexp-tree
regexp-tree copied to clipboard
Incorrect results when quantifier range unsafe integer
E.g
/a{9007199254740993}/
gives
{
"type": "Quantifier",
"kind": "Range",
"from": 9007199254740992,
"to": 9007199254740992,
"greedy": true
}
Note 9007199254740992
not 9007199254740993
.
I wonder if the parser should throw if !Number.isSafeInteger(x)
?
Or if numbers this size are actually handled by engines(?) maybe we should also expose a string version of the number
Thanks, yeah, this is a weird edge-case. An agual JS regexp is actually generated with correct number /a{9007199254740993,9007199254740993}/
, so from the code generator perspective it might be good to support it.
We can probably check if the number is safe, store the number, otherwise a string. Or add the new string fields as you suggests (not obvious though what will be kept in the number field).
Maybe Bigint could help here? Although it's complicated with it not being supported everywhere.
Could be something like:
-
from: number | null
-
fromBigInt: bigint
(if device supports big int) -
fromString: string
Yeah, we need something predictable and working on most of the case. I think we can just make types of the from
and to
fields to be strings, since we need to support correct code generation, back from having AST.