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

.replace replacing removed code #223

Open
fisker opened this issue Sep 22, 2022 · 3 comments
Open

.replace replacing removed code #223

fisker opened this issue Sep 22, 2022 · 3 comments

Comments

@fisker
Copy link
Contributor

fisker commented Sep 22, 2022

> new (require('magic-string'))('00').remove(0, 1).replace('0', '1').toString()
'10'

Shouldn't the result be 1?

@antfu
Copy link
Collaborator

antfu commented Sep 22, 2022

.replace matches against the original string, which is a document caveat. I am not sure if there is a way to improve that, if so I am open for PR.

@fisker
Copy link
Contributor Author

fisker commented Sep 22, 2022

I'm not sure exactly how it works, I generated a new MagicString before replacing for now. prettier/prettier@77ac062

@Tal500
Copy link
Contributor

Tal500 commented Oct 4, 2022

.replace matches against the original string, which is a document caveat. I am not sure if there is a way to improve that, if so I am open for PR.

Is it problematic to get as parameter if the user wants to perform the search on the original string or not?

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

3 participants