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

[Feature request] in replace and replaceAll, allow the replacer function to return "no-op" value #225

Open
Tal500 opened this issue Oct 4, 2022 · 0 comments

Comments

@Tal500
Copy link
Contributor

Tal500 commented Oct 4, 2022

The replace and replaceAll functions are mimicking the standard method of the string prototype in JS.

If you enter a replacer function on standard JS, and you see some match you don't want to change, you're simply return the original match in the function body.
This strategy allows the replacer function to do a "no-op" replacement.

Today, you might think you can do the same on magic-string, but in the sourcemap I think it will be shown that the substring was changed(e.g. "blabla" was replaced by "blabla"), but this was not the intention.

Can we allow for the replacement function to return sometimes a value of undefined? This way, whenever this value is being returned, magic-string will know not to replace this incident.

It might make sense in some cases to mark a substring as "replaced" in the sourcemap, even though it didn't change at all. This is why I'm not suggesting to check if the replacer return value was different, but rather suggest to check if it was returning undefined.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant