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.
* Passes a string and {@linkcode replaceValue} to the [Symbol.replace] method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Passes a string and {@linkcode replaceValue} to the [Symbol.replace] method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm.
* Passes a string and {@linkcode replaceValue} to the `[Symbol.replace]` method on {@linkcode searchValue}. This method is expected to implement its own replacement algorithm.

(Suggestion, dunno if the stdlib has its own style rules about JSDoc. Also @@replace is technically the name for the method—it's only accessed via Symbol.replace)

Copy link
Member

Choose a reason for hiding this comment

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

I like the formatting improvement, but I think @@replace is only useful for people who have read the spec.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, I'm fine with [Symbol.replace]. FWIW, on MDN we consistently use RegExp.prototype[@@replace]() so I hope it's not that obscure, but I can understand.

* @param searchValue An object that supports searching for and replacing matches within a string.
* @param replaceValue The replacement text.
*/
replace(searchValue: { [Symbol.replace](string: string, replaceValue: string): string; }, replaceValue: string): string;

Expand Down
4 changes: 2 additions & 2 deletions src/lib/es5.d.ts
Expand Up @@ -429,8 +429,8 @@ 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 searchValue A string or regular expression to search for.
* @param replaceValue A string containing the text to replace. When the {@linkcode searchValue} is a string, only the first match is replaced. If the {@linkcode searchValue} is a RegExp, all matches are replaced if the g flag is set. Otherwise only the first one is.
Copy link
Member

Choose a reason for hiding this comment

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

I think I would reword this to highlight the interesting global regex case first, and try to cover strings and sticky regexes later.

Suggested change
* @param replaceValue A string containing the text to replace. When the {@linkcode searchValue} is a string, only the first match is replaced. If the {@linkcode searchValue} is a RegExp, all matches are replaced if the g flag is set. Otherwise only the first one is.
* @param replaceValue A string containing the text to replace. When the {@linkcode searchValue} is a RegExp, all matches are replaced if the g flag is set (taking into account the y flag if present). Otherwise {@linkcode searchValue} only the first match is replaced.

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

Expand Down
50 changes: 48 additions & 2 deletions tests/baselines/reference/completionsStringMethods.baseline
Expand Up @@ -1048,7 +1048,7 @@
"kind": "space"
},
{
"text": "A string to search for.",
"text": "A string or regular expression to search for.",
"kind": "text"
}
]
Expand All @@ -1065,7 +1065,53 @@
"kind": "space"
},
{
"text": "A string containing the text to replace for every successful match of searchValue in this string.",
"text": "A string containing the text to replace. When the ",
"kind": "text"
},
{
"text": "{@linkcode ",
"kind": "link"
},
{
"text": "searchValue",
"kind": "linkName",
"target": {
"fileName": "lib.d.ts",
"textSpan": {
"start": 19079,
"length": 28
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": " is a string, only the first match is replaced. If the ",
"kind": "text"
},
{
"text": "{@linkcode ",
"kind": "link"
},
{
"text": "searchValue",
"kind": "linkName",
"target": {
"fileName": "lib.d.ts",
"textSpan": {
"start": 19079,
"length": 28
}
}
},
{
"text": "}",
"kind": "link"
},
{
"text": " is a RegExp, all matches are replaced if the g flag is set. Otherwise only the first one is.",
"kind": "text"
}
]
Expand Down