dfahlander / typeson-registry

The type registry for typeson
MIT License
6 stars 5 forks source link

Improve RegExp #20

Closed septs closed 4 years ago

septs commented 4 years ago

see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/flags

septs commented 4 years ago

@brettz9

septs commented 4 years ago

@brettz9

brettz9 commented 4 years ago

Btw, normally you shouldn't need to ping me, even for issues I'm not subscribed to, as I'm watching the repo, and plan to reply as I have energy (I have some health issues, but also as a result have free time, so sometimes I am very free and at other times I may not have energy to reply as quickly as I'd like).

I'm good with a dotAll addition, but if switching to flags we have to ensure the flags API is either transpiled by Babel for older browsers or we change our targets to browsers which support these. The ESLint compat/compat rule we have applied will catch some errors, though not sure it would be able to detect flags being supported for our targeted browsers. OTOH, maybe with typeson having core-js-bundle as a peerDep., it will be sufficient for typeson-registry since it seems core-js does have a flags polyfill. (core-js-bundle is really only needed for older browsers but added as a peer dep. to inform users.)

As far as lastIndex, while we can add another type which supports preserving lastIndex (if there is a use case for preserving such state), it is dropped by the structured cloning algorithm (SCA) in both Firefox and Chrome, so we don't want to add it to the existing regexp type which is used in our structured cloning preset (off topic, but just interesting to mention an oddity in Firefox in that Firefox, unlike Chrome, will actually reset lastIndex to 0 on the original regular expression as well as on the posted message if postMessage is run (postMessage being an easy way to test the SCA); but in any case, in both browsers lastIndex is reset to 0 when cloned).