Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/es2015.symbol.wellknown.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ interface String {
match(matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null;

/**
* Replaces first match with string or all matches with RegExp.
* @param searchValue A string or RegExp search value.
* @param replaceValue A string containing the text to replace for match.
* Replaces one or more occurrences of substrings that match the method provided by `searchValue`.
* @param searchValue An object that supports searching for and replacing matches within a string.
* @param replacer The replacement text.
*/
replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;

Expand Down
2 changes: 1 addition & 1 deletion src/lib/es5.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ interface String {
/**
* Replaces text in a string, using a regular expression or search string.
* @param searchValue A string to search for.
* @param replaceValue A string containing the text to replace for every successful match of searchValue in this string.
* @param replaceValue A string containing the text to replace. When the searchvalue is a string, only the first match is replaced. If the searchValue is a Regexp, all matches are replaced if the g flag is set. Otherwise only the first one is.
Copy link
Copy Markdown
Contributor

@Josh-Cena Josh-Cena Jul 26, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an "interesting" aspect where "aaa-a".replace(/a/gy, "x") is xxx-a. I don't know how detailed we want it to be, but "all matches are replaced if the g flag is set" is technically not correct—and arguably less correct than before.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MDN's documentation for the sticky flag says that it ignores the global flag. If that's true, then I think it's fine to document it as-is, since you'll presumably find out about y long after g and hopefully read about the override.

However, is that consistent with your example? If there's some kind of interaction, it might be worth documenting.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's an open issue for it: mdn/content#1454 I just haven't gotten around to fix it.

*/
replace(searchValue: string | RegExp, replaceValue: string): string;

Expand Down