denoland / std

The Deno Standard Library
https://jsr.io/@std
MIT License
3k stars 598 forks source link

`@std/regexp/escape` vs `RegExp.escape` (newly Stage 3!) #5794

Open lionel-rowe opened 2 weeks ago

lionel-rowe commented 2 weeks ago

Mainly a tracking issue, probably (?) no action needed for now.

The RegExp.escape proposal has overcome its TC39 deadlock and is now at Stage 3!

The exact details of the implementation in the spec differ somewhat from @std/regexp/escape, but as far as I can tell, the only functional difference is that alphanumeric chars get automatically escaped at the start of the string, such that RegExp.escape('7_8_9') becomes '\\x37_8_9', which sacrifices a certain amount of readability in exchange for allowing safe interpolation immediately after the sequences \0, \<digits>, and \c.

Not sure if desirable or worthwhile to replace at this stage, but I've created a lightweight polyfill that passes the test262 tests and could work as a drop-in replacement for @std/regexp/escape. But probably better to just wait until implementations drop and then deprecate @std/regexp/escape.

iuioiua commented 2 weeks ago

But probably better to just wait until implementations drop and then deprecate @std/regexp/escape.

I like this option 🙂