Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lionel-rowe opened this issue Aug 23, 2024 · 1 comment
Open

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

lionel-rowe opened this issue Aug 23, 2024 · 1 comment
Labels
regexp suggestion a suggestion yet to be agreed

Comments

@lionel-rowe
Copy link
Contributor

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
Copy link
Collaborator

iuioiua commented Aug 25, 2024

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

I like this option 🙂

@iuioiua iuioiua added suggestion a suggestion yet to be agreed regexp labels Aug 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regexp suggestion a suggestion yet to be agreed
Projects
None yet
Development

No branches or pull requests

2 participants