-
Notifications
You must be signed in to change notification settings - Fork 115
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
feat: fix .replace()
when searching string, add .replaceAll()
#222
Conversation
test/MagicString.js
Outdated
@@ -1305,7 +1305,28 @@ describe('MagicString', () => { | |||
|
|||
s.replace('2', '3'); | |||
|
|||
assert.strictEqual(s.toString(), '1 3 1 2'); | |||
assert.strictEqual(s.toString(), '1 3 1 3'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we don't want add .replaceAll
, I guess we should just replace them all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess it makes better sense to align with JavaScript's string, so I'd prefer adding .replaceAll
and keeping .replace
only replaced once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure!
@antfu Can you take a look? |
src/MagicString.js
Outdated
} | ||
|
||
replace(searchValue, replacement) { | ||
return this[typeof searchValue === 'string' ? '_replaceString' : '_replaceRegexp']( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use an if condition instead of props accessing? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
All review points addressed. |
.replace()
when searching string.replace()
when searching string, add .replaceAll()
.replace()
when searching string, add .replaceAll()
.replace()
when searching string, add .replaceAll()
Awesome, thanks! |
Should have added "replaceAll" to the typescript definition file! See the PR I have submitted right now: #224 |
Fix #221