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

Fix(47969): String.prototypr.replace docs fix #50041

Merged
merged 10 commits into from Sep 28, 2022
6 changes: 3 additions & 3 deletions src/lib/es2015.symbol.wellknown.d.ts
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`.
navya9singh marked this conversation as resolved.
Show resolved Hide resolved
* @param searchValue An object that supports searching for and replacing matches within a string.
* @param replacer The replacement text.
navya9singh marked this conversation as resolved.
Show resolved Hide resolved
*/
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
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.
navya9singh marked this conversation as resolved.
Show resolved Hide resolved
* @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.
navya9singh marked this conversation as resolved.
Show resolved Hide resolved
Copy link
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
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
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