-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. If we don't want add There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! |
||
}); | ||
|
||
it('Should not treat string as regexp', () => { | ||
assert.strictEqual( | ||
new MagicString('1234').replace('.', '*').toString(), | ||
'1234' | ||
); | ||
}); | ||
|
||
it('Should use substitution directly', () => { | ||
assert.strictEqual( | ||
new MagicString('11').replace('1', '$0$1').toString(), | ||
'$0$1$0$1' | ||
); | ||
}); | ||
|
||
it('Should not search back', () => { | ||
assert.strictEqual( | ||
new MagicString('121212').replace('12', '21').toString(), | ||
'212121' | ||
); | ||
}); | ||
|
||
it('works with global regex replace', () => { | ||
|
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